-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Showing
11 changed files
with
320 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# RUN: not llvm-mc -triple armv7 %s 2>&1| FileCheck %s | ||
|
||
.arm | ||
|
||
ADC r0, r1, #0xFFFFFEEE | ||
# CHECK: error: invalid operand for instruction | ||
ADC r0, r1, #0xABFEABFF | ||
# CHECK: error: invalid operand for instruction | ||
ADC r0, r1, #0xFFFFFE02 | ||
# CHECK: error: invalid operand for instruction | ||
|
||
ADD.W r0, r0, #0xFF01FF01 | ||
# CHECK: error: invalid operand for instruction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# RUN: not llvm-mc -triple thumbv7 -mcpu=cortex-m0 %s 2>&1 | FileCheck %s | ||
|
||
.thumb | ||
|
||
ADDs r1, r0, #0xFFFFFFF5 | ||
# CHECK: error: instruction requires: arm-mode | ||
|
||
ADDs r0, #0xFFFFFEFF | ||
# CHECK: error: invalid operand for instruction | ||
|
||
SUBs r1, r0, #0xFFFFFFF5 | ||
# CHECK: error: instruction requires: arm-mode | ||
|
||
SUBs r0, #0xFFFFFEFF | ||
# CHECK: error: invalid operand for instruction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# RUN: llvm-mc -triple thumbv7 -mcpu=cortex-m0 %s -show-encoding | FileCheck %s | ||
# RUN: not llvm-mc -triple thumbv7 -mcpu=cortex-m0 %s -show-encoding -mattr=+no-neg-immediates 2>&1 | FileCheck %s -check-prefix=CHECK-DISABLED | ||
|
||
.thumb | ||
|
||
ADDs r1, r0, #0xFFFFFFF9 | ||
# CHECK: subs r1, r0, #7 | ||
# CHECK-DISABLED: error: instruction requires: NegativeImmediates | ||
ADDs r0, #0xFFFFFF01 | ||
# CHECK: subs r0, #255 | ||
# CHECK-DISABLED: error: instruction requires: NegativeImmediates | ||
|
||
SUBs r0, #0xFFFFFF01 | ||
# CHECK: adds r0, #255 | ||
# CHECK-DISABLED: error: instruction requires: NegativeImmediates | ||
|
||
SUBs r1, r0, #0xFFFFFFF9 | ||
# CHECK: adds r1, r0, #7 | ||
# CHECK-DISABLED: error: instruction requires: NegativeImmediates |
Oops, something went wrong.