This is an archive of the discontinued LLVM Phabricator instance.

[Mips] Emit the correct DINS variant
ClosedPublic

Authored by spetrovic on Mar 15 2017, 9:56 AM.

Details

Summary

This patch fixes emitting of correct variant of DINS instruction. I'm referencing the gnu assembler for this solution.
Here is an example of a case where LLVM assembler emits DINS instruction instead of DINSM:

For instruction: dins $2, $1, 28, 6

Output without the patch: 7c220f07 dins v0,at,0x1c,0xffffffe6 -> 07 (opcode for dins)
Output with the patch: 7c220f05 dins v0,at,0x1c,0x6 -> 05 (opcode for dinsm)

Output with gnu assembler: 7c220f05 dins v0,at,0x1c,0x6 -> (05 opcode for dinsm)

Diff Detail

Repository
rL LLVM

Event Timeline

spetrovic created this revision.Mar 15 2017, 9:56 AM
sdardis edited edge metadata.Mar 15 2017, 10:35 AM

This requires a test. Can you add regression tests to test/MC/Mips/mips64extins.s as part of this patch?

I think that llvm-objdump tool has an issue with DINS instruction, so I was using gnu objdump for testing.
For example, for dins $2, $1, 28, 6 llvm-objdump generates: dins 7c 22 0f 05 dinsm $2, $1, 28, 38 (it dumps DINSM instruction, that part is ok, but it generates 38 instead of 6). Thats why I didn't add test case, once when llvm-objdump is fixed I can add test.
The issue with llvm-objdump might be that for dins, bits 15-11 contain (pos + size - 1) and for dinsm (pos + size -33) and it seems that llvm-objdump treats these bits for dinsm as if it was dins, since it always displays size increased for 32.

sdardis accepted this revision.Mar 20 2017, 7:16 AM

LGTM with inline comment addressed.

As for the disassembler, for the moment just match the instruction encoding and opcode.

Ideally, we should emit the assembly text for dins in all cases.

lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
124 ↗(On Diff #91884)

The second condition is incorrect, it should be (pos + size) <= 64, according to the 5.04 BIS.

This revision is now accepted and ready to land.Mar 20 2017, 7:16 AM
spetrovic updated this revision to Diff 92470.Mar 21 2017, 5:12 AM
spetrovic marked an inline comment as done.

Comment addressed

This revision was automatically updated to reflect the committed changes.