Skip to content

Commit f68a415

Browse files
[LLVM][AArch64] Replace MnemonicAlias with InstAlias for CAS* instructions
Replaces the MnemonicAliases added for compare and swap instructions to use InstAlias. This ensures we don't try to map to instructions where the operands do not match when both the LSE & LSUI features are available.
1 parent b74176a commit f68a415

File tree

3 files changed

+99
-8
lines changed

3 files changed

+99
-8
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.td

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,21 +2665,25 @@ defm CASLT : CompareAndSwapUnprivileged<0b11, 0, 1, "l">;
26652665
defm CASAT : CompareAndSwapUnprivileged<0b11, 1, 0, "a">;
26662666
defm CASALT : CompareAndSwapUnprivileged<0b11, 1, 1, "al">;
26672667

2668-
def : MnemonicAlias<"cas", "cast">;
2669-
def : MnemonicAlias<"casl", "caslt">;
2670-
def : MnemonicAlias<"casa", "casat">;
2671-
def : MnemonicAlias<"casal", "casalt">;
2668+
def : InstAlias<"cast $Rs, $Rt, [$Rn]", (CASX GPR64:$Rs, GPR64:$Rt, GPR64sp0:$Rn)>;
2669+
def : InstAlias<"caslt $Rs, $Rt, [$Rn]", (CASLX GPR64:$Rs, GPR64:$Rt, GPR64sp0:$Rn)>;
2670+
def : InstAlias<"casat $Rs, $Rt, [$Rn]", (CASAX GPR64:$Rs, GPR64:$Rt, GPR64sp0:$Rn)>;
2671+
def : InstAlias<"casalt $Rs, $Rt, [$Rn]", (CASALX GPR64:$Rs, GPR64:$Rt, GPR64sp0:$Rn)>;
26722672

26732673
// v9.6-a atomic CASPT
26742674
defm CASPT : CompareAndSwapPairUnprivileged<0b01, 0, 0, "">;
26752675
defm CASPLT : CompareAndSwapPairUnprivileged<0b01, 0, 1, "l">;
26762676
defm CASPAT : CompareAndSwapPairUnprivileged<0b01, 1, 0, "a">;
26772677
defm CASPALT : CompareAndSwapPairUnprivileged<0b01, 1, 1, "al">;
26782678

2679-
def : MnemonicAlias<"casp", "caspt">;
2680-
def : MnemonicAlias<"caspl", "casplt">;
2681-
def : MnemonicAlias<"caspa", "caspat">;
2682-
def : MnemonicAlias<"caspal", "caspalt">;
2679+
def : InstAlias<"caspt $Rs, $Rt, [$Rn]",
2680+
(CASPX XSeqPairClassOperand:$Rs, XSeqPairClassOperand:$Rt, GPR64sp0:$Rn)>;
2681+
def : InstAlias<"casplt $Rs, $Rt, [$Rn]",
2682+
(CASPLX XSeqPairClassOperand:$Rs, XSeqPairClassOperand:$Rt, GPR64sp0:$Rn)>;
2683+
def : InstAlias<"caspat $Rs, $Rt, [$Rn]",
2684+
(CASPAX XSeqPairClassOperand:$Rs, XSeqPairClassOperand:$Rt, GPR64sp0:$Rn)>;
2685+
def : InstAlias<"caspalt $Rs, $Rt, [$Rn]",
2686+
(CASPALX XSeqPairClassOperand:$Rs, XSeqPairClassOperand:$Rt, GPR64sp0:$Rn)>;
26832687
}
26842688

26852689
// v8.1 atomic SWP

llvm/test/MC/AArch64/armv8.1a-lse.s

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// RUN: not llvm-mc -triple aarch64-none-linux-gnu -mcpu=tsv110 -show-encoding < %s 2> %t | FileCheck %s
88
// RUN: FileCheck -check-prefix=CHECK-ERROR < %t %s
99
// RUN: not llvm-mc -triple aarch64-none-linux-gnu -mattr=+v8r -show-encoding < %s 2> %t | FileCheck %s
10+
// RUN: FileCheck -check-prefix=CHECK-ERROR < %t %s
11+
// RUN: not llvm-mc -triple aarch64-none-linux-gnu -mattr=+v8.1a,+lse,+lsui -show-encoding < %s 2> %t | FileCheck %s -check-prefix=CHECK-FEAT-LSUI
1012
// RUN: FileCheck -check-prefix=CHECK-ERROR < %t %s
1113
.text
1214

@@ -78,6 +80,15 @@
7880
// CHECK: casal x0, x1, [x2] // encoding: [0x41,0xfc,0xe0,0xc8]
7981
// CHECK: casal x2, x3, [sp] // encoding: [0xe3,0xff,0xe2,0xc8]
8082

83+
// CHECK-FEAT-LSUI: cast x0, x1, [x2] // encoding: [0x41,0x7c,0xa0,0xc8]
84+
// CHECK-FEAT-LSUI: cast x2, x3, [sp] // encoding: [0xe3,0x7f,0xa2,0xc8]
85+
// CHECK-FEAT-LSUI: casat x0, x1, [x2] // encoding: [0x41,0x7c,0xe0,0xc8]
86+
// CHECK-FEAT-LSUI: casat x2, x3, [sp] // encoding: [0xe3,0x7f,0xe2,0xc8]
87+
// CHECK-FEAT-LSUI: caslt x0, x1, [x2] // encoding: [0x41,0xfc,0xa0,0xc8]
88+
// CHECK-FEAT-LSUI: caslt x2, x3, [sp] // encoding: [0xe3,0xff,0xa2,0xc8]
89+
// CHECK-FEAT-LSUI: casalt x0, x1, [x2] // encoding: [0x41,0xfc,0xe0,0xc8]
90+
// CHECK-FEAT-LSUI: casalt x2, x3, [sp] // encoding: [0xe3,0xff,0xe2,0xc8]
91+
8192
swp w0, w1, [x2]
8293
swp w2, w3, [sp]
8394
swpa w0, w1, [x2]
@@ -95,6 +106,15 @@
95106
// CHECK: swpal w0, w1, [x2] // encoding: [0x41,0x80,0xe0,0xb8]
96107
// CHECK: swpal w2, w3, [sp] // encoding: [0xe3,0x83,0xe2,0xb8]
97108

109+
// CHECK-FEAT-LSUI: swpt w0, w1, [x2] // encoding: [0x41,0x84,0x20,0x19]
110+
// CHECK-FEAT-LSUI: swpt w2, w3, [sp] // encoding: [0xe3,0x87,0x22,0x19]
111+
// CHECK-FEAT-LSUI: swpta w0, w1, [x2] // encoding: [0x41,0x84,0xa0,0x19]
112+
// CHECK-FEAT-LSUI: swpta w2, w3, [sp] // encoding: [0xe3,0x87,0xa2,0x19]
113+
// CHECK-FEAT-LSUI: swptl w0, w1, [x2] // encoding: [0x41,0x84,0x60,0x19]
114+
// CHECK-FEAT-LSUI: swptl w2, w3, [sp] // encoding: [0xe3,0x87,0x62,0x19]
115+
// CHECK-FEAT-LSUI: swptal w0, w1, [x2] // encoding: [0x41,0x84,0xe0,0x19]
116+
// CHECK-FEAT-LSUI: swptal w2, w3, [sp] // encoding: [0xe3,0x87,0xe2,0x19]
117+
98118
swpb w0, w1, [x2]
99119
swpb w2, w3, [sp]
100120
swph w0, w1, [x2]
@@ -112,6 +132,15 @@
112132
// CHECK: swplb w0, w1, [x2] // encoding: [0x41,0x80,0x60,0x38]
113133
// CHECK: swplb w2, w3, [sp] // encoding: [0xe3,0x83,0x62,0x38]
114134

135+
// CHECK-FEAT-LSUI: swpt x0, x1, [x2] // encoding: [0x41,0x84,0x20,0x59]
136+
// CHECK-FEAT-LSUI: swpt x2, x3, [sp] // encoding: [0xe3,0x87,0x22,0x59]
137+
// CHECK-FEAT-LSUI: swpta x0, x1, [x2] // encoding: [0x41,0x84,0xa0,0x59]
138+
// CHECK-FEAT-LSUI: swpta x2, x3, [sp] // encoding: [0xe3,0x87,0xa2,0x59]
139+
// CHECK-FEAT-LSUI: swptl x0, x1, [x2] // encoding: [0x41,0x84,0x60,0x59]
140+
// CHECK-FEAT-LSUI: swptl x2, x3, [sp] // encoding: [0xe3,0x87,0x62,0x59]
141+
// CHECK-FEAT-LSUI: swptal x0, x1, [x2] // encoding: [0x41,0x84,0xe0,0x59]
142+
// CHECK-FEAT-LSUI: swptal x2, x3, [sp] // encoding: [0xe3,0x87,0xe2,0x59]
143+
115144
swpalb w0, w1, [x2]
116145
swpalb w2, w3, [sp]
117146
swpah w0, w1, [x2]
@@ -163,6 +192,15 @@
163192
// CHECK: caspa x0, x1, x2, x3, [x2] // encoding: [0x42,0x7c,0x60,0x48]
164193
// CHECK: caspa x4, x5, x6, x7, [sp] // encoding: [0xe6,0x7f,0x64,0x48]
165194

195+
// CHECK-FEAT-LSUI: casp w0, w1, w2, w3, [x5] // encoding: [0xa2,0x7c,0x20,0x08]
196+
// CHECK-FEAT-LSUI: casp w4, w5, w6, w7, [sp] // encoding: [0xe6,0x7f,0x24,0x08]
197+
// CHECK-FEAT-LSUI: caspt x0, x1, x2, x3, [x2] // encoding: [0x42,0x7c,0x20,0x48]
198+
// CHECK-FEAT-LSUI: caspt x4, x5, x6, x7, [sp] // encoding: [0xe6,0x7f,0x24,0x48]
199+
// CHECK-FEAT-LSUI: caspa w0, w1, w2, w3, [x5] // encoding: [0xa2,0x7c,0x60,0x08]
200+
// CHECK-FEAT-LSUI: caspa w4, w5, w6, w7, [sp] // encoding: [0xe6,0x7f,0x64,0x08]
201+
// CHECK-FEAT-LSUI: caspat x0, x1, x2, x3, [x2] // encoding: [0x42,0x7c,0x60,0x48]
202+
// CHECK-FEAT-LSUI: caspat x4, x5, x6, x7, [sp] // encoding: [0xe6,0x7f,0x64,0x48]
203+
166204
caspl w0, w1, w2, w3, [x5]
167205
caspl w4, w5, w6, w7, [sp]
168206
caspl x0, x1, x2, x3, [x2]
@@ -180,6 +218,15 @@
180218
// CHECK: caspal x0, x1, x2, x3, [x2] // encoding: [0x42,0xfc,0x60,0x48]
181219
// CHECK: caspal x4, x5, x6, x7, [sp] // encoding: [0xe6,0xff,0x64,0x48]
182220

221+
// CHECK-FEAT-LSUI: caspl w0, w1, w2, w3, [x5] // encoding: [0xa2,0xfc,0x20,0x08]
222+
// CHECK-FEAT-LSUI: caspl w4, w5, w6, w7, [sp] // encoding: [0xe6,0xff,0x24,0x08]
223+
// CHECK-FEAT-LSUI: casplt x0, x1, x2, x3, [x2] // encoding: [0x42,0xfc,0x20,0x48]
224+
// CHECK-FEAT-LSUI: casplt x4, x5, x6, x7, [sp] // encoding: [0xe6,0xff,0x24,0x48]
225+
// CHECK-FEAT-LSUI: caspal w0, w1, w2, w3, [x5] // encoding: [0xa2,0xfc,0x60,0x08]
226+
// CHECK-FEAT-LSUI: caspal w4, w5, w6, w7, [sp] // encoding: [0xe6,0xff,0x64,0x08]
227+
// CHECK-FEAT-LSUI: caspalt x0, x1, x2, x3, [x2] // encoding: [0x42,0xfc,0x60,0x48]
228+
// CHECK-FEAT-LSUI: caspalt x4, x5, x6, x7, [sp] // encoding: [0xe6,0xff,0x64,0x48]
229+
183230
ldadd w0, w1, [x2]
184231
ldadd w2, w3, [sp]
185232
ldadda w0, w1, [x2]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: llvm-mc -triple aarch64 -mattr=+lse -mattr=+lsui -show-encoding %s | FileCheck %s
2+
// RUN: not llvm-mc -triple aarch64 -mattr=+lsui -show-encoding %s 2>&1 | FileCheck %s --check-prefix=ERROR
3+
4+
_func:
5+
// CHECK: _func:
6+
7+
//------------------------------------------------------------------------------
8+
// CAS(P)T instructions
9+
//------------------------------------------------------------------------------
10+
cas w26, w28, [x21]
11+
// CHECK: cas w26, w28, [x21]
12+
// ERROR: error: instruction requires: lse
13+
14+
casl w26, w28, [x21]
15+
// CHECK: casl w26, w28, [x21]
16+
// ERROR: error: instruction requires: lse
17+
18+
casa w26, w28, [x21]
19+
// CHECK: casa w26, w28, [x21]
20+
// ERROR: error: instruction requires: lse
21+
22+
casal w26, w28, [x21]
23+
// CHECK: casal w26, w28, [x21]
24+
// ERROR: error: instruction requires: lse
25+
26+
casp w26, w27, w28, w29, [x21]
27+
// CHECK: casp w26, w27, w28, w29, [x21]
28+
// ERROR: error: instruction requires: lse
29+
30+
caspl w26, w27, w28, w29, [x21]
31+
// CHECK: caspl w26, w27, w28, w29, [x21]
32+
// ERROR: error: instruction requires: lse
33+
34+
caspa w26, w27, w28, w29, [x21]
35+
// CHECK: caspa w26, w27, w28, w29, [x21]
36+
// ERROR: error: instruction requires: lse
37+
38+
caspal w26, w27, w28, w29, [x21]
39+
// CHECK: caspal w26, w27, w28, w29, [x21]
40+
// ERROR: error: instruction requires: lse

0 commit comments

Comments
 (0)