1 ; RUN: llc -amdgpu-scalarize-global-loads=false -mtriple=amdgcn -mcpu=bonaire -enable-amdgpu-aa=0 -verify-machineinstrs -enable-misched -enable-aa-sched-mi < %s | FileCheck -enable-var-scope -check-prefixes=GCN,CI %s
2 ; RUN: llc -amdgpu-scalarize-global-loads=false -mtriple=amdgcn -mcpu=gfx900 -enable-amdgpu-aa=0 -verify-machineinstrs -enable-misched -enable-aa-sched-mi < %s | FileCheck -enable-var-scope -check-prefixes=GCN,GFX9 %s
4 %struct.lds = type { [64 x ptr], [16 x i8] }
5 @stored_lds_struct = addrspace(3) global %struct.lds undef, align 16
6 @stored_lds_ptr = addrspace(3) global ptr addrspace(3) undef, align 4
7 @stored_constant_ptr = addrspace(3) global ptr addrspace(4) undef, align 8
8 @stored_global_ptr = addrspace(3) global ptr addrspace(1) undef, align 8
10 ; GCN-LABEL: {{^}}no_reorder_flat_load_local_store_local_load:
11 ; GCN: flat_load_dwordx4
12 ; GCN: ds_write_b128 {{v[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}} offset:512
13 ; GCN: ds_read2_b32 {{v\[[0-9]+:[0-9]+\]}}, {{v[0-9]+}} offset0:129 offset1:130
14 define amdgpu_kernel void @no_reorder_flat_load_local_store_local_load(ptr addrspace(3) %out, ptr %fptr) #0 {
15 %ptr1 = getelementptr %struct.lds, ptr addrspace(3) @stored_lds_struct, i32 0, i32 1
16 %ptr2 = getelementptr %struct.lds, ptr addrspace(3) @stored_lds_struct, i32 0, i32 1, i32 4
17 call void @llvm.memcpy.p3.p0(ptr addrspace(3) align 16 %ptr1, ptr align 8 %fptr, i64 16, i1 false)
18 %vector_load = load <2 x i32>, ptr addrspace(3) %ptr2, align 4
19 store <2 x i32> %vector_load, ptr addrspace(3) %out, align 4
23 ; GCN-LABEL: {{^}}reorder_local_load_global_store_local_load:
24 ; CI: ds_read2_b32 {{v\[[0-9]+:[0-9]+\]}}, {{v[0-9]+}} offset0:1 offset1:3
25 ; CI: buffer_store_dword
27 ; GFX9: ds_read2_b32 {{v\[[0-9]+:[0-9]+\]}}, {{v[0-9]+}} offset0:1 offset1:3
28 ; GFX9: global_store_dword
29 ; GFX9: global_store_dword
30 define amdgpu_kernel void @reorder_local_load_global_store_local_load(ptr addrspace(1) %out, ptr addrspace(1) %gptr) #0 {
31 %ptr0 = load ptr addrspace(3), ptr addrspace(3) @stored_lds_ptr, align 4
33 %ptr1 = getelementptr inbounds i32, ptr addrspace(3) %ptr0, i32 1
34 %ptr2 = getelementptr inbounds i32, ptr addrspace(3) %ptr0, i32 3
36 %tmp1 = load i32, ptr addrspace(3) %ptr1, align 4
37 store i32 99, ptr addrspace(1) %gptr, align 4
38 %tmp2 = load i32, ptr addrspace(3) %ptr2, align 4
40 %add = add nsw i32 %tmp1, %tmp2
42 store i32 %add, ptr addrspace(1) %out, align 4
46 ; GCN-LABEL: {{^}}no_reorder_local_load_volatile_global_store_local_load:
47 ; CI: ds_read_b32 {{v[0-9]+}}, {{v[0-9]+}} offset:4
48 ; CI: buffer_store_dword
49 ; CI: ds_read_b32 {{v[0-9]+}}, {{v[0-9]+}} offset:12
51 ; GFX9: ds_read_b32 {{v[0-9]+}}, {{v[0-9]+}} offset:4
52 ; GFX9: global_store_dword
53 ; GFX9: ds_read_b32 {{v[0-9]+}}, {{v[0-9]+}} offset:12
54 define amdgpu_kernel void @no_reorder_local_load_volatile_global_store_local_load(ptr addrspace(1) %out, ptr addrspace(1) %gptr) #0 {
55 %ptr0 = load ptr addrspace(3), ptr addrspace(3) @stored_lds_ptr, align 4
57 %ptr1 = getelementptr inbounds i32, ptr addrspace(3) %ptr0, i32 1
58 %ptr2 = getelementptr inbounds i32, ptr addrspace(3) %ptr0, i32 3
60 %tmp1 = load i32, ptr addrspace(3) %ptr1, align 4
61 store volatile i32 99, ptr addrspace(1) %gptr, align 4
62 %tmp2 = load i32, ptr addrspace(3) %ptr2, align 4
64 %add = add nsw i32 %tmp1, %tmp2
66 store i32 %add, ptr addrspace(1) %out, align 4
70 ; GCN-LABEL: {{^}}no_reorder_barrier_local_load_global_store_local_load:
71 ; CI: ds_read_b32 {{v[0-9]+}}, {{v[0-9]+}} offset:4
72 ; CI: ds_read_b32 {{v[0-9]+}}, {{v[0-9]+}} offset:12
73 ; CI: buffer_store_dword
75 ; GFX9-DAG: global_store_dword
76 ; GFX9-DAG: ds_read_b32 {{v[0-9]+}}, {{v[0-9]+}} offset:4
78 ; GFX9-DAG: ds_read_b32 {{v[0-9]+}}, {{v[0-9]+}} offset:12
79 ; GFX9-DAG: global_store_dword
80 define amdgpu_kernel void @no_reorder_barrier_local_load_global_store_local_load(ptr addrspace(1) %out, ptr addrspace(1) %gptr) #0 {
81 %ptr0 = load ptr addrspace(3), ptr addrspace(3) @stored_lds_ptr, align 4
83 %ptr1 = getelementptr inbounds i32, ptr addrspace(3) %ptr0, i32 1
84 %ptr2 = getelementptr inbounds i32, ptr addrspace(3) %ptr0, i32 3
86 %tmp1 = load i32, ptr addrspace(3) %ptr1, align 4
87 store i32 99, ptr addrspace(1) %gptr, align 4
88 call void @llvm.amdgcn.s.barrier() #1
89 %tmp2 = load i32, ptr addrspace(3) %ptr2, align 4
91 %add = add nsw i32 %tmp1, %tmp2
93 store i32 %add, ptr addrspace(1) %out, align 4
97 ; GCN-LABEL: {{^}}reorder_constant_load_global_store_constant_load:
98 ; GCN-DAG: v_readfirstlane_b32 s[[PTR_LO:[0-9]+]], v{{[0-9]+}}
99 ; GCN: v_readfirstlane_b32 s[[PTR_HI:[0-9]+]], v{{[0-9]+}}
101 ; CI: s_load_dword s{{[0-9]+}}, s[[[PTR_LO]]:[[PTR_HI]]], 0x1
102 ; CI: buffer_store_dword
103 ; CI: s_load_dword s{{[0-9]+}}, s[[[PTR_LO]]:[[PTR_HI]]], 0x3
105 ; GFX9: s_load_dword s{{[0-9]+}}, s[[[PTR_LO]]:[[PTR_HI]]], 0x4
106 ; GFX9: global_store_dword
107 ; GFX9: s_load_dword s{{[0-9]+}}, s[[[PTR_LO]]:[[PTR_HI]]], 0xc
109 ; CI: buffer_store_dword
110 ; GFX9: global_store_dword
111 define amdgpu_kernel void @reorder_constant_load_global_store_constant_load(ptr addrspace(1) %out, ptr addrspace(1) %gptr) #0 {
112 %ptr0 = load ptr addrspace(4), ptr addrspace(3) @stored_constant_ptr, align 8
114 %ptr1 = getelementptr inbounds i32, ptr addrspace(4) %ptr0, i64 1
115 %ptr2 = getelementptr inbounds i32, ptr addrspace(4) %ptr0, i64 3
117 %tmp1 = load i32, ptr addrspace(4) %ptr1, align 4
118 store i32 99, ptr addrspace(1) %gptr, align 4
119 %tmp2 = load i32, ptr addrspace(4) %ptr2, align 4
121 %add = add nsw i32 %tmp1, %tmp2
123 store i32 %add, ptr addrspace(1) %out, align 4
127 ; GCN-LABEL: {{^}}reorder_constant_load_local_store_constant_load:
128 ; GCN: v_readfirstlane_b32 s[[PTR_LO:[0-9]+]], v{{[0-9]+}}
129 ; GCN: v_readfirstlane_b32 s[[PTR_HI:[0-9]+]], v{{[0-9]+}}
131 ; CI-DAG: s_load_dword s{{[0-9]+}}, s[[[PTR_LO]]:[[PTR_HI]]], 0x1
132 ; CI-DAG: s_load_dword s{{[0-9]+}}, s[[[PTR_LO]]:[[PTR_HI]]], 0x3
134 ; GFX9-DAG: s_load_dword s{{[0-9]+}}, s[[[PTR_LO]]:[[PTR_HI]]], 0x4
135 ; GFX9-DAG: s_load_dword s{{[0-9]+}}, s[[[PTR_LO]]:[[PTR_HI]]], 0xc
137 ; GCN-DAG: ds_write_b32
138 ; CI: buffer_store_dword
139 ; GFX9: global_store_dword
140 define amdgpu_kernel void @reorder_constant_load_local_store_constant_load(ptr addrspace(1) %out, ptr addrspace(3) %lptr) #0 {
141 %ptr0 = load ptr addrspace(4), ptr addrspace(3) @stored_constant_ptr, align 8
143 %ptr1 = getelementptr inbounds i32, ptr addrspace(4) %ptr0, i64 1
144 %ptr2 = getelementptr inbounds i32, ptr addrspace(4) %ptr0, i64 3
146 %tmp1 = load i32, ptr addrspace(4) %ptr1, align 4
147 store i32 99, ptr addrspace(3) %lptr, align 4
148 %tmp2 = load i32, ptr addrspace(4) %ptr2, align 4
150 %add = add nsw i32 %tmp1, %tmp2
152 store i32 %add, ptr addrspace(1) %out, align 4
156 ; GCN-LABEL: {{^}}reorder_smrd_load_local_store_smrd_load:
161 ; CI: buffer_store_dword
162 ; GFX9: global_store_dword
163 define amdgpu_kernel void @reorder_smrd_load_local_store_smrd_load(ptr addrspace(1) %out, ptr addrspace(3) noalias %lptr, ptr addrspace(4) %ptr0) #0 {
164 %ptr1 = getelementptr inbounds i32, ptr addrspace(4) %ptr0, i64 1
165 %ptr2 = getelementptr inbounds i32, ptr addrspace(4) %ptr0, i64 2
167 %tmp1 = load i32, ptr addrspace(4) %ptr1, align 4
168 store i32 99, ptr addrspace(3) %lptr, align 4
169 %tmp2 = load i32, ptr addrspace(4) %ptr2, align 4
171 %add = add nsw i32 %tmp1, %tmp2
173 store i32 %add, ptr addrspace(1) %out, align 4
177 ; GCN-LABEL: {{^}}reorder_global_load_local_store_global_load:
178 ; CI: buffer_load_dword
179 ; CI: buffer_load_dword
181 ; CI: buffer_store_dword
183 ; GFX9: global_load_dword v{{[0-9]+}}, v{{[0-9]+}}, s{{\[[0-9]+:[0-9]+\]}} offset:4
184 ; GFX9: global_load_dword v{{[0-9]+}}, v{{[0-9]+}}, s{{\[[0-9]+:[0-9]+\]}} offset:12
186 define amdgpu_kernel void @reorder_global_load_local_store_global_load(ptr addrspace(1) %out, ptr addrspace(3) %lptr, ptr addrspace(1) %ptr0) #0 {
187 %ptr1 = getelementptr inbounds i32, ptr addrspace(1) %ptr0, i64 1
188 %ptr2 = getelementptr inbounds i32, ptr addrspace(1) %ptr0, i64 3
190 %tmp1 = load i32, ptr addrspace(1) %ptr1, align 4
191 store i32 99, ptr addrspace(3) %lptr, align 4
192 %tmp2 = load i32, ptr addrspace(1) %ptr2, align 4
194 %add = add nsw i32 %tmp1, %tmp2
196 store i32 %add, ptr addrspace(1) %out, align 4
200 ; GCN-LABEL: {{^}}reorder_local_offsets:
201 ; GCN: ds_read2_b32 {{v\[[0-9]+:[0-9]+\]}}, {{v[0-9]+}} offset0:100 offset1:102
202 ; GCN-DAG: ds_write2_b32 {{v[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}} offset0:3 offset1:100
203 ; GCN-DAG: ds_write_b32 {{v[0-9]+}}, {{v[0-9]+}} offset:408
204 ; CI: buffer_store_dword
205 ; GFX9: global_store_dword
207 define amdgpu_kernel void @reorder_local_offsets(ptr addrspace(1) nocapture %out, ptr addrspace(1) noalias nocapture readnone %gptr, ptr addrspace(3) noalias nocapture %ptr0) #0 {
208 %ptr1 = getelementptr inbounds i32, ptr addrspace(3) %ptr0, i32 3
209 %ptr2 = getelementptr inbounds i32, ptr addrspace(3) %ptr0, i32 100
210 %ptr3 = getelementptr inbounds i32, ptr addrspace(3) %ptr0, i32 102
212 store i32 123, ptr addrspace(3) %ptr1, align 4
213 %tmp1 = load i32, ptr addrspace(3) %ptr2, align 4
214 %tmp2 = load i32, ptr addrspace(3) %ptr3, align 4
215 store i32 123, ptr addrspace(3) %ptr2, align 4
216 %tmp3 = load i32, ptr addrspace(3) %ptr1, align 4
217 store i32 789, ptr addrspace(3) %ptr3, align 4
219 %add.0 = add nsw i32 %tmp2, %tmp1
220 %add.1 = add nsw i32 %add.0, %tmp3
221 store i32 %add.1, ptr addrspace(1) %out, align 4
225 ; GCN-LABEL: {{^}}reorder_global_offsets:
226 ; CI-DAG: buffer_load_dword {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, 0 offset:400
227 ; CI-DAG: buffer_load_dword {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, 0 offset:408
228 ; CI-DAG: buffer_store_dword {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, 0 offset:12
229 ; CI-DAG: buffer_store_dword {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, 0 offset:400
230 ; CI-DAG: buffer_store_dword {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, 0 offset:408
231 ; CI: buffer_store_dword
234 ; GFX9-DAG: global_load_dword {{v[0-9]+}}, v{{[0-9]+}}, s{{\[[0-9]+:[0-9]+\]}} offset:400
235 ; GFX9-DAG: global_load_dword {{v[0-9]+}}, v{{[0-9]+}}, s{{\[[0-9]+:[0-9]+\]}} offset:408
236 ; GFX9-DAG: global_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s{{\[[0-9]+:[0-9]+\]}} offset:12
237 ; GFX9-DAG: global_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s{{\[[0-9]+:[0-9]+\]}} offset:400
238 ; GFX9-DAG: global_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s{{\[[0-9]+:[0-9]+\]}} offset:408
239 ; GFX9: global_store_dword
241 define amdgpu_kernel void @reorder_global_offsets(ptr addrspace(1) nocapture %out, ptr addrspace(1) noalias nocapture readnone %gptr, ptr addrspace(1) noalias nocapture %ptr0) #0 {
242 %ptr1 = getelementptr inbounds i32, ptr addrspace(1) %ptr0, i32 3
243 %ptr2 = getelementptr inbounds i32, ptr addrspace(1) %ptr0, i32 100
244 %ptr3 = getelementptr inbounds i32, ptr addrspace(1) %ptr0, i32 102
246 store i32 123, ptr addrspace(1) %ptr1, align 4
247 %tmp1 = load i32, ptr addrspace(1) %ptr2, align 4
248 %tmp2 = load i32, ptr addrspace(1) %ptr3, align 4
249 store i32 123, ptr addrspace(1) %ptr2, align 4
250 %tmp3 = load i32, ptr addrspace(1) %ptr1, align 4
251 store i32 789, ptr addrspace(1) %ptr3, align 4
253 %add.0 = add nsw i32 %tmp2, %tmp1
254 %add.1 = add nsw i32 %add.0, %tmp3
255 store i32 %add.1, ptr addrspace(1) %out, align 4
259 ; GCN-LABEL: {{^}}reorder_global_offsets_addr64_soffset0:
260 ; CI: buffer_load_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:12{{$}}
261 ; CI-NEXT: buffer_load_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:28{{$}}
262 ; CI-NEXT: buffer_load_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:44{{$}}
270 ; CI-DAG: buffer_store_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}}
271 ; CI-DAG: buffer_store_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:20{{$}}
272 ; CI-DAG: buffer_store_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:36{{$}}
273 ; CI: buffer_store_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:52{{$}}
275 ; GFX9: global_load_dword {{v[0-9]+}}, v{{[0-9]+}}, s{{\[[0-9]+:[0-9]+\]}} offset:12
276 ; GFX9: global_load_dword {{v[0-9]+}}, v{{[0-9]+}}, s{{\[[0-9]+:[0-9]+\]}} offset:28
277 ; GFX9: global_load_dword {{v[0-9]+}}, v{{[0-9]+}}, s{{\[[0-9]+:[0-9]+\]}} offset:44
279 ; GFX9: global_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s{{\[[0-9]+:[0-9]+\]$}}
280 ; GFX9: global_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s{{\[[0-9]+:[0-9]+\]}} offset:20
281 ; GFX9: global_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s{{\[[0-9]+:[0-9]+\]}} offset:36
282 ; GFX9: global_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s{{\[[0-9]+:[0-9]+\]}} offset:52
284 define amdgpu_kernel void @reorder_global_offsets_addr64_soffset0(ptr addrspace(1) noalias nocapture %ptr.base) #0 {
285 %id = call i32 @llvm.amdgcn.workitem.id.x()
286 %id.ext = sext i32 %id to i64
288 %ptr0 = getelementptr inbounds i32, ptr addrspace(1) %ptr.base, i64 %id.ext
289 %ptr1 = getelementptr inbounds i32, ptr addrspace(1) %ptr0, i32 3
290 %ptr2 = getelementptr inbounds i32, ptr addrspace(1) %ptr0, i32 5
291 %ptr3 = getelementptr inbounds i32, ptr addrspace(1) %ptr0, i32 7
292 %ptr4 = getelementptr inbounds i32, ptr addrspace(1) %ptr0, i32 9
293 %ptr5 = getelementptr inbounds i32, ptr addrspace(1) %ptr0, i32 11
294 %ptr6 = getelementptr inbounds i32, ptr addrspace(1) %ptr0, i32 13
296 store i32 789, ptr addrspace(1) %ptr0, align 4
297 %tmp1 = load i32, ptr addrspace(1) %ptr1, align 4
298 store i32 123, ptr addrspace(1) %ptr2, align 4
299 %tmp2 = load i32, ptr addrspace(1) %ptr3, align 4
300 %add.0 = add nsw i32 %tmp1, %tmp2
301 store i32 %add.0, ptr addrspace(1) %ptr4, align 4
302 %tmp3 = load i32, ptr addrspace(1) %ptr5, align 4
303 %add.1 = add nsw i32 %add.0, %tmp3
304 store i32 %add.1, ptr addrspace(1) %ptr6, align 4
308 ; GCN-LABEL: {{^}}reorder_local_load_tbuffer_store_local_load:
309 ; GCN: ds_read2_b32 {{v\[[0-9]+:[0-9]+\]}}, {{v[0-9]+}} offset0:1 offset1:2
310 ; GCN: tbuffer_store_format
311 define amdgpu_vs void @reorder_local_load_tbuffer_store_local_load(ptr addrspace(1) %out, i32 %a1, i32 %vaddr) #0 {
312 %ptr0 = load ptr addrspace(3), ptr addrspace(3) @stored_lds_ptr, align 4
314 %ptr1 = getelementptr inbounds i32, ptr addrspace(3) %ptr0, i32 1
315 %ptr2 = getelementptr inbounds i32, ptr addrspace(3) %ptr0, i32 2
317 %tmp1 = load i32, ptr addrspace(3) %ptr1, align 4
319 %vdata = insertelement <4 x i32> undef, i32 %a1, i32 0
320 %vaddr.add = add i32 %vaddr, 32
321 call void @llvm.amdgcn.struct.ptr.tbuffer.store.v4i32(<4 x i32> %vdata, ptr addrspace(8) undef, i32 %vaddr.add, i32 0, i32 0, i32 228, i32 3)
323 %tmp2 = load i32, ptr addrspace(3) %ptr2, align 4
325 %add = add nsw i32 %tmp1, %tmp2
326 store i32 %add, ptr addrspace(1) %out, align 4
330 declare void @llvm.memcpy.p3.p0(ptr addrspace(3), ptr, i64, i1)
331 declare void @llvm.amdgcn.s.barrier() #1
332 declare i32 @llvm.amdgcn.workitem.id.x() #2
333 declare void @llvm.amdgcn.struct.ptr.tbuffer.store.v4i32(<4 x i32>, ptr addrspace(8), i32, i32, i32, i32 immarg, i32 immarg) #3
335 attributes #0 = { nounwind }
336 attributes #1 = { convergent nounwind willreturn }
337 attributes #2 = { nounwind readnone speculatable willreturn }
338 attributes #3 = { nounwind willreturn writeonly }