1 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=kaveri -mattr=-promote-alloca -amdgpu-sroa=0 -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 -amdgpu-sroa=0 -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 -amdgpu-sroa=0 -amdgpu-enable-flat-scratch -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,GFX9,GFX9-FLATSCR %s
5 ; Test that non-entry function frame indices are expanded properly to
6 ; give an index relative to the scratch wave offset register
8 ; Materialize into a mov. Make sure there isn't an unnecessary copy.
9 ; GCN-LABEL: {{^}}func_mov_fi_i32:
10 ; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
12 ; CI-NEXT: v_lshr_b32_e64 v0, s32, 6
13 ; GFX9-MUBUF-NEXT: v_lshrrev_b32_e64 v0, 6, s32
15 ; GFX9-FLATSCR: v_mov_b32_e32 v0, s32
16 ; GFX9-FLATSCR-NOT: v_lshrrev_b32_e64
20 ; GCN: ds_write_b32 v0, v0
21 define void @func_mov_fi_i32() #0 {
22 %alloca = alloca i32, addrspace(5)
23 store volatile i32 addrspace(5)* %alloca, i32 addrspace(5)* addrspace(3)* undef
27 ; Offset due to different objects
28 ; GCN-LABEL: {{^}}func_mov_fi_i32_offset:
29 ; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
31 ; CI-DAG: v_lshr_b32_e64 v0, s32, 6
33 ; CI: ds_write_b32 v0, v0
34 ; CI-NEXT: v_lshr_b32_e64 [[SCALED:v[0-9]+]], s32, 6
35 ; CI-NEXT: v_add_i32_e{{32|64}} v0, {{s\[[0-9]+:[0-9]+\]|vcc}}, 4, [[SCALED]]
36 ; CI-NEXT: ds_write_b32 v0, v0
38 ; GFX9-MUBUF-NEXT: v_lshrrev_b32_e64 v0, 6, s32
39 ; GFX9-FLATSCR: v_mov_b32_e32 v0, s32
40 ; GFX9-FLATSCR: s_add_i32 [[ADD:[^,]+]], s32, 4
41 ; GFX9-NEXT: ds_write_b32 v0, v0
42 ; GFX9-MUBUF-NEXT: v_lshrrev_b32_e64 [[SCALED:v[0-9]+]], 6, s32
43 ; GFX9-MUBUF-NEXT: v_add_u32_e32 v0, 4, [[SCALED]]
44 ; GFX9-FLATSCR-NEXT: v_mov_b32_e32 v0, [[ADD]]
45 ; GFX9-NEXT: ds_write_b32 v0, v0
46 define void @func_mov_fi_i32_offset() #0 {
47 %alloca0 = alloca i32, addrspace(5)
48 %alloca1 = alloca i32, addrspace(5)
49 store volatile i32 addrspace(5)* %alloca0, i32 addrspace(5)* addrspace(3)* undef
50 store volatile i32 addrspace(5)* %alloca1, i32 addrspace(5)* addrspace(3)* undef
54 ; Materialize into an add of a constant offset from the FI.
55 ; FIXME: Should be able to merge adds
57 ; GCN-LABEL: {{^}}func_add_constant_to_fi_i32:
58 ; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
60 ; CI: v_lshr_b32_e64 [[SCALED:v[0-9]+]], s32, 6
61 ; CI-NEXT: v_add_i32_e32 v0, vcc, 4, [[SCALED]]
63 ; GFX9-MUBUF: v_lshrrev_b32_e64 [[SCALED:v[0-9]+]], 6, s32
64 ; GFX9-MUBUF-NEXT: v_add_u32_e32 v0, 4, [[SCALED]]
66 ; GFX9-FLATSCR: v_mov_b32_e32 [[ADD:v[0-9]+]], s32
67 ; GFX9-FLATSCR-NEXT: v_add_u32_e32 v0, 4, [[ADD]]
70 ; GCN: ds_write_b32 v0, v0
71 define void @func_add_constant_to_fi_i32() #0 {
72 %alloca = alloca [2 x i32], align 4, addrspace(5)
73 %gep0 = getelementptr inbounds [2 x i32], [2 x i32] addrspace(5)* %alloca, i32 0, i32 1
74 store volatile i32 addrspace(5)* %gep0, i32 addrspace(5)* addrspace(3)* undef
78 ; A user the materialized frame index can't be meaningfully folded
80 ; FIXME: Should use s_mul but the frame index always gets materialized into a
83 ; GCN-LABEL: {{^}}func_other_fi_user_i32:
85 ; CI: v_lshr_b32_e64 v0, s32, 6
87 ; GFX9-MUBUF: v_lshrrev_b32_e64 v0, 6, s32
88 ; GFX9-FLATSCR: v_mov_b32_e32 v0, s32
90 ; GCN-NEXT: v_mul_lo_u32 v0, v0, 9
92 ; GCN: ds_write_b32 v0, v0
93 define void @func_other_fi_user_i32() #0 {
94 %alloca = alloca [2 x i32], align 4, addrspace(5)
95 %ptrtoint = ptrtoint [2 x i32] addrspace(5)* %alloca to i32
96 %mul = mul i32 %ptrtoint, 9
97 store volatile i32 %mul, i32 addrspace(3)* undef
101 ; GCN-LABEL: {{^}}func_store_private_arg_i32_ptr:
102 ; GCN: v_mov_b32_e32 v1, 15{{$}}
103 ; MUBUF: buffer_store_dword v1, v0, s[0:3], 0 offen{{$}}
104 ; GFX9-FLATSCR: scratch_store_dword v0, v1, off{{$}}
105 define void @func_store_private_arg_i32_ptr(i32 addrspace(5)* %ptr) #0 {
106 store volatile i32 15, i32 addrspace(5)* %ptr
110 ; GCN-LABEL: {{^}}func_load_private_arg_i32_ptr:
112 ; MUBUF-NEXT: buffer_load_dword v0, v0, s[0:3], 0 offen glc{{$}}
113 ; GFX9-FLATSCR-NEXT: scratch_load_dword v0, v0, off glc{{$}}
114 define void @func_load_private_arg_i32_ptr(i32 addrspace(5)* %ptr) #0 {
115 %val = load volatile i32, i32 addrspace(5)* %ptr
119 ; GCN-LABEL: {{^}}void_func_byval_struct_i8_i32_ptr:
122 ; CI: v_lshr_b32_e64 [[SHIFT:v[0-9]+]], s32, 6
123 ; CI-NEXT: v_or_b32_e32 v0, 4, [[SHIFT]]
125 ; GFX9-MUBUF: v_lshrrev_b32_e64 [[SHIFT:v[0-9]+]], 6, s32
126 ; GFX9-MUBUF-NEXT: v_or_b32_e32 v0, 4, [[SHIFT]]
128 ; GFX9-FLATSCR: v_mov_b32_e32 [[SP:v[0-9]+]], s32
129 ; GFX9-FLATSCR-NEXT: v_or_b32_e32 v0, 4, [[SP]]
132 ; GCN: ds_write_b32 v0, v0
133 define void @void_func_byval_struct_i8_i32_ptr({ i8, i32 } addrspace(5)* byval({ i8, i32 }) %arg0) #0 {
134 %gep0 = getelementptr inbounds { i8, i32 }, { i8, i32 } addrspace(5)* %arg0, i32 0, i32 0
135 %gep1 = getelementptr inbounds { i8, i32 }, { i8, i32 } addrspace(5)* %arg0, i32 0, i32 1
136 %load1 = load i32, i32 addrspace(5)* %gep1
137 store volatile i32 addrspace(5)* %gep1, i32 addrspace(5)* addrspace(3)* undef
141 ; GCN-LABEL: {{^}}void_func_byval_struct_i8_i32_ptr_value:
142 ; GCN: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
143 ; MUBUF-NEXT: buffer_load_ubyte v0, off, s[0:3], s32
144 ; MUBUF-NEXT: buffer_load_dword v1, off, s[0:3], s32 offset:4
145 ; GFX9-FLATSCR-NEXT: scratch_load_ubyte v0, off, s32
146 ; GFX9-FLATSCR-NEXT: scratch_load_dword v1, off, s32 offset:4
147 define void @void_func_byval_struct_i8_i32_ptr_value({ i8, i32 } addrspace(5)* byval({ i8, i32 }) %arg0) #0 {
148 %gep0 = getelementptr inbounds { i8, i32 }, { i8, i32 } addrspace(5)* %arg0, i32 0, i32 0
149 %gep1 = getelementptr inbounds { i8, i32 }, { i8, i32 } addrspace(5)* %arg0, i32 0, i32 1
150 %load0 = load i8, i8 addrspace(5)* %gep0
151 %load1 = load i32, i32 addrspace(5)* %gep1
152 store volatile i8 %load0, i8 addrspace(3)* undef
153 store volatile i32 %load1, i32 addrspace(3)* undef
157 ; GCN-LABEL: {{^}}void_func_byval_struct_i8_i32_ptr_nonentry_block:
159 ; CI: v_lshr_b32_e64 [[SHIFT:v[0-9]+]], s32, 6
161 ; GFX9-MUBUF: v_lshrrev_b32_e64 [[SP:v[0-9]+]], 6, s32
162 ; GFX9-FLATSCR: v_mov_b32_e32 [[SP:v[0-9]+]], s32
164 ; GCN: s_and_saveexec_b64
166 ; CI: v_add_i32_e32 [[GEP:v[0-9]+]], vcc, 4, [[SHIFT]]
167 ; CI: buffer_load_dword v{{[0-9]+}}, off, s[0:3], s32 offset:4 glc{{$}}
169 ; GFX9: v_add_u32_e32 [[GEP:v[0-9]+]], 4, [[SP]]
170 ; GFX9-MUBUF: buffer_load_dword v{{[0-9]+}}, off, s[0:3], s32 offset:4 glc{{$}}
171 ; GFX9-FLATSCR: scratch_load_dword v{{[0-9]+}}, off, s32 offset:4 glc{{$}}
173 ; GCN: ds_write_b32 v{{[0-9]+}}, [[GEP]]
174 define void @void_func_byval_struct_i8_i32_ptr_nonentry_block({ i8, i32 } addrspace(5)* byval({ i8, i32 }) %arg0, i32 %arg2) #0 {
175 %cmp = icmp eq i32 %arg2, 0
176 br i1 %cmp, label %bb, label %ret
179 %gep0 = getelementptr inbounds { i8, i32 }, { i8, i32 } addrspace(5)* %arg0, i32 0, i32 0
180 %gep1 = getelementptr inbounds { i8, i32 }, { i8, i32 } addrspace(5)* %arg0, i32 0, i32 1
181 %load1 = load volatile i32, i32 addrspace(5)* %gep1
182 store volatile i32 addrspace(5)* %gep1, i32 addrspace(5)* addrspace(3)* undef
189 ; Added offset can't be used with VOP3 add
190 ; GCN-LABEL: {{^}}func_other_fi_user_non_inline_imm_offset_i32:
192 ; CI-DAG: s_movk_i32 [[K:s[0-9]+|vcc_lo|vcc_hi]], 0x200
193 ; CI-DAG: v_lshr_b32_e64 [[SCALED:v[0-9]+]], s32, 6
194 ; CI: v_add_i32_e32 [[VZ:v[0-9]+]], vcc, [[K]], [[SCALED]]
196 ; GFX9-MUBUF-DAG: v_lshrrev_b32_e64 [[SCALED:v[0-9]+]], 6, s32
197 ; GFX9-MUBUF: v_add_u32_e32 [[VZ:v[0-9]+]], 0x200, [[SCALED]]
199 ; GFX9-FLATSCR-DAG: s_add_i32 [[SZ:[^,]+]], s32, 0x200
200 ; GFX9-FLATSCR: v_mov_b32_e32 [[VZ:v[0-9]+]], [[SZ]]
202 ; GCN: v_mul_lo_u32 [[VZ]], [[VZ]], 9
203 ; GCN: ds_write_b32 v0, [[VZ]]
204 define void @func_other_fi_user_non_inline_imm_offset_i32() #0 {
205 %alloca0 = alloca [128 x i32], align 4, addrspace(5)
206 %alloca1 = alloca [8 x i32], align 4, addrspace(5)
207 %gep0 = getelementptr inbounds [128 x i32], [128 x i32] addrspace(5)* %alloca0, i32 0, i32 65
208 %gep1 = getelementptr inbounds [8 x i32], [8 x i32] addrspace(5)* %alloca1, i32 0, i32 0
209 store volatile i32 7, i32 addrspace(5)* %gep0
210 %ptrtoint = ptrtoint i32 addrspace(5)* %gep1 to i32
211 %mul = mul i32 %ptrtoint, 9
212 store volatile i32 %mul, i32 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], [128 x i32] addrspace(5)* %alloca0, i32 0, i32 65
235 %gep1 = getelementptr inbounds [8 x i32], [8 x i32] addrspace(5)* %alloca1, i32 0, i32 0
236 store volatile i32 7, i32 addrspace(5)* %gep0
237 call void asm sideeffect "; use $0", "{vcc}"(i64 %vcc)
238 %ptrtoint = ptrtoint i32 addrspace(5)* %gep1 to i32
239 %mul = mul i32 %ptrtoint, 9
240 store volatile i32 %mul, i32 addrspace(3)* undef
244 declare void @func(<4 x float> addrspace(5)* nocapture) #0
246 ; undef flag not preserved in eliminateFrameIndex when handling the
247 ; stores in the middle block.
249 ; GCN-LABEL: {{^}}undefined_stack_store_reg:
250 ; GCN: s_and_saveexec_b64
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 v0, off, s[0:3], s33 offset:
254 ; MUBUF: buffer_store_dword v{{[0-9]+}}, off, s[0:3], 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 v0, off, s33 offset:
258 ; FLATSCR: scratch_store_dword v{{[0-9]+}}, off, s33 offset:
259 define void @undefined_stack_store_reg(float %arg, i32 %arg1) #0 {
261 %tmp = alloca <4 x float>, align 16, addrspace(5)
262 %tmp2 = insertelement <4 x float> undef, float %arg, i32 0
263 store <4 x float> %tmp2, <4 x float> addrspace(5)* undef
264 %tmp3 = icmp eq i32 %arg1, 0
265 br i1 %tmp3, label %bb4, label %bb5
268 call void @func(<4 x float> addrspace(5)* nonnull undef)
269 store <4 x float> %tmp2, <4 x float> addrspace(5)* %tmp, align 16
270 call void @func(<4 x float> addrspace(5)* nonnull %tmp)
277 ; GCN-LABEL: {{^}}alloca_ptr_nonentry_block:
278 ; GCN: s_and_saveexec_b64
279 ; MUBUF: buffer_load_dword v{{[0-9]+}}, off, s[0:3], s32 offset:4
280 ; FLATSCR: scratch_load_dword v{{[0-9]+}}, off, s32 offset:4
282 ; CI: v_lshr_b32_e64 [[SHIFT:v[0-9]+]], s32, 6
283 ; CI-NEXT: v_or_b32_e32 [[PTR:v[0-9]+]], 4, [[SHIFT]]
285 ; GFX9-MUBUF: v_lshrrev_b32_e64 [[SHIFT:v[0-9]+]], 6, s32
286 ; GFX9-MUBUF-NEXT: v_or_b32_e32 [[PTR:v[0-9]+]], 4, [[SHIFT]]
288 ; GFX9-FLATSCR: v_mov_b32_e32 [[SP:v[0-9]+]], s32
289 ; GFX9-FLATSCR-NEXT: v_or_b32_e32 [[PTR:v[0-9]+]], 4, [[SP]]
291 ; GCN: ds_write_b32 v{{[0-9]+}}, [[PTR]]
292 define void @alloca_ptr_nonentry_block(i32 %arg0) #0 {
293 %alloca0 = alloca { i8, i32 }, align 4, addrspace(5)
294 %cmp = icmp eq i32 %arg0, 0
295 br i1 %cmp, label %bb, label %ret
298 %gep0 = getelementptr inbounds { i8, i32 }, { i8, i32 } addrspace(5)* %alloca0, i32 0, i32 0
299 %gep1 = getelementptr inbounds { i8, i32 }, { i8, i32 } addrspace(5)* %alloca0, i32 0, i32 1
300 %load1 = load volatile i32, i32 addrspace(5)* %gep1
301 store volatile i32 addrspace(5)* %gep1, i32 addrspace(5)* addrspace(3)* undef
308 attributes #0 = { nounwind }