This is an archive of the discontinued LLVM Phabricator instance.

[mips][microMIPS] Implement LH, LHE, LHU and LHUE instructions and add CodeGen support
ClosedPublic

Authored by zbuljan on Dec 10 2015, 7:02 AM.

Details

Summary

The patch implements microMIPSr6 LH, LHE, LHU and LHUE instructions.

There was a problem with previous implementation of this instructions (D9824) and because of that commit rL254897 was reverted.

After commit of previous patch, test-suite failed with error message in the form of:

fatal error: error in backend: Cannot select: t124: i32,ch = load<LD2[%d](tbaa=<0x94acc48>), sext from i16> t0, t2, undef:i32

There was problem with selecting lh and lhu instructions in LLVM backend.

For that reason I decided to revert commit rL254897 and make this patch which besides implementation of instructions and standard regression tests also includes CodeGen tests (lh_lhu.ll).

Diff Detail

Repository
rL LLVM

Event Timeline

zbuljan updated this revision to Diff 42428.Dec 10 2015, 7:02 AM
zbuljan retitled this revision from to [mips][microMIPS] Implement LH, LHE, LHU and LHUE instructions.
zbuljan updated this object.
zbuljan added subscribers: petarj, llvm-commits.
zbuljan updated this revision to Diff 50405.Mar 11 2016, 1:55 AM

Rebased to work with top of the tree.

sdardis requested changes to this revision.Apr 15 2016, 7:12 AM
sdardis edited edge metadata.

Hi,

After applying this patch and checking lh_lhu.ll with "-asm-show-inst" I see:

lh      $2, %lo(us)($2)         # <MCInst #1187 LH
                                #  <MCOperand Reg:321>
                                #  <MCOperand Reg:321>
                                #  <MCOperand Expr:(us@ABS_LO)>>

Shouldn't LLVM have picked LH_MM? The rest are small nits regarding some style issues and the ordering of instructions in test files.

lib/Target/Mips/MicroMips32r6InstrFormats.td
883 ↗(On Diff #50405)

Can you redo this definition in the style of SB32_SH32_STORE_FM_MMR6 ? You split addr into base and offset, then assign to Inst.

lib/Target/Mips/MicroMips32r6InstrInfo.td
173–174 ↗(On Diff #50405)

Can you use the 0bxxx style of specifying opcodes here? It makes it somewhat easier to check and is more consistent with the overall MIPS backend.

test/MC/Disassembler/Mips/micromips32r6/valid.txt
261–264 ↗(On Diff #50405)

Can you sort these alphabetically into the existing instructions?

test/MC/Mips/micromips-invalid.s
105 ↗(On Diff #50405)

Can you add some out of range negative tests for these instructions as well? This applies to the other invalid tests as well.

test/MC/Mips/micromips32r6/valid.s
255–258 ↗(On Diff #50405)

Can you sort these alphabetically into the first 100~ instructions.

This revision now requires changes to proceed.Apr 15 2016, 7:12 AM
zbuljan updated this revision to Diff 55564.Apr 29 2016, 4:20 AM
zbuljan retitled this revision from [mips][microMIPS] Implement LH, LHE, LHU and LHUE instructions to [mips][microMIPS] Implement LH, LHE, LHU and LHUE instructions and add CodeGen support.
zbuljan edited edge metadata.

Rebased to work with TOT.
Removed microMIPS32r6 implementation of LH and LHU instructions because it is not required.
Added required DAG patterns for microMIPS LH and LHU instructions so they can be selected properly.
Expanded .ll test with load atomic to check added DAG pattern.
Tests for the standard encodings are sorted in alphabetical order.
Added invalid tests for the negative ranges.

sdardis requested changes to this revision.May 5 2016, 7:17 AM
sdardis edited edge metadata.

One nit and one small change, comments are inlined.

lib/Target/Mips/MicroMipsInstrFormats.td
1026 ↗(On Diff #55564)

This class needs to inherit from MMArch, so that this instruction ends up in the Std2MicroMips mapping table from direct object emission.

You can verify the mapping by looking at the Std2MicroMips function in $BUILDDIR/lib/Target/Mips/MipsGenDAGISel.inc and/or the records from llvm-tblgen for the string Arch = in the defs of the instructions.

You'll also have to remove the line "list<Pattern> = []" from the definition of MMArch, otherwise the DAG pattern doesn't get set properly and the instruction cannot be selected in the common case.

Removing that line from the MMArch definition will cause test failures as the selection mechanism be arranged and some 16bit instructions will not be chosen. Some of the test failures are fixed in D19906.

test/CodeGen/Mips/llvm-ir/lh_lhu.ll
3 ↗(On Diff #55564)

Check microMIPS64r6 as well.

This revision now requires changes to proceed.May 5 2016, 7:17 AM
zbuljan updated this revision to Diff 57453.May 17 2016, 3:56 AM
zbuljan edited edge metadata.

Rebased to work with TOT.
Changed LH_LHU_FM_MM format class to inherit from MMArch.
Removed the line "list<Pattern> = []" from the definition of MMArch class.
Added "int AddedComplexity = 1" parameter to definition of 16-bit instructions.
Updated lh_lhu.ll with test for microMIPS64r6.

sdardis accepted this revision.May 17 2016, 9:15 AM
sdardis edited edge metadata.

LGTM.

This revision is now accepted and ready to land.May 17 2016, 9:15 AM
This revision was automatically updated to reflect the committed changes.