1 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=kaveri -mattr=-promote-alloca -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,CI,MUBUF %s
2 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -mattr=-promote-alloca -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,GFX9,GFX9-MUBUF,MUBUF %s
3 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -mattr=-promote-alloca,+enable-flat-scratch -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,GFX9,GFX9-FLATSCR %s
4 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 < %s | FileCheck --check-prefixes=GFX11 %s
6 ; Test that non-entry function frame indices are expanded properly to
7 ; give an index relative to the scratch wave offset register
9 ; Materialize into a mov. Make sure there isn't an unnecessary copy.
10 ; GCN-LABEL: {{^}}func_mov_fi_i32:
11 ; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
13 ; CI-NEXT: v_lshr_b32_e64 v0, s32, 6
14 ; GFX9-MUBUF-NEXT: v_lshrrev_b32_e64 v0, 6, s32
16 ; GFX9-FLATSCR: v_mov_b32_e32 v0, s32
17 ; GFX9-FLATSCR-NOT: v_lshrrev_b32_e64
21 ; GCN: ds_write_b32 v0, v0
22 define void @func_mov_fi_i32() #0 {
23 %alloca = alloca i32, addrspace(5)
24 store volatile ptr addrspace(5) %alloca, ptr addrspace(3) undef
28 ; Offset due to different objects
29 ; GCN-LABEL: {{^}}func_mov_fi_i32_offset:
30 ; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
32 ; CI-DAG: v_lshr_b32_e64 v0, s32, 6
34 ; CI: ds_write_b32 v0, v0
35 ; CI-NEXT: v_lshr_b32_e64 [[SCALED:v[0-9]+]], s32, 6
36 ; CI-NEXT: v_add_i32_e{{32|64}} v0, {{s\[[0-9]+:[0-9]+\]|vcc}}, 4, [[SCALED]]
37 ; CI-NEXT: ds_write_b32 v0, v0
39 ; GFX9-MUBUF-NEXT: v_lshrrev_b32_e64 v0, 6, s32
40 ; GFX9-FLATSCR: v_mov_b32_e32 v0, s32
41 ; GFX9-FLATSCR: s_add_i32 [[ADD:[^,]+]], s32, 4
42 ; GFX9-NEXT: ds_write_b32 v0, v0
43 ; GFX9-MUBUF-NEXT: v_lshrrev_b32_e64 [[SCALED:v[0-9]+]], 6, s32
44 ; GFX9-MUBUF-NEXT: v_add_u32_e32 v0, 4, [[SCALED]]
45 ; GFX9-FLATSCR-NEXT: v_mov_b32_e32 v0, [[ADD]]
46 ; GFX9-NEXT: ds_write_b32 v0, v0
47 define void @func_mov_fi_i32_offset() #0 {
48 %alloca0 = alloca i32, addrspace(5)
49 %alloca1 = alloca i32, addrspace(5)
50 store volatile ptr addrspace(5) %alloca0, ptr addrspace(3) undef
51 store volatile ptr addrspace(5) %alloca1, ptr addrspace(3) undef
55 ; Materialize into an add of a constant offset from the FI.
56 ; FIXME: Should be able to merge adds
58 ; GCN-LABEL: {{^}}func_add_constant_to_fi_i32:
59 ; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
61 ; CI: v_lshr_b32_e64 [[SCALED:v[0-9]+]], s32, 6
62 ; CI-NEXT: v_add_i32_e32 v0, vcc, 4, [[SCALED]]
64 ; GFX9-MUBUF: v_lshrrev_b32_e64 [[SCALED:v[0-9]+]], 6, s32
65 ; GFX9-MUBUF-NEXT: v_add_u32_e32 v0, 4, [[SCALED]]
67 ; GFX9-FLATSCR: v_mov_b32_e32 [[ADD:v[0-9]+]], s32
68 ; GFX9-FLATSCR-NEXT: v_add_u32_e32 v0, 4, [[ADD]]
71 ; GCN: ds_write_b32 v0, v0
72 define void @func_add_constant_to_fi_i32() #0 {
73 %alloca = alloca [2 x i32], align 4, addrspace(5)
74 %gep0 = getelementptr inbounds [2 x i32], ptr addrspace(5) %alloca, i32 0, i32 1
75 store volatile ptr addrspace(5) %gep0, ptr addrspace(3) undef
79 ; A user the materialized frame index can't be meaningfully folded
81 ; FIXME: Should use s_mul but the frame index always gets materialized into a
84 ; GCN-LABEL: {{^}}func_other_fi_user_i32:
86 ; CI: v_lshr_b32_e64 v0, s32, 6
88 ; GFX9-MUBUF: v_lshrrev_b32_e64 v0, 6, s32
89 ; GFX9-FLATSCR: v_mov_b32_e32 v0, s32
91 ; GCN-NEXT: v_mul_lo_u32 v0, v0, 9
93 ; GCN: ds_write_b32 v0, v0
94 define void @func_other_fi_user_i32() #0 {
95 %alloca = alloca [2 x i32], align 4, addrspace(5)
96 %ptrtoint = ptrtoint ptr addrspace(5) %alloca to i32
97 %mul = mul i32 %ptrtoint, 9
98 store volatile i32 %mul, ptr addrspace(3) undef
102 ; GCN-LABEL: {{^}}func_store_private_arg_i32_ptr:
103 ; GCN: v_mov_b32_e32 v1, 15{{$}}
104 ; MUBUF: buffer_store_dword v1, v0, s[0:3], 0 offen{{$}}
105 ; GFX9-FLATSCR: scratch_store_dword v0, v1, off{{$}}
106 define void @func_store_private_arg_i32_ptr(ptr addrspace(5) %ptr) #0 {
107 store volatile i32 15, ptr addrspace(5) %ptr
111 ; GCN-LABEL: {{^}}func_load_private_arg_i32_ptr:
113 ; MUBUF-NEXT: buffer_load_dword v0, v0, s[0:3], 0 offen glc{{$}}
114 ; GFX9-FLATSCR-NEXT: scratch_load_dword v0, v0, off glc{{$}}
115 define void @func_load_private_arg_i32_ptr(ptr addrspace(5) %ptr) #0 {
116 %val = load volatile i32, ptr addrspace(5) %ptr
120 ; GCN-LABEL: {{^}}void_func_byval_struct_i8_i32_ptr:
123 ; CI: v_lshr_b32_e64 [[SHIFT:v[0-9]+]], s32, 6
124 ; CI-NEXT: v_or_b32_e32 v0, 4, [[SHIFT]]
126 ; GFX9-MUBUF: v_lshrrev_b32_e64 [[SHIFT:v[0-9]+]], 6, s32
127 ; GFX9-MUBUF-NEXT: v_or_b32_e32 v0, 4, [[SHIFT]]
129 ; GFX9-FLATSCR: v_mov_b32_e32 [[SP:v[0-9]+]], s32
130 ; GFX9-FLATSCR-NEXT: v_or_b32_e32 v0, 4, [[SP]]
133 ; GCN: ds_write_b32 v0, v0
134 define void @void_func_byval_struct_i8_i32_ptr(ptr addrspace(5) byval({ i8, i32 }) %arg0) #0 {
135 %gep0 = getelementptr inbounds { i8, i32 }, ptr addrspace(5) %arg0, i32 0, i32 0
136 %gep1 = getelementptr inbounds { i8, i32 }, ptr addrspace(5) %arg0, i32 0, i32 1
137 %load1 = load i32, ptr addrspace(5) %gep1
138 store volatile ptr addrspace(5) %gep1, ptr addrspace(3) undef
142 ; GCN-LABEL: {{^}}void_func_byval_struct_i8_i32_ptr_value:
143 ; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
144 ; MUBUF-NEXT: buffer_load_ubyte v0, off, s[0:3], s32
145 ; MUBUF-NEXT: buffer_load_dword v1, off, s[0:3], s32 offset:4
146 ; GFX9-FLATSCR-NEXT: scratch_load_ubyte v0, off, s32
147 ; GFX9-FLATSCR-NEXT: scratch_load_dword v1, off, s32 offset:4
148 define void @void_func_byval_struct_i8_i32_ptr_value(ptr addrspace(5) byval({ i8, i32 }) %arg0) #0 {
149 %gep0 = getelementptr inbounds { i8, i32 }, ptr addrspace(5) %arg0, i32 0, i32 0
150 %gep1 = getelementptr inbounds { i8, i32 }, ptr addrspace(5) %arg0, i32 0, i32 1
151 %load0 = load i8, ptr addrspace(5) %gep0
152 %load1 = load i32, ptr addrspace(5) %gep1
153 store volatile i8 %load0, ptr addrspace(3) undef
154 store volatile i32 %load1, ptr addrspace(3) undef
158 ; GCN-LABEL: {{^}}void_func_byval_struct_i8_i32_ptr_nonentry_block:
160 ; GCN: s_and_saveexec_b64
162 ; CI: buffer_load_dword v{{[0-9]+}}, off, s[0:3], s32 offset:4 glc{{$}}
163 ; GFX9-MUBUF: buffer_load_dword v{{[0-9]+}}, off, s[0:3], s32 offset:4 glc{{$}}
164 ; GFX9-FLATSCR: scratch_load_dword v{{[0-9]+}}, off, s32 offset:4 glc{{$}}
166 ; CI: v_lshr_b32_e64 [[SHIFT:v[0-9]+]], s32, 6
167 ; CI: v_add_i32_e32 [[GEP:v[0-9]+]], vcc, 4, [[SHIFT]]
169 ; GFX9-MUBUF: v_lshrrev_b32_e64 [[SP:v[0-9]+]], 6, s32
170 ; GFX9-FLATSCR: v_mov_b32_e32 [[SP:v[0-9]+]], s32
172 ; GFX9: v_add_u32_e32 [[GEP:v[0-9]+]], 4, [[SP]]
174 ; GCN: ds_write_b32 v{{[0-9]+}}, [[GEP]]
175 define void @void_func_byval_struct_i8_i32_ptr_nonentry_block(ptr addrspace(5) byval({ i8, i32 }) %arg0, i32 %arg2) #0 {
176 %cmp = icmp eq i32 %arg2, 0
177 br i1 %cmp, label %bb, label %ret
180 %gep0 = getelementptr inbounds { i8, i32 }, ptr addrspace(5) %arg0, i32 0, i32 0
181 %gep1 = getelementptr inbounds { i8, i32 }, ptr addrspace(5) %arg0, i32 0, i32 1
182 %load1 = load volatile i32, ptr addrspace(5) %gep1
183 store volatile ptr addrspace(5) %gep1, ptr addrspace(3) undef
190 ; Added offset can't be used with VOP3 add
191 ; GCN-LABEL: {{^}}func_other_fi_user_non_inline_imm_offset_i32:
193 ; CI-DAG: s_movk_i32 [[K:s[0-9]+|vcc_lo|vcc_hi]], 0x200
194 ; CI-DAG: v_lshr_b32_e64 [[SCALED:v[0-9]+]], s32, 6
195 ; CI: v_add_i32_e32 [[VZ:v[0-9]+]], vcc, [[K]], [[SCALED]]
197 ; GFX9-MUBUF-DAG: v_lshrrev_b32_e64 [[SCALED:v[0-9]+]], 6, s32
198 ; GFX9-MUBUF: v_add_u32_e32 [[VZ:v[0-9]+]], 0x200, [[SCALED]]
200 ; GFX9-FLATSCR-DAG: s_add_i32 [[SZ:[^,]+]], s32, 0x200
201 ; GFX9-FLATSCR: v_mov_b32_e32 [[VZ:v[0-9]+]], [[SZ]]
203 ; GCN: v_mul_lo_u32 [[VZ]], [[VZ]], 9
204 ; GCN: ds_write_b32 v0, [[VZ]]
205 define void @func_other_fi_user_non_inline_imm_offset_i32() #0 {
206 %alloca0 = alloca [128 x i32], align 4, addrspace(5)
207 %alloca1 = alloca [8 x i32], align 4, addrspace(5)
208 %gep0 = getelementptr inbounds [128 x i32], ptr addrspace(5) %alloca0, i32 0, i32 65
209 store volatile i32 7, ptr addrspace(5) %gep0
210 %ptrtoint = ptrtoint ptr addrspace(5) %alloca1 to i32
211 %mul = mul i32 %ptrtoint, 9
212 store volatile i32 %mul, ptr addrspace(3) undef
216 ; GCN-LABEL: {{^}}func_other_fi_user_non_inline_imm_offset_i32_vcc_live:
218 ; CI-DAG: s_movk_i32 [[OFFSET:s[0-9]+]], 0x200
219 ; CI-DAG: v_lshr_b32_e64 [[SCALED:v[0-9]+]], s32, 6
220 ; CI: v_add_i32_e64 [[VZ:v[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, [[OFFSET]], [[SCALED]]
222 ; GFX9-MUBUF-DAG: v_lshrrev_b32_e64 [[SCALED:v[0-9]+]], 6, s32
223 ; GFX9-MUBUF: v_add_u32_e32 [[VZ:v[0-9]+]], 0x200, [[SCALED]]
225 ; GFX9-FLATSCR-DAG: s_add_i32 [[SZ:[^,]+]], s32, 0x200
226 ; GFX9-FLATSCR: v_mov_b32_e32 [[VZ:v[0-9]+]], [[SZ]]
228 ; GCN: v_mul_lo_u32 [[VZ]], [[VZ]], 9
229 ; GCN: ds_write_b32 v0, [[VZ]]
230 define void @func_other_fi_user_non_inline_imm_offset_i32_vcc_live() #0 {
231 %alloca0 = alloca [128 x i32], align 4, addrspace(5)
232 %alloca1 = alloca [8 x i32], align 4, addrspace(5)
233 %vcc = call i64 asm sideeffect "; def $0", "={vcc}"()
234 %gep0 = getelementptr inbounds [128 x i32], ptr addrspace(5) %alloca0, i32 0, i32 65
235 store volatile i32 7, ptr addrspace(5) %gep0
236 call void asm sideeffect "; use $0", "{vcc}"(i64 %vcc)
237 %ptrtoint = ptrtoint ptr addrspace(5) %alloca1 to i32
238 %mul = mul i32 %ptrtoint, 9
239 store volatile i32 %mul, ptr addrspace(3) undef
243 declare void @func(ptr addrspace(5) nocapture) #0
245 ; undef flag not preserved in eliminateFrameIndex when handling the
246 ; stores in the middle block.
248 ; GCN-LABEL: {{^}}undefined_stack_store_reg:
249 ; GCN: s_and_saveexec_b64
250 ; MUBUF: buffer_store_dword v0, off, s[0:3], s33 offset:
251 ; MUBUF: buffer_store_dword v0, off, s[0:3], s33 offset:
252 ; MUBUF: buffer_store_dword v0, off, s[0:3], s33 offset:
253 ; MUBUF: buffer_store_dword v{{[0-9]+}}, off, s[0:3], s33 offset:
254 ; FLATSCR: scratch_store_dword v0, off, s33 offset:
255 ; FLATSCR: scratch_store_dword v0, off, s33 offset:
256 ; FLATSCR: scratch_store_dword v0, off, s33 offset:
257 ; FLATSCR: scratch_store_dword v{{[0-9]+}}, off, s33 offset:
258 define void @undefined_stack_store_reg(float %arg, i32 %arg1) #0 {
260 %tmp = alloca <4 x float>, align 16, addrspace(5)
261 %tmp2 = insertelement <4 x float> undef, float %arg, i32 0
262 store <4 x float> %tmp2, ptr addrspace(5) undef
263 %tmp3 = icmp eq i32 %arg1, 0
264 br i1 %tmp3, label %bb4, label %bb5
267 call void @func(ptr addrspace(5) nonnull undef)
268 store <4 x float> %tmp2, ptr addrspace(5) %tmp, align 16
269 call void @func(ptr addrspace(5) nonnull %tmp)
276 ; GCN-LABEL: {{^}}alloca_ptr_nonentry_block:
277 ; GCN: s_and_saveexec_b64
278 ; MUBUF: buffer_load_dword v{{[0-9]+}}, off, s[0:3], s32 offset:4
279 ; FLATSCR: scratch_load_dword v{{[0-9]+}}, off, s32 offset:4
281 ; CI: v_lshr_b32_e64 [[SHIFT:v[0-9]+]], s32, 6
282 ; CI-NEXT: v_or_b32_e32 [[PTR:v[0-9]+]], 4, [[SHIFT]]
284 ; GFX9-MUBUF: v_lshrrev_b32_e64 [[SHIFT:v[0-9]+]], 6, s32
285 ; GFX9-MUBUF-NEXT: v_or_b32_e32 [[PTR:v[0-9]+]], 4, [[SHIFT]]
287 ; GFX9-FLATSCR: v_mov_b32_e32 [[SP:v[0-9]+]], s32
288 ; GFX9-FLATSCR-NEXT: v_or_b32_e32 [[PTR:v[0-9]+]], 4, [[SP]]
290 ; GCN: ds_write_b32 v{{[0-9]+}}, [[PTR]]
291 define void @alloca_ptr_nonentry_block(i32 %arg0) #0 {
292 %alloca0 = alloca { i8, i32 }, align 8, addrspace(5)
293 %cmp = icmp eq i32 %arg0, 0
294 br i1 %cmp, label %bb, label %ret
297 %gep0 = getelementptr inbounds { i8, i32 }, ptr addrspace(5) %alloca0, i32 0, i32 0
298 %gep1 = getelementptr inbounds { i8, i32 }, ptr addrspace(5) %alloca0, i32 0, i32 1
299 %load1 = load volatile i32, ptr addrspace(5) %gep1
300 store volatile ptr addrspace(5) %gep1, ptr addrspace(3) undef
307 %struct0 = type { [4224 x %type.i16] }
308 %type.i16 = type { i16 }
309 @_ZZN0 = external hidden addrspace(3) global %struct0, align 8
311 ; GFX11-LABEL: tied_operand_test:
312 ; GFX11: ; %bb.0: ; %entry
313 ; GFX11-DAG: scratch_load_u16 [[LDRESULT:v[0-9]+]], off, off
314 ; GFX11-DAG: v_mov_b32_e32 [[C:v[0-9]+]], 0x7b
315 ; GFX11-DAG: ds_store_b16 v{{[0-9]+}}, [[LDRESULT]] offset:10
316 ; GFX11-DAG: ds_store_b16 v{{[0-9]+}}, [[C]] offset:8
317 ; GFX11-NEXT: s_endpgm
318 define protected amdgpu_kernel void @tied_operand_test(i1 %c1, i1 %c2, i32 %val) {
320 %scratch0 = alloca i16, align 4, addrspace(5)
321 %scratch1 = alloca i16, align 4, addrspace(5)
322 %first = select i1 %c1, ptr addrspace(5) %scratch0, ptr addrspace(5) %scratch1
323 %spec.select = select i1 %c2, ptr addrspace(5) %first, ptr addrspace(5) %scratch0
324 %dead.load = load i16, ptr addrspace(5) %spec.select, align 2
325 %scratch0.load = load i16, ptr addrspace(5) %scratch0, align 4
326 %add4 = add nuw nsw i32 %val, 4
327 %addr0 = getelementptr inbounds %struct0, ptr addrspace(3) @_ZZN0, i32 0, i32 0, i32 %add4, i32 0
328 store i16 123, ptr addrspace(3) %addr0, align 2
329 %add5 = add nuw nsw i32 %val, 5
330 %addr1 = getelementptr inbounds %struct0, ptr addrspace(3) @_ZZN0, i32 0, i32 0, i32 %add5, i32 0
331 store i16 %scratch0.load, ptr addrspace(3) %addr1, align 2
335 attributes #0 = { nounwind }