This is an archive of the discontinued LLVM Phabricator instance.

ARM: Add support for ARM modified immediate syntax - Take 3
ClosedPublic

Authored by rmaprath on Nov 25 2014, 7:32 AM.

Details

Summary

Hi Tim,

This patch takes into account all the points discussed in [1, 2] and attempts to revive modified-immediate syntax support without duplicating instructions. As a proof of concept, I have added this support for 4 instructions - I'll add the rest of it (should be an easy task now) if you think this approach is acceptable.

Please let me know what you think.

Best,

  • Asiri

[1] http://marc.info/?t=137511225000002&r=1&w=3
[2] http://marc.info/?t=137675335900002&r=1&w=2

Diff Detail

Event Timeline

rmaprath updated this revision to Diff 16625.Nov 25 2014, 7:32 AM
rmaprath retitled this revision from to ARM: Add support for ARM modified immediate syntax - Take 3.
rmaprath updated this object.
rmaprath edited the test plan for this revision. (Show Details)
rmaprath added reviewers: t.p.northover, rengolin.
rmaprath added a subscriber: Unknown Object (MLST).
rmaprath updated this revision to Diff 16627.Nov 25 2014, 9:14 AM

Added disassembler tests.

rmaprath updated this revision to Diff 16718.Nov 28 2014, 3:46 AM

Hi Tim,

This is the full patch implementing support for modified immediate assembly syntax.

I think we can now get rid of the so_imm, so_imm_not and so_imm_neg definitions (replace them with mod_imm*), I will do that in a follow up patch (thought of keeping the current patch focused on the issue at hand).

(and ping?)

  • Asiri

Hi Asiri,

Sorry for the delay here. I've got some minor quibbles, but it looks mostly OK:

lib/Target/ARM/AsmParser/ARMAsmParser.cpp
4463–4465

I don't understand this one. Wouldn't that example have been covered by AsmToken::EndOfStatement above?

4502–4506

This looks a bit sketchy: combining and then splitting apart the immediates with some redundant masks.

Doesn't it amount to "CreateModImm(Imm1, Imm2)"?

lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp
1336

I don't think this is quite right. E.g. Op.getImm() == 0.

The obviously correct test is that "getSOImmVal(Rotated) == Op.getImm()", isn't it? If you think that's too expensive, could we at least assert it?

rmaprath updated this revision to Diff 16763.Dec 1 2014, 6:29 AM
rmaprath edited edge metadata.

Addressed review comments.

Hi Tim,

Comment at: lib/Target/ARM/AsmParser/ARMAsmParser.cpp:4463-4465
@@ +4462,5 @@
+
+ if (Parser.getTok().isNot(AsmToken::Comma)) {
+ Consider [mov r0, #-10], which is aliased with mvn. We cannot fail
+
the parse here.

+ Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));

I don't understand this one. Wouldn't that example have been covered by AsmToken::EndOfStatement above?

-10 (0xfffffff6 in two's complement) is not representable as a modified immediate. Since we have already parsed the input and cannot back-out at this stage, here we create a plain immediate and let other rules match it. I'm not 100% sure of the tablegen blackmagic going underneath, but it's the following instruction alias that consumes the immediate generated this way:

def : ARMInstAlias<"mov${s}${p} $Rd, $imm",

(MVNi rGPR:$Rd, mod_imm_not:$imm, pred:$p, cc_out:$s)>;

I think this alias definition causes the immediate to be treated as -(-10), which can be encoded as a modified immediate (+10).

Comment at: lib/Target/ARM/AsmParser/ARMAsmParser.cpp:4502-4506
@@ +4501,7 @@
+ Imm2 = CE->getValue();
+ if (!(Imm2 & ~0x1E)) {
+ // We have a match!
+ unsigned Enc = ((Imm2 & 0x1E) << 7) | Imm1;
+ Operands.push_back(ARMOperand::CreateModImm((Enc & 0xFF),
+ (Enc & 0xF00) >> 7,

+ S, Ex2));

This looks a bit sketchy: combining and then splitting apart the immediates with some redundant masks.

Doesn't it amount to "CreateModImm(Imm1, Imm2)"?

Fixed :)

Comment at: lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp:1336
@@ +1335,3 @@
+ int32_t Rotated = ARM_AM::rotr32(Bits, Rot); if ((Bits & 0x3) &&
+ (Rotated & ~0xFF)) {

+ // #rot has the least possible value

I don't think this is quite right. E.g. Op.getImm() == 0.

The obviously correct test is that "getSOImmVal(Rotated) == Op.getImm()", isn't it? If you think that's too expensive, could we at least assert it?

Op.getImm() == 0 will be taken care of from the previous if statement (Rot == 0), but I think your version is much more readable, I've switched to it.

OK to commit?

Thanks!

  • Asiri

http://reviews.llvm.org/D6408

In D6408#12, @rmaprath wrote:

Hi Tim,

Comment at: lib/Target/ARM/AsmParser/ARMAsmParser.cpp:4463-4465
@@ +4462,5 @@
+
+ if (Parser.getTok().isNot(AsmToken::Comma)) {
+ Consider [mov r0, #-10], which is aliased with mvn. We cannot fail
+
the parse here.

+ Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));

I don't understand this one. Wouldn't that example have been covered by AsmToken::EndOfStatement above?

-10 (0xfffffff6 in two's complement) is not representable as a modified immediate.

I.e (Enc == -1).

--Asiri

Hi Asiri,

Thanks for the AsmParser explanation and updated patch, I see now. But I think there's still one slight bit of streamlining we can do in the InstPrinter:

lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp
1332–1338

Isn't this now redundant? Looks like it would be covered fine by the logic below.

rmaprath updated this revision to Diff 16774.Dec 1 2014, 10:20 AM

Addressed review comments.

Hi Tim,

Comment at: lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp:1332-1338
@@ +1331,9 @@
+
+ if (Rot == 0) {
+ O << "#"
+ << markup("<imm:")
+ << Bits
+ << markup(">");
+ return;
+ }

+

Isn't this now redundant? Looks like it would be covered fine by the logic below.

Thanks for the catch!

I've attached an updated patch.

--Asiri

t.p.northover accepted this revision.Dec 1 2014, 10:34 AM
t.p.northover edited edge metadata.

Thanks Asiri,

I think this looks fine now.

Cheers.

Tim.

This revision is now accepted and ready to land.Dec 1 2014, 10:34 AM
rmaprath closed this revision.Dec 2 2014, 5:22 AM

Thanks Tim!

Committed as r223113, r223115. I will submit a cleanup patch to get rid of the so_imm and related definitions soon.

--Asiri