This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Allow negative immediates for ADD/SUB in asm
AbandonedPublic

Authored by rengolin on Jun 29 2015, 11:43 AM.

Details

Summary

Allow assembly code (either in an asm file or inline asm) to have negative
offsets for ADD/SUB, and convert them to their inverse instructions as per
the ARMv8 Instruction Set Overview, section 5.4.1.

I'm not really sure of a few things:

  1. If I accept negative numbers in isAddSubImm(), will this break other stuff?
  2. The manual doesn't say specifically, but I'm assuming we can't swap ADDS/SUBS.
  3. The error message may not be in the best of places, nor the best of texts. I'm open to suggestions.
  4. Is this really the best way to modify the MCInst?
  5. Adding support for #-4096 and higher powers of two may be trivial. I'll check while this review goes on.
  6. Changing the parser like this seems a lot better than both printers (as I had in bugzilla).

Fixes PR20978.

Diff Detail

Event Timeline

rengolin updated this revision to Diff 28691.Jun 29 2015, 11:43 AM
rengolin retitled this revision from to [AArch64] Allow negative immediates for ADD/SUB in asm.
rengolin updated this object.
rengolin edited the test plan for this revision. (Show Details)
rengolin set the repository for this revision to rL LLVM.
rengolin added subscribers: Unknown Object (MLST), echristo, grosbach.

Can't this be done as a simple InstAlias? The operand type even seems to exist already to support CodeGen (neg_addsub_shifted_imm, though it's a bit weird). You'd need a slightly adapted isNegAddSubImm and addNegAddSubImm methods, but you'd get your shifted values practically for free.

lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
3324–3325

The immediate form, we probably can. As I recall the edge cases where the transformation is invalid occur when the RHS is U?INT_(MIN|MAX). The shifted 12-bit immediates never are, so it should be OK.

Can't this be done as a simple InstAlias? The operand type even seems to exist already to support CodeGen (neg_addsub_shifted_imm, though it's a bit weird). You'd need a slightly adapted isNegAddSubImm and addNegAddSubImm methods, but you'd get your shifted values practically for free.

This was my first attempt, but since this is the asm parser, the instruction can be matched, but will not change. Both in asm files and inline asm, the parser is simply building MCInsts from whatever comes.

Unless I'm missing something obvious... Do you have an example in the table-gen file that does that already?

lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
3324–3325

Good point.

aadg added a subscriber: aadg.Jun 29 2015, 2:22 PM

You might want to have a look at the patch which I submitted to the mailing list On July 11th, 2014 ("[PATCH] [AArch64] Add add/sub/cmp/cmn aliases to MC AsmParser") to solve this very issue. It uses a different approach --- mostly tablegen based.

In D10810#196624, @aadg wrote:

You might want to have a look at the patch which I submitted to the mailing list On July 11th, 2014 ("[PATCH] [AArch64] Add add/sub/cmp/cmn aliases to MC AsmParser") to solve this very issue. It uses a different approach --- mostly tablegen based.

Hum, I remember that patch. I thought you had committed... If that one fixes the issue, do you want to go ahead and commit it?

rengolin abandoned this revision.Jul 1 2015, 4:11 AM

Abandoning, since Arnaud had a better solution all along.

aadg added a comment.Jul 1 2015, 8:11 AM

Abandoning, since Arnaud had a better solution all along.

Committed my patch @ r241166.