]> granicus.if.org Git - llvm/commit
[ARM] [Assembler] Support negative immediates for A32, T32 and T16
authorSanne Wouda <sanne.wouda@arm.com>
Tue, 21 Mar 2017 14:59:17 +0000 (14:59 +0000)
committerSanne Wouda <sanne.wouda@arm.com>
Tue, 21 Mar 2017 14:59:17 +0000 (14:59 +0000)
commit94612f1d5fd50b35f95fb6301256da7df175f8a4
treeede23318ec2859072109f2c9e4fe963339567b7d
parent656673e86d5050f8b73733b91bcd8c1950d55e71
[ARM] [Assembler] Support negative immediates for A32, T32 and T16

Summary:
To support negative immediates for certain arithmetic instructions, the
instruction is converted to the inverse instruction with a negated (or inverted)
immediate. For example, "ADD r0, r1, #FFFFFFFF" cannot be encoded as an ADD
instruction.  However, "SUB r0, r1, #1" is equivalent.

These conversions are different from instruction aliases.  An alias maps
several assembler instructions onto one encoding.  A conversion, however, maps
an *invalid* instruction--e.g. with an immediate that cannot be represented in
the encoding--to a different (but equivalent) instruction.

Several instructions with negative immediates were being converted already, but
this was not systematically tested, nor did it cover all instructions.

This patch implements all possible substitutions for ARM, Thumb1 and
Thumb2 assembler and adds tests.  It also adds a feature flag
(-mattr=+no-neg-immediates) to turn these substitutions off.  This is
helpful for users who want their code to assemble to exactly what they
wrote.

Reviewers: t.p.northover, rovka, samparker, javed.absar, peter.smith, rengolin

Reviewed By: javed.absar

Subscribers: aadg, aemerson, llvm-commits

Differential Revision: https://reviews.llvm.org/D30571

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298380 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/ARM/ARM.td
lib/Target/ARM/ARMInstrFormats.td
lib/Target/ARM/ARMInstrInfo.td
lib/Target/ARM/ARMInstrThumb.td
lib/Target/ARM/ARMInstrThumb2.td
lib/Target/ARM/ARMSubtarget.h
lib/Target/ARM/AsmParser/ARMAsmParser.cpp
test/MC/ARM/negative-immediates-fail.s [new file with mode: 0644]
test/MC/ARM/negative-immediates-thumb1-fail.s [new file with mode: 0644]
test/MC/ARM/negative-immediates-thumb1.s [new file with mode: 0644]
test/MC/ARM/negative-immediates.s [new file with mode: 0644]