Skip to content

Commit ae5d407

Browse files
pbarrioKtwu
authored andcommitted
[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 swiftlang#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 upstream-commit: d4e7b00
1 parent 7789f3b commit ae5d407

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
@@ -937,6 +937,24 @@ let Uses = [LR], Defs = [LR], CRm = 0b0000 in {
937937
def XPACLRI : SystemNoOperands<0b111, "hint\t#7">;
938938
}
939939

940+
// In order to be able to write readable assembly, LLVM should accept assembly
941+
// inputs that use pointer authentication mnemonics, even with PA disabled.
942+
// However, in order to be compatible with other assemblers (e.g. GAS), LLVM
943+
// should not emit these mnemonics unless PA is enabled.
944+
def : InstAlias<"paciaz", (PACIAZ), 0>;
945+
def : InstAlias<"pacibz", (PACIBZ), 0>;
946+
def : InstAlias<"autiaz", (AUTIAZ), 0>;
947+
def : InstAlias<"autibz", (AUTIBZ), 0>;
948+
def : InstAlias<"paciasp", (PACIASP), 0>;
949+
def : InstAlias<"pacibsp", (PACIBSP), 0>;
950+
def : InstAlias<"autiasp", (AUTIASP), 0>;
951+
def : InstAlias<"autibsp", (AUTIBSP), 0>;
952+
def : InstAlias<"pacia1716", (PACIA1716), 0>;
953+
def : InstAlias<"pacib1716", (PACIB1716), 0>;
954+
def : InstAlias<"autia1716", (AUTIA1716), 0>;
955+
def : InstAlias<"autib1716", (AUTIB1716), 0>;
956+
def : InstAlias<"xpaclri", (XPACLRI), 0>;
957+
940958
// These pointer authentication instructions require armv8.3a
941959
let Predicates = [HasPA] in {
942960
multiclass SignAuth<bits<3> prefix, bits<3> prefix_z, string asm,
@@ -951,7 +969,7 @@ let Predicates = [HasPA] in {
951969
def DZB : SignAuthZero<prefix_z, 0b11, !strconcat(asm, "dzb"), op>;
952970
}
953971

954-
// When compiling with PA, there is a better mnemonic for these instructions.
972+
// When PA is enabled, a better mnemonic should be emitted.
955973
def : InstAlias<"paciaz", (PACIAZ), 1>;
956974
def : InstAlias<"pacibz", (PACIBZ), 1>;
957975
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)