1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -global-isel -amdgpu-load-store-vectorizer=0 -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,DEFAULTSIZE %s
3 ; RUN: llc -global-isel -amdgpu-load-store-vectorizer=0 -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -verify-machineinstrs -amdgpu-assume-dynamic-stack-object-size=1024 < %s | FileCheck -check-prefixes=GCN,ASSUME1024 %s
5 ; FIXME: Generated test checks do not check metadata at the end of the
6 ; function, so this also includes manually added checks.
8 ; Test that we can select a statically sized alloca outside of the
11 ; FIXME: FunctionLoweringInfo unhelpfully doesn't preserve an
12 ; alignment less than the stack alignment.
13 define amdgpu_kernel void @kernel_non_entry_block_static_alloca_uniformly_reached_align4(ptr addrspace(1) %out, i32 %arg.cond0, i32 %arg.cond1, i32 %in) {
14 ; GCN-LABEL: kernel_non_entry_block_static_alloca_uniformly_reached_align4:
15 ; GCN: ; %bb.0: ; %entry
16 ; GCN-NEXT: s_load_dword s4, s[6:7], 0x8
17 ; GCN-NEXT: s_add_u32 s0, s0, s15
18 ; GCN-NEXT: s_addc_u32 s1, s1, 0
19 ; GCN-NEXT: s_mov_b32 s33, 0
20 ; GCN-NEXT: s_movk_i32 s32, 0x400
21 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
22 ; GCN-NEXT: s_cmp_lg_u32 s4, 0
23 ; GCN-NEXT: s_cbranch_scc1 .LBB0_3
24 ; GCN-NEXT: ; %bb.1: ; %bb.0
25 ; GCN-NEXT: s_load_dword s4, s[6:7], 0xc
26 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
27 ; GCN-NEXT: s_cmp_lg_u32 s4, 0
28 ; GCN-NEXT: s_cbranch_scc1 .LBB0_3
29 ; GCN-NEXT: ; %bb.2: ; %bb.1
30 ; GCN-NEXT: s_load_dword s5, s[6:7], 0x10
31 ; GCN-NEXT: s_add_u32 s4, s32, 0x1000
32 ; GCN-NEXT: v_mov_b32_e32 v1, 0
33 ; GCN-NEXT: v_mov_b32_e32 v2, s4
34 ; GCN-NEXT: v_mov_b32_e32 v3, 1
35 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
36 ; GCN-NEXT: s_lshl_b32 s5, s5, 2
37 ; GCN-NEXT: s_add_u32 s4, s4, s5
38 ; GCN-NEXT: buffer_store_dword v1, v2, s[0:3], 0 offen
39 ; GCN-NEXT: buffer_store_dword v3, v2, s[0:3], 0 offen offset:4
40 ; GCN-NEXT: v_mov_b32_e32 v2, s4
41 ; GCN-NEXT: buffer_load_dword v2, v2, s[0:3], 0 offen
42 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[6:7], 0x0
43 ; GCN-NEXT: s_waitcnt vmcnt(0)
44 ; GCN-NEXT: v_add_u32_e32 v0, v2, v0
45 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
46 ; GCN-NEXT: global_store_dword v1, v0, s[4:5]
47 ; GCN-NEXT: .LBB0_3: ; %bb.2
48 ; GCN-NEXT: v_mov_b32_e32 v0, 0
49 ; GCN-NEXT: global_store_dword v[0:1], v0, off
50 ; GCN-NEXT: s_waitcnt vmcnt(0)
54 %cond0 = icmp eq i32 %arg.cond0, 0
55 br i1 %cond0, label %bb.0, label %bb.2
58 %alloca = alloca [16 x i32], align 4, addrspace(5)
59 %gep1 = getelementptr [16 x i32], ptr addrspace(5) %alloca, i32 0, i32 1
60 %cond1 = icmp eq i32 %arg.cond1, 0
61 br i1 %cond1, label %bb.1, label %bb.2
64 ; Use the alloca outside of the defining block.
65 store i32 0, ptr addrspace(5) %alloca
66 store i32 1, ptr addrspace(5) %gep1
67 %gep2 = getelementptr [16 x i32], ptr addrspace(5) %alloca, i32 0, i32 %in
68 %load = load i32, ptr addrspace(5) %gep2
69 %tid = call i32 @llvm.amdgcn.workitem.id.x()
70 %add = add i32 %load, %tid
71 store i32 %add, ptr addrspace(1) %out
75 store volatile i32 0, ptr addrspace(1) undef
78 ; DEFAULTSIZE: .amdhsa_private_segment_fixed_size 16
79 ; DEFAULTSIZE: ; ScratchSize: 16
81 ; ASSUME1024: .amdhsa_private_segment_fixed_size 1040
82 ; ASSUME1024: ; ScratchSize: 1040
84 define amdgpu_kernel void @kernel_non_entry_block_static_alloca_uniformly_reached_align64(ptr addrspace(1) %out, i32 %arg.cond, i32 %in) {
85 ; GCN-LABEL: kernel_non_entry_block_static_alloca_uniformly_reached_align64:
86 ; GCN: ; %bb.0: ; %entry
87 ; GCN-NEXT: s_load_dword s4, s[6:7], 0x8
88 ; GCN-NEXT: s_add_u32 s0, s0, s15
89 ; GCN-NEXT: s_addc_u32 s1, s1, 0
90 ; GCN-NEXT: s_mov_b32 s33, 0
91 ; GCN-NEXT: s_movk_i32 s32, 0x1000
92 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
93 ; GCN-NEXT: s_cmp_lg_u32 s4, 0
94 ; GCN-NEXT: s_cbranch_scc1 .LBB1_2
95 ; GCN-NEXT: ; %bb.1: ; %bb.0
96 ; GCN-NEXT: s_load_dword s4, s[6:7], 0xc
97 ; GCN-NEXT: s_add_u32 s5, s32, 0x1000
98 ; GCN-NEXT: s_and_b32 s5, s5, 0xfffff000
99 ; GCN-NEXT: v_mov_b32_e32 v1, 0
100 ; GCN-NEXT: v_mov_b32_e32 v2, s5
101 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
102 ; GCN-NEXT: s_lshl_b32 s4, s4, 2
103 ; GCN-NEXT: v_mov_b32_e32 v3, 1
104 ; GCN-NEXT: s_add_u32 s4, s5, s4
105 ; GCN-NEXT: buffer_store_dword v1, v2, s[0:3], 0 offen
106 ; GCN-NEXT: buffer_store_dword v3, v2, s[0:3], 0 offen offset:4
107 ; GCN-NEXT: v_mov_b32_e32 v2, s4
108 ; GCN-NEXT: buffer_load_dword v2, v2, s[0:3], 0 offen
109 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[6:7], 0x0
110 ; GCN-NEXT: s_waitcnt vmcnt(0)
111 ; GCN-NEXT: v_add_u32_e32 v0, v2, v0
112 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
113 ; GCN-NEXT: global_store_dword v1, v0, s[4:5]
114 ; GCN-NEXT: .LBB1_2: ; %bb.1
115 ; GCN-NEXT: v_mov_b32_e32 v0, 0
116 ; GCN-NEXT: global_store_dword v[0:1], v0, off
117 ; GCN-NEXT: s_waitcnt vmcnt(0)
120 %cond = icmp eq i32 %arg.cond, 0
121 br i1 %cond, label %bb.0, label %bb.1
124 %alloca = alloca [16 x i32], align 64, addrspace(5)
125 %gep1 = getelementptr [16 x i32], ptr addrspace(5) %alloca, i32 0, i32 1
126 store i32 0, ptr addrspace(5) %alloca
127 store i32 1, ptr addrspace(5) %gep1
128 %gep2 = getelementptr [16 x i32], ptr addrspace(5) %alloca, i32 0, i32 %in
129 %load = load i32, ptr addrspace(5) %gep2
130 %tid = call i32 @llvm.amdgcn.workitem.id.x()
131 %add = add i32 %load, %tid
132 store i32 %add, ptr addrspace(1) %out
136 store volatile i32 0, ptr addrspace(1) undef
140 ; DEFAULTSIZE: .amdhsa_private_segment_fixed_size 64
141 ; DEFAULTSIZE: ; ScratchSize: 64
143 ; ASSUME1024: .amdhsa_private_segment_fixed_size 1088
144 ; ASSUME1024: ; ScratchSize: 1088
147 define void @func_non_entry_block_static_alloca_align4(ptr addrspace(1) %out, i32 %arg.cond0, i32 %arg.cond1, i32 %in) {
148 ; GCN-LABEL: func_non_entry_block_static_alloca_align4:
149 ; GCN: ; %bb.0: ; %entry
150 ; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
151 ; GCN-NEXT: s_mov_b32 s7, s33
152 ; GCN-NEXT: v_cmp_eq_u32_e32 vcc, 0, v2
153 ; GCN-NEXT: s_mov_b32 s33, s32
154 ; GCN-NEXT: s_addk_i32 s32, 0x400
155 ; GCN-NEXT: s_and_saveexec_b64 s[4:5], vcc
156 ; GCN-NEXT: s_cbranch_execz .LBB2_3
157 ; GCN-NEXT: ; %bb.1: ; %bb.0
158 ; GCN-NEXT: v_cmp_eq_u32_e32 vcc, 0, v3
159 ; GCN-NEXT: s_and_b64 exec, exec, vcc
160 ; GCN-NEXT: s_cbranch_execz .LBB2_3
161 ; GCN-NEXT: ; %bb.2: ; %bb.1
162 ; GCN-NEXT: s_add_u32 s6, s32, 0x1000
163 ; GCN-NEXT: v_mov_b32_e32 v2, 0
164 ; GCN-NEXT: v_mov_b32_e32 v3, s6
165 ; GCN-NEXT: buffer_store_dword v2, v3, s[0:3], 0 offen
166 ; GCN-NEXT: v_mov_b32_e32 v2, 1
167 ; GCN-NEXT: buffer_store_dword v2, v3, s[0:3], 0 offen offset:4
168 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v4
169 ; GCN-NEXT: v_add_u32_e32 v2, s6, v2
170 ; GCN-NEXT: buffer_load_dword v2, v2, s[0:3], 0 offen
171 ; GCN-NEXT: v_and_b32_e32 v3, 0x3ff, v31
172 ; GCN-NEXT: s_waitcnt vmcnt(0)
173 ; GCN-NEXT: v_add_u32_e32 v2, v2, v3
174 ; GCN-NEXT: global_store_dword v[0:1], v2, off
175 ; GCN-NEXT: .LBB2_3: ; %bb.2
176 ; GCN-NEXT: s_or_b64 exec, exec, s[4:5]
177 ; GCN-NEXT: v_mov_b32_e32 v0, 0
178 ; GCN-NEXT: global_store_dword v[0:1], v0, off
179 ; GCN-NEXT: s_waitcnt vmcnt(0)
180 ; GCN-NEXT: s_addk_i32 s32, 0xfc00
181 ; GCN-NEXT: s_mov_b32 s33, s7
182 ; GCN-NEXT: s_setpc_b64 s[30:31]
185 %cond0 = icmp eq i32 %arg.cond0, 0
186 br i1 %cond0, label %bb.0, label %bb.2
189 %alloca = alloca [16 x i32], align 4, addrspace(5)
190 %gep1 = getelementptr [16 x i32], ptr addrspace(5) %alloca, i32 0, i32 1
191 %cond1 = icmp eq i32 %arg.cond1, 0
192 br i1 %cond1, label %bb.1, label %bb.2
195 ; Use the alloca outside of the defining block.
196 store i32 0, ptr addrspace(5) %alloca
197 store i32 1, ptr addrspace(5) %gep1
198 %gep2 = getelementptr [16 x i32], ptr addrspace(5) %alloca, i32 0, i32 %in
199 %load = load i32, ptr addrspace(5) %gep2
200 %tid = call i32 @llvm.amdgcn.workitem.id.x()
201 %add = add i32 %load, %tid
202 store i32 %add, ptr addrspace(1) %out
206 store volatile i32 0, ptr addrspace(1) undef
210 define void @func_non_entry_block_static_alloca_align64(ptr addrspace(1) %out, i32 %arg.cond, i32 %in) {
211 ; GCN-LABEL: func_non_entry_block_static_alloca_align64:
212 ; GCN: ; %bb.0: ; %entry
213 ; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
214 ; GCN-NEXT: s_mov_b32 s7, s33
215 ; GCN-NEXT: s_add_i32 s33, s32, 0xfc0
216 ; GCN-NEXT: v_cmp_eq_u32_e32 vcc, 0, v2
217 ; GCN-NEXT: s_and_b32 s33, s33, 0xfffff000
218 ; GCN-NEXT: s_addk_i32 s32, 0x2000
219 ; GCN-NEXT: s_and_saveexec_b64 s[4:5], vcc
220 ; GCN-NEXT: s_cbranch_execz .LBB3_2
221 ; GCN-NEXT: ; %bb.1: ; %bb.0
222 ; GCN-NEXT: s_add_u32 s6, s32, 0x1000
223 ; GCN-NEXT: s_and_b32 s6, s6, 0xfffff000
224 ; GCN-NEXT: v_mov_b32_e32 v2, 0
225 ; GCN-NEXT: v_mov_b32_e32 v4, s6
226 ; GCN-NEXT: buffer_store_dword v2, v4, s[0:3], 0 offen
227 ; GCN-NEXT: v_mov_b32_e32 v2, 1
228 ; GCN-NEXT: buffer_store_dword v2, v4, s[0:3], 0 offen offset:4
229 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v3
230 ; GCN-NEXT: v_add_u32_e32 v2, s6, v2
231 ; GCN-NEXT: buffer_load_dword v2, v2, s[0:3], 0 offen
232 ; GCN-NEXT: v_and_b32_e32 v3, 0x3ff, v31
233 ; GCN-NEXT: s_waitcnt vmcnt(0)
234 ; GCN-NEXT: v_add_u32_e32 v2, v2, v3
235 ; GCN-NEXT: global_store_dword v[0:1], v2, off
236 ; GCN-NEXT: .LBB3_2: ; %bb.1
237 ; GCN-NEXT: s_or_b64 exec, exec, s[4:5]
238 ; GCN-NEXT: v_mov_b32_e32 v0, 0
239 ; GCN-NEXT: global_store_dword v[0:1], v0, off
240 ; GCN-NEXT: s_waitcnt vmcnt(0)
241 ; GCN-NEXT: s_addk_i32 s32, 0xe000
242 ; GCN-NEXT: s_mov_b32 s33, s7
243 ; GCN-NEXT: s_setpc_b64 s[30:31]
245 %cond = icmp eq i32 %arg.cond, 0
246 br i1 %cond, label %bb.0, label %bb.1
249 %alloca = alloca [16 x i32], align 64, addrspace(5)
250 %gep1 = getelementptr [16 x i32], ptr addrspace(5) %alloca, i32 0, i32 1
251 store i32 0, ptr addrspace(5) %alloca
252 store i32 1, ptr addrspace(5) %gep1
253 %gep2 = getelementptr [16 x i32], ptr addrspace(5) %alloca, i32 0, i32 %in
254 %load = load i32, ptr addrspace(5) %gep2
255 %tid = call i32 @llvm.amdgcn.workitem.id.x()
256 %add = add i32 %load, %tid
257 store i32 %add, ptr addrspace(1) %out
261 store volatile i32 0, ptr addrspace(1) undef
265 declare i32 @llvm.amdgcn.workitem.id.x() #0
267 attributes #0 = { nounwind readnone speculatable }
269 !llvm.module.flags = !{!0}
270 !0 = !{i32 1, !"amdhsa_code_object_version", i32 500}
271 ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
273 ; DEFAULTSIZE: {{.*}}