Skip to content

Commit d4e7b00

Browse files
committed
[AArch64] Allow PAC mnemonics in the HINT space with PAC disabled
Summary: It is important to emit HINT instructions instead of PAC ones when PAC is disabled. This allows compatibility with other assemblers (e.g. GAS). This was implemented in commit da33762. Still, developers of assembly code will want to write code that is compatible with both pre- and post-PAC CPUs. They could use HINT mnemonics, but the new mnemonics are a lot more readable (e.g. paciaz instead of hint rust-lang#24), and they will result in the same encodings. So, while LLVM should not *emit* the new mnemonics when PAC is disabled, this patch will at least make LLVM *accept* assembly code that uses them. Reviewers: danielkiss, chill, olista01, LukeCheeseman, simon_tatham Subscribers: kristof.beyls, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78372
1 parent 6121122 commit d4e7b00

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.td

+19-1
Original file line numberDiff line numberDiff line change
@@ -915,10 +915,28 @@ let Uses = [LR], Defs = [LR], CRm = 0b0000 in {
915915
def XPACLRI : SystemNoOperands<0b111, "hint\t#7">;
916916
}
917917

918+
// In order to be able to write readable assembly, LLVM should accept assembly
919+
// inputs that use pointer authentication mnemonics, even with PA disabled.
920+
// However, in order to be compatible with other assemblers (e.g. GAS), LLVM
921+
// should not emit these mnemonics unless PA is enabled.
922+
def : InstAlias<"paciaz", (PACIAZ), 0>;
923+
def : InstAlias<"pacibz", (PACIBZ), 0>;
924+
def : InstAlias<"autiaz", (AUTIAZ), 0>;
925+
def : InstAlias<"autibz", (AUTIBZ), 0>;
926+
def : InstAlias<"paciasp", (PACIASP), 0>;
927+
def : InstAlias<"pacibsp", (PACIBSP), 0>;
928+
def : InstAlias<"autiasp", (AUTIASP), 0>;
929+
def : InstAlias<"autibsp", (AUTIBSP), 0>;
930+
def : InstAlias<"pacia1716", (PACIA1716), 0>;
931+
def : InstAlias<"pacib1716", (PACIB1716), 0>;
932+
def : InstAlias<"autia1716", (AUTIA1716), 0>;
933+
def : InstAlias<"autib1716", (AUTIB1716), 0>;
934+
def : InstAlias<"xpaclri", (XPACLRI), 0>;
935+
918936
// These pointer authentication instructions require armv8.3a
919937
let Predicates = [HasPA] in {
920938

921-
// When compiling with PA, there is a better mnemonic for these instructions.
939+
// When PA is enabled, a better mnemonic should be emitted.
922940
def : InstAlias<"paciaz", (PACIAZ), 1>;
923941
def : InstAlias<"pacibz", (PACIBZ), 1>;
924942
def : InstAlias<"autiaz", (AUTIAZ), 1>;

llvm/test/MC/AArch64/armv8.3a-signed-pointer.s

+14-27
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: FileCheck --check-prefixes=CHECK,ALL %s
33

44
// RUN: not llvm-mc -triple aarch64-none-linux-gnu -show-encoding %s -o - > %t.1 2>%t.2
5-
// RUN: FileCheck --check-prefixes=ALL %s < %t.1
5+
// RUN: FileCheck --check-prefixes=NO83,ALL %s < %t.1
66
// RUN: FileCheck --check-prefix=CHECK-REQ %s < %t.2
77

88
// ALL: .text
@@ -98,56 +98,43 @@
9898
// ALL-EMPTY:
9999
paciasp
100100
// CHECK-NEXT: paciasp // encoding: [0x3f,0x23,0x03,0xd5]
101-
// CHECK-REQ: error: instruction requires: pa
102-
// CHECK-REQ-NEXT: paciasp
101+
// NO83-NEXT: hint #25 // encoding: [0x3f,0x23,0x03,0xd5]
103102
autiasp
104103
// CHECK-NEXT: autiasp // encoding: [0xbf,0x23,0x03,0xd5]
105-
// CHECK-REQ: error: instruction requires: pa
106-
// CHECK-REQ-NEXT: autiasp
104+
// NO83-NEXT: hint #29 // encoding: [0xbf,0x23,0x03,0xd5]
107105
paciaz
108106
// CHECK-NEXT: paciaz // encoding: [0x1f,0x23,0x03,0xd5]
109-
// CHECK-REQ: error: instruction requires: pa
110-
// CHECK-REQ-NEXT: paciaz
107+
// NO83-NEXT: hint #24 // encoding: [0x1f,0x23,0x03,0xd5]
111108
autiaz
112109
// CHECK-NEXT: autiaz // encoding: [0x9f,0x23,0x03,0xd5]
113-
// CHECK-REQ: error: instruction requires: pa
114-
// CHECK-REQ-NEXT: autiaz
110+
// NO83-NEXT: hint #28 // encoding: [0x9f,0x23,0x03,0xd5]
115111
pacia1716
116112
// CHECK-NEXT: pacia1716 // encoding: [0x1f,0x21,0x03,0xd5]
117-
// CHECK-REQ: error: instruction requires: pa
118-
// CHECK-REQ-NEXT: pacia1716
113+
// NO83-NEXT: hint #8 // encoding: [0x1f,0x21,0x03,0xd5]
119114
autia1716
120115
// CHECK-NEXT: autia1716 // encoding: [0x9f,0x21,0x03,0xd5]
121-
// CHECK-REQ: error: instruction requires: pa
122-
// CHECK-REQ-NEXT: autia1716
116+
// NO83-NEXT: hint #12 // encoding: [0x9f,0x21,0x03,0xd5]
123117
pacibsp
124118
// CHECK-NEXT: pacibsp // encoding: [0x7f,0x23,0x03,0xd5]
125-
// CHECK-REQ: error: instruction requires: pa
126-
// CHECK-REQ-NEXT: pacibsp
119+
// NO83-NEXT: hint #27 // encoding: [0x7f,0x23,0x03,0xd5]
127120
autibsp
128121
// CHECK-NEXT: autibsp // encoding: [0xff,0x23,0x03,0xd5]
129-
// CHECK-REQ: error: instruction requires: pa
130-
// CHECK-REQ-NEXT: autibsp
122+
// NO83-NEXT: hint #31 // encoding: [0xff,0x23,0x03,0xd5]
131123
pacibz
132124
// CHECK-NEXT: pacibz // encoding: [0x5f,0x23,0x03,0xd5]
133-
// CHECK-REQ: error: instruction requires: pa
134-
// CHECK-REQ-NEXT: pacibz
125+
// NO83-NEXT: hint #26 // encoding: [0x5f,0x23,0x03,0xd5]
135126
autibz
136127
// CHECK-NEXT: autibz // encoding: [0xdf,0x23,0x03,0xd5]
137-
// CHECK-REQ: error: instruction requires: pa
138-
// CHECK-REQ-NEXT: autibz
128+
// NO83-NEXT: hint #30 // encoding: [0xdf,0x23,0x03,0xd5]
139129
pacib1716
140130
// CHECK-NEXT: pacib1716 // encoding: [0x5f,0x21,0x03,0xd5]
141-
// CHECK-REQ: error: instruction requires: pa
142-
// CHECK-REQ-NEXT: pacib1716
131+
// NO83-NEXT: hint #10 // encoding: [0x5f,0x21,0x03,0xd5]
143132
autib1716
144133
// CHECK-NEXT: autib1716 // encoding: [0xdf,0x21,0x03,0xd5]
145-
// CHECK-REQ: error: instruction requires: pa
146-
// CHECK-REQ-NEXT: autib1716
134+
// NO83-NEXT: hint #14 // encoding: [0xdf,0x21,0x03,0xd5]
147135
xpaclri
148136
// CHECK-NEXT: xpaclri // encoding: [0xff,0x20,0x03,0xd5]
149-
// CHECK-REQ: error: instruction requires: pa
150-
// CHECK-REQ-NEXT: xpaclri
137+
// NO83-NEXT: hint #7 // encoding: [0xff,0x20,0x03,0xd5]
151138

152139
// ALL-EMPTY:
153140
pacia x0, x1

0 commit comments

Comments
 (0)