[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
llvm-svn: 298380
2017-03-21 22:59:17 +08:00
|
|
|
# RUN: not llvm-mc -triple thumbv7 -mcpu=cortex-m0 %s 2>&1 | FileCheck %s
|
|
|
|
|
|
|
|
.thumb
|
|
|
|
|
|
|
|
ADDs r1, r0, #0xFFFFFFF5
|
2017-10-03 18:26:11 +08:00
|
|
|
# CHECK: error: invalid instruction, any one of the following would fix this:
|
|
|
|
# CHECK-DAG: note: instruction requires: thumb2
|
|
|
|
# CHECK-DAG: note: invalid operand for instruction
|
2017-10-04 17:18:07 +08:00
|
|
|
# CHECK-DAG: note: operand must be an immediate in the range [0,7]
|
2017-10-10 20:31:53 +08:00
|
|
|
# CHECK-DAG: note: operand must be a register in range [r0, r7]
|
[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
llvm-svn: 298380
2017-03-21 22:59:17 +08:00
|
|
|
|
|
|
|
ADDs r0, #0xFFFFFEFF
|
2017-10-03 18:26:11 +08:00
|
|
|
# CHECK: error: invalid instruction, any one of the following would fix this:
|
|
|
|
# CHECK-DAG: note: invalid operand for instruction
|
2017-10-04 17:18:07 +08:00
|
|
|
# CHECK-DAG: note: operand must be an immediate in the range [0,255]
|
[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
llvm-svn: 298380
2017-03-21 22:59:17 +08:00
|
|
|
|
|
|
|
SUBs r1, r0, #0xFFFFFFF5
|
2017-10-03 18:26:11 +08:00
|
|
|
# CHECK: error: invalid instruction, any one of the following would fix this:
|
|
|
|
# CHECK-DAG: note: invalid operand for instruction
|
2017-10-04 17:18:07 +08:00
|
|
|
# CHECK-DAG: note: operand must be an immediate in the range [0,7]
|
2017-10-10 20:31:53 +08:00
|
|
|
# CHECK-DAG: note: operand must be a register in range [r0, r7]
|
[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
llvm-svn: 298380
2017-03-21 22:59:17 +08:00
|
|
|
|
|
|
|
SUBs r0, #0xFFFFFEFF
|
2017-10-03 18:26:11 +08:00
|
|
|
# CHECK: error: invalid instruction, any one of the following would fix this:
|
|
|
|
# CHECK-DAG: note: invalid operand for instruction
|
2017-10-04 17:18:07 +08:00
|
|
|
# CHECK-DAG: note: operand must be an immediate in the range [0,255]
|
2017-05-05 19:31:25 +08:00
|
|
|
|
|
|
|
ORRs r0, r1, #0xFFFFFF00
|
2017-10-03 18:26:11 +08:00
|
|
|
# CHECK: error: invalid instruction, any one of the following would fix this:
|
|
|
|
# CHECK-DAG: note: instruction requires: thumb2
|
|
|
|
# CHECK-DAG: note: too many operands for instruction
|
|
|
|
|
2017-05-05 19:31:25 +08:00
|
|
|
ORNs r0, r1, #0xFFFFFF00
|
|
|
|
# CHECK: error: instruction requires: thumb2
|