Skip to content

Commit 7563231

Browse files
committed
[AMDGPU][MC] Disallow null as saddr in flat instructions
Some flat instructions have an saddr operand. When 'null' is provided as saddr, it may have the same encoding as another instruction. For example, the instructions 'global_atomic_add v1, v2, null' and 'global_atomic_add v[1:2], v2, off' have the same encoding. This patch disallows having null as saddr.
1 parent 0a6a3c1 commit 7563231

File tree

7 files changed

+825
-6
lines changed

7 files changed

+825
-6
lines changed

llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ DECODE_OPERAND_REG_7(SReg_32_XM0_XEXEC, OPW32)
293293
DECODE_OPERAND_REG_7(SReg_32_XEXEC_HI, OPW32)
294294
DECODE_OPERAND_REG_7(SReg_64, OPW64)
295295
DECODE_OPERAND_REG_7(SReg_64_XEXEC, OPW64)
296+
DECODE_OPERAND_REG_7(SReg_64_XEXEC_XNULL, OPW64)
296297
DECODE_OPERAND_REG_7(SReg_96, OPW96)
297298
DECODE_OPERAND_REG_7(SReg_128, OPW128)
298299
DECODE_OPERAND_REG_7(SReg_256, OPW256)

llvm/lib/Target/AMDGPU/FLATInstructions.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class FLAT_Load_Pseudo <string opName, RegisterClass regClass,
207207
!con(
208208
!con(
209209
!if(EnableSaddr,
210-
(ins SReg_64:$saddr, VGPR_32:$vaddr),
210+
(ins SReg_64_XEXEC_XNULL:$saddr, VGPR_32:$vaddr),
211211
(ins VReg_64:$vaddr)),
212212
(ins flat_offset:$offset)),
213213
// FIXME: Operands with default values do not work with following non-optional operands.
@@ -229,7 +229,7 @@ class FLAT_Store_Pseudo <string opName, RegisterClass vdataClass,
229229
(outs),
230230
!con(
231231
!if(EnableSaddr,
232-
(ins VGPR_32:$vaddr, getLdStRegisterOperand<vdataClass>.ret:$vdata, SReg_64:$saddr),
232+
(ins VGPR_32:$vaddr, getLdStRegisterOperand<vdataClass>.ret:$vdata, SReg_64_XEXEC_XNULL:$saddr),
233233
(ins VReg_64:$vaddr, getLdStRegisterOperand<vdataClass>.ret:$vdata)),
234234
(ins flat_offset:$offset, CPol_0:$cpol)),
235235
" $vaddr, $vdata"#!if(HasSaddr, !if(EnableSaddr, ", $saddr", ", off"), "")#"$offset$cpol"> {
@@ -587,7 +587,7 @@ multiclass FLAT_Global_Atomic_Pseudo_NO_RTN<
587587

588588
def _SADDR : FLAT_AtomicNoRet_Pseudo <opName,
589589
(outs),
590-
(ins VGPR_32:$vaddr, data_op:$vdata, SReg_64:$saddr, flat_offset:$offset, CPol_0:$cpol),
590+
(ins VGPR_32:$vaddr, data_op:$vdata, SReg_64_XEXEC_XNULL:$saddr, flat_offset:$offset, CPol_0:$cpol),
591591
" $vaddr, $vdata, $saddr$offset$cpol">,
592592
GlobalSaddrTable<1, opName> {
593593
let has_saddr = 1;
@@ -618,7 +618,7 @@ multiclass FLAT_Global_Atomic_Pseudo_RTN<
618618

619619
def _SADDR_RTN : FLAT_AtomicRet_Pseudo <opName,
620620
(outs vdst_op:$vdst),
621-
(ins VGPR_32:$vaddr, data_op:$vdata, SReg_64:$saddr, flat_offset:$offset, CPol_GLC1:$cpol),
621+
(ins VGPR_32:$vaddr, data_op:$vdata, SReg_64_XEXEC_XNULL:$saddr, flat_offset:$offset, CPol_GLC1:$cpol),
622622
" $vdst, $vaddr, $vdata, $saddr$offset$cpol">,
623623
GlobalSaddrTable<1, opName#"_rtn"> {
624624
let has_saddr = 1;

llvm/lib/Target/AMDGPU/SIRegisterInfo.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,14 @@ def TTMP_64 : SIRegisterClass<"AMDGPU", [v2i32, i64, f64, v4i16, v4f16, v4bf16],
845845
let HasSGPR = 1;
846846
}
847847

848+
def SReg_64_XEXEC_XNULL : SIRegisterClass<"AMDGPU", [v2i32, i64, v2f32, f64, i1, v4i16, v4f16, v4bf16], 32,
849+
(add SGPR_64, VCC, FLAT_SCR, XNACK_MASK, SRC_SHARED_BASE,
850+
SRC_SHARED_LIMIT, SRC_PRIVATE_BASE, SRC_PRIVATE_LIMIT, TTMP_64, TBA, TMA)> {
851+
let CopyCost = 1;
852+
let AllocationPriority = 1;
853+
let HasSGPR = 1;
854+
}
855+
848856
def SReg_64_XEXEC : SIRegisterClass<"AMDGPU", [v2i32, i64, v2f32, f64, i1, v4i16, v4f16, v4bf16], 32,
849857
(add SGPR_64, VCC, FLAT_SCR, XNACK_MASK, SGPR_NULL64, SRC_SHARED_BASE,
850858
SRC_SHARED_LIMIT, SRC_PRIVATE_BASE, SRC_PRIVATE_LIMIT, TTMP_64, TBA, TMA)> {

llvm/test/MC/AMDGPU/flat-global.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ global_store_dword v3, v1, s[2:3] offset:-8
212212

213213
// XXX: Is this valid?
214214
global_store_dword v3, v1, exec
215-
// GFX10: encoding: [0x00,0x80,0x70,0xdc,0x03,0x01,0x7e,0x00]
216-
// GFX9: global_store_dword v3, v1, exec ; encoding: [0x00,0x80,0x70,0xdc,0x03,0x01,0x7e,0x00]
215+
// GFX10-ERR: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
216+
// GFX9-ERR: :[[@LINE-2]]:{{[0-9]+}}: error: invalid operand for instruction
217217
// VI-ERR: :[[@LINE-3]]:{{[0-9]+}}: error: instruction not supported on this GPU
218218

219219
global_load_dword v1, v[3:4], s2
Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
// RUN: not llvm-mc -triple=amdgcn -mcpu=gfx1010 %s 2>&1 | FileCheck --check-prefixes=GFX1010,GFX10 --implicit-check-not=error: %s
2+
// RUN: not llvm-mc -triple=amdgcn -mcpu=gfx1030 %s 2>&1 | FileCheck --check-prefixes=GFX1030,GFX10 --implicit-check-not=error: %s
3+
4+
global_atomic_add v2, v4, null
5+
// GFX10: :[[@LINE-1]]:27: error: invalid operand for instruction
6+
7+
global_atomic_add v0, v2, v4, null glc
8+
// GFX10: :[[@LINE-1]]:31: error: invalid operand for instruction
9+
10+
global_atomic_add_x2 v2, v[4:5], null
11+
// GFX10: :[[@LINE-1]]:34: error: invalid operand for instruction
12+
13+
global_atomic_add_x2 v[0:1], v2, v[4:5], null
14+
// GFX10: :[[@LINE-1]]:42: error: invalid operand for instruction
15+
16+
global_atomic_and v2, v4, null
17+
// GFX10: :[[@LINE-1]]:27: error: invalid operand for instruction
18+
19+
global_atomic_and v0, v2, v4, null
20+
// GFX10: :[[@LINE-1]]:31: error: invalid operand for instruction
21+
22+
global_atomic_and_x2 v2, v[4:5], null
23+
// GFX10: :[[@LINE-1]]:34: error: invalid operand for instruction
24+
25+
global_atomic_and_x2 v0, v2, v[4:5], null
26+
// GFX10: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
27+
28+
global_atomic_cmpswap v2, v[4:5], null
29+
// GFX10: :[[@LINE-1]]:35: error: invalid operand for instruction
30+
31+
global_atomic_cmpswap v0, v2, v[4:5], null
32+
// GFX10: :[[@LINE-1]]:39: error: invalid operand for instruction
33+
34+
global_atomic_cmpswap_x2 v2, v[4:7], null
35+
// GFX10: :[[@LINE-1]]:38: error: invalid operand for instruction
36+
37+
global_atomic_cmpswap_x2 v[0:1], v2, v[4:7], null
38+
// GFX10: :[[@LINE-1]]:46: error: invalid operand for instruction
39+
40+
global_atomic_csub v2, v4, null
41+
// GFX1010: :[[@LINE-1]]:{{[0-9]+}}: error: instruction not supported on this GPU
42+
// GFX1030: :[[@LINE-2]]:28: error: invalid operand for instruction
43+
44+
global_atomic_csub v0, v2, v4, null
45+
// GFX1010: :[[@LINE-1]]:{{[0-9]+}}: error: instruction not supported on this GPU
46+
// GFX1030: :[[@LINE-2]]:32: error: invalid operand for instruction
47+
48+
global_atomic_dec v2, v4, null
49+
// GFX10: :[[@LINE-1]]:27: error: invalid operand for instruction
50+
51+
global_atomic_dec v0, v2, v4, null
52+
// GFX10: :[[@LINE-1]]:31: error: invalid operand for instruction
53+
54+
global_atomic_dec_x2 v2, v[4:5], null
55+
// GFX10: :[[@LINE-1]]:34: error: invalid operand for instruction
56+
57+
global_atomic_dec_x2 v[0:1], v2, v[4:5], null
58+
// GFX10: :[[@LINE-1]]:42: error: invalid operand for instruction
59+
60+
global_atomic_fcmpswap v2, v[4:5], null
61+
// GFX10: :[[@LINE-1]]:36: error: invalid operand for instruction
62+
63+
global_atomic_fcmpswap v0, v2, v[4:5], null
64+
// GFX10: :[[@LINE-1]]:40: error: invalid operand for instruction
65+
66+
global_atomic_fcmpswap_x2 v2, v[4:7], null
67+
// GFX10: :[[@LINE-1]]:39: error: invalid operand for instruction
68+
69+
global_atomic_fcmpswap_x2 v[0:1], v2, v[4:7], null
70+
// GFX10: :[[@LINE-1]]:47: error: invalid operand for instruction
71+
72+
global_atomic_fmax v2, v4, null
73+
// GFX10: :[[@LINE-1]]:28: error: invalid operand for instruction
74+
75+
global_atomic_fmax v0, v2, v4, null
76+
// GFX10: :[[@LINE-1]]:32: error: invalid operand for instruction
77+
78+
global_atomic_fmax_x2 v2, v[4:5], null
79+
// GFX10: :[[@LINE-1]]:35: error: invalid operand for instruction
80+
81+
global_atomic_fmax_x2 v[0:1], v2, v[4:5], null
82+
// GFX10: :[[@LINE-1]]:43: error: invalid operand for instruction
83+
84+
global_atomic_fmin v2, v4, null
85+
// GFX10: :[[@LINE-1]]:28: error: invalid operand for instruction
86+
87+
global_atomic_fmin v0, v2, v4, null
88+
// GFX10: :[[@LINE-1]]:32: error: invalid operand for instruction
89+
90+
global_atomic_fmin_x2 v2, v[4:5], null
91+
// GFX10: :[[@LINE-1]]:35: error: invalid operand for instruction
92+
93+
global_atomic_fmin_x2 v[0:1], v2, v[4:5], null
94+
// GFX10: :[[@LINE-1]]:43: error: invalid operand for instruction
95+
96+
global_atomic_inc v2, v4, null
97+
// GFX10: :[[@LINE-1]]:27: error: invalid operand for instruction
98+
99+
global_atomic_inc v0, v2, v4, null
100+
// GFX10: :[[@LINE-1]]:31: error: invalid operand for instruction
101+
102+
global_atomic_inc_x2 v2, v[4:5], null
103+
// GFX10: :[[@LINE-1]]:34: error: invalid operand for instruction
104+
105+
global_atomic_inc_x2 v[0:1], v2, v[4:5], null
106+
// GFX10: :[[@LINE-1]]:42: error: invalid operand for instruction
107+
108+
global_atomic_or v2, v4, null
109+
// GFX10: :[[@LINE-1]]:26: error: invalid operand for instruction
110+
111+
global_atomic_or v0, v2, v4, null
112+
// GFX10: :[[@LINE-1]]:30: error: invalid operand for instruction
113+
114+
global_atomic_or_x2 v2, v[4:5], null
115+
// GFX10: :[[@LINE-1]]:33: error: invalid operand for instruction
116+
117+
global_atomic_or_x2 v[0:1], v2, v[4:5], null
118+
// GFX10: :[[@LINE-1]]:41: error: invalid operand for instruction
119+
120+
global_atomic_smax v2, v4, null
121+
// GFX10: :[[@LINE-1]]:28: error: invalid operand for instruction
122+
123+
global_atomic_smax v0, v2, v4, null
124+
// GFX10: :[[@LINE-1]]:32: error: invalid operand for instruction
125+
126+
global_atomic_smax_x2 v2, v[4:5], null
127+
// GFX10: :[[@LINE-1]]:35: error: invalid operand for instruction
128+
129+
global_atomic_smax_x2 v[0:1], v2, v[4:5], null
130+
// GFX10: :[[@LINE-1]]:43: error: invalid operand for instruction
131+
132+
global_atomic_smin v2, v4, null
133+
// GFX10: :[[@LINE-1]]:28: error: invalid operand for instruction
134+
135+
global_atomic_smin v0, v2, v4, null
136+
// GFX10: :[[@LINE-1]]:32: error: invalid operand for instruction
137+
138+
global_atomic_smin_x2 v2, v[4:5], null
139+
// GFX10: :[[@LINE-1]]:35: error: invalid operand for instruction
140+
141+
global_atomic_smin_x2 v[0:1], v2, v[4:5], null
142+
// GFX10: :[[@LINE-1]]:43: error: invalid operand for instruction
143+
144+
global_atomic_sub v2, v4, null
145+
// GFX10: :[[@LINE-1]]:27: error: invalid operand for instruction
146+
147+
global_atomic_sub v0, v2, v4, null
148+
// GFX10: :[[@LINE-1]]:31: error: invalid operand for instruction
149+
150+
global_atomic_sub_x2 v2, v[4:5], null
151+
// GFX10: :[[@LINE-1]]:34: error: invalid operand for instruction
152+
153+
global_atomic_sub_x2 v[0:1], v2, v[4:5], null
154+
// GFX10: :[[@LINE-1]]:42: error: invalid operand for instruction
155+
156+
global_atomic_swap v2, v4, null
157+
// GFX10: :[[@LINE-1]]:28: error: invalid operand for instruction
158+
159+
global_atomic_swap v0, v2, v4, null
160+
// GFX10: :[[@LINE-1]]:32: error: invalid operand for instruction
161+
162+
global_atomic_swap_x2 v2, v[4:5], null
163+
// GFX10: :[[@LINE-1]]:35: error: invalid operand for instruction
164+
165+
global_atomic_swap_x2 v[0:1], v2, v[4:5], null
166+
// GFX10: :[[@LINE-1]]:43: error: invalid operand for instruction
167+
168+
global_atomic_umax v2, v4, null
169+
// GFX10: :[[@LINE-1]]:28: error: invalid operand for instruction
170+
171+
global_atomic_umax v0, v2, v4, null
172+
// GFX10: :[[@LINE-1]]:32: error: invalid operand for instruction
173+
174+
global_atomic_umax_x2 v2, v[4:5], null
175+
// GFX10: :[[@LINE-1]]:35: error: invalid operand for instruction
176+
177+
global_atomic_umax_x2 v[0:1], v2, v[4:5], null
178+
// GFX10: :[[@LINE-1]]:43: error: invalid operand for instruction
179+
180+
global_atomic_umin v2, v4, null
181+
// GFX10: :[[@LINE-1]]:28: error: invalid operand for instruction
182+
183+
global_atomic_umin v0, v2, v4, null
184+
// GFX10: :[[@LINE-1]]:32: error: invalid operand for instruction
185+
186+
global_atomic_umin_x2 v2, v[4:5], null
187+
// GFX10: :[[@LINE-1]]:35: error: invalid operand for instruction
188+
189+
global_atomic_umin_x2 v[0:1], v2, v[4:5], null
190+
// GFX10: :[[@LINE-1]]:43: error: invalid operand for instruction
191+
192+
global_atomic_xor v2, v4, null
193+
// GFX10: :[[@LINE-1]]:27: error: invalid operand for instruction
194+
195+
global_atomic_xor v0, v2, v4, null
196+
// GFX10: :[[@LINE-1]]:31: error: invalid operand for instruction
197+
198+
global_atomic_xor_x2 v2, v[4:5], null
199+
// GFX10: :[[@LINE-1]]:34: error: invalid operand for instruction
200+
201+
global_atomic_xor_x2 v[0:1], v2, v[4:5], null
202+
// GFX10: :[[@LINE-1]]:42: error: invalid operand for instruction
203+
204+
global_load_dword v0, v4, null
205+
// GFX10: :[[@LINE-1]]:27: error: invalid operand for instruction
206+
207+
global_load_dwordx2 v[0:1], v4, null
208+
// GFX10: :[[@LINE-1]]:33: error: invalid operand for instruction
209+
210+
global_load_dwordx3 v[0:2], v4, null
211+
// GFX10: :[[@LINE-1]]:33: error: invalid operand for instruction
212+
213+
global_load_dwordx4 v[0:3], v4, null
214+
// GFX10: :[[@LINE-1]]:33: error: invalid operand for instruction
215+
216+
global_load_sbyte v0, v2, null
217+
// GFX10: :[[@LINE-1]]:27: error: invalid operand for instruction
218+
219+
global_load_sbyte_d16 v0, v2, null
220+
// GFX10: :[[@LINE-1]]:31: error: invalid operand for instruction
221+
222+
global_load_sbyte_d16_hi v0, v2, null
223+
// GFX10: :[[@LINE-1]]:34: error: invalid operand for instruction
224+
225+
global_load_short_d16 v0, v2, null
226+
// GFX10: :[[@LINE-1]]:31: error: invalid operand for instruction
227+
228+
global_load_short_d16_hi v0, v2, null
229+
// GFX10: :[[@LINE-1]]:34: error: invalid operand for instruction
230+
231+
global_load_sshort v0, v2, null
232+
// GFX10: :[[@LINE-1]]:28: error: invalid operand for instruction
233+
234+
global_load_ubyte v0, v2, null
235+
// GFX10: :[[@LINE-1]]:27: error: invalid operand for instruction
236+
237+
global_load_ubyte_d16 v0, v2, null
238+
// GFX10: :[[@LINE-1]]:31: error: invalid operand for instruction
239+
240+
global_load_ubyte_d16_hi v0, v2, null
241+
// GFX10: :[[@LINE-1]]:34: error: invalid operand for instruction
242+
243+
global_load_ushort v0, v2, null
244+
// GFX10: :[[@LINE-1]]:28: error: invalid operand for instruction
245+
246+
global_store_byte v0, v2, null
247+
// GFX10: :[[@LINE-1]]:27: error: invalid operand for instruction
248+
249+
global_store_byte_d16_hi v0, v2, null
250+
// GFX10: :[[@LINE-1]]:34: error: invalid operand for instruction
251+
252+
global_store_dword v0, v2, null
253+
// GFX10: :[[@LINE-1]]:28: error: invalid operand for instruction
254+
255+
global_store_dwordx2 v0, v[2:3], null
256+
// GFX10: :[[@LINE-1]]:34: error: invalid operand for instruction
257+
258+
global_store_dwordx3 v0, v[2:4], null
259+
// GFX10: :[[@LINE-1]]:34: error: invalid operand for instruction
260+
261+
global_store_dwordx4 v0, v[2:5], null
262+
// GFX10: :[[@LINE-1]]:34: error: invalid operand for instruction
263+
264+
global_store_short v0, v2, null
265+
// GFX10: :[[@LINE-1]]:28: error: invalid operand for instruction
266+
267+
global_store_short_d16_hi v0, v2, null
268+
// GFX10: :[[@LINE-1]]:35: error: invalid operand for instruction

0 commit comments

Comments
 (0)