1 ; RUN: opt -passes=amdgpu-attributor -mcpu=kaveri -mattr=-promote-alloca < %s | llc | FileCheck -enable-var-scope -check-prefix=HSA -check-prefix=CI %s
2 ; RUN: opt -passes=amdgpu-attributor -mcpu=gfx900 -mattr=-promote-alloca < %s | llc | FileCheck -enable-var-scope -check-prefix=HSA -check-prefix=GFX9 %s
4 target triple = "amdgcn-amd-amdhsa"
6 ; HSA-LABEL: {{^}}use_group_to_flat_addrspacecast:
8 ; CI-DAG: s_load_dword [[PTR:s[0-9]+]], s[6:7], 0x0{{$}}
9 ; CI-DAG: s_load_dword [[APERTURE:s[0-9]+]], s[4:5], 0x10{{$}}
10 ; CI-DAG: s_cmp_lg_u32 [[PTR]], -1
11 ; CI-DAG: s_cselect_b32 s[[HI:[0-9]+]], [[APERTURE]], 0
12 ; CI-DAG: s_cselect_b32 s[[LO:[0-9]+]], [[PTR]], 0
14 ; GFX9-DAG: s_mov_b64 s[{{[0-9]+}}:[[HIBASE:[0-9]+]]], src_shared_base
16 ; HSA-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7
17 ; GFX9-DAG: s_load_dword [[PTR:s[0-9]+]], s[4:5], 0x0{{$}}
19 ; GFX9: s_cmp_lg_u32 [[PTR]], -1
20 ; GFX9-DAG: s_cselect_b32 s[[LO:[0-9]+]], s[[HIBASE]], 0
21 ; GFX9-DAG: s_cselect_b32 s[[HI:[0-9]+]], [[PTR]], 0
23 ; HSA: flat_store_dword v[[[LO]]:[[HI]]], [[K]]
25 ; HSA: .amdhsa_user_sgpr_private_segment_buffer 1
26 ; HSA: .amdhsa_user_sgpr_dispatch_ptr 0
27 ; CI: .amdhsa_user_sgpr_queue_ptr 1
28 ; GFX9: .amdhsa_user_sgpr_queue_ptr 0
30 ; At most 2 digits. Make sure src_shared_base is not counted as a high
33 ; HSA: NumSgprs: {{[0-9]+}}
34 define amdgpu_kernel void @use_group_to_flat_addrspacecast(ptr addrspace(3) %ptr) #0 {
35 %stof = addrspacecast ptr addrspace(3) %ptr to ptr
36 store volatile i32 7, ptr %stof
40 ; Test handling inside a non-kernel
41 ; HSA-LABEL: {{^}}use_group_to_flat_addrspacecast_func:
42 ; CI-DAG: s_load_dword [[APERTURE:s[0-9]+]], s[6:7], 0x10{{$}}
43 ; CI-DAG: v_mov_b32_e32 [[VAPERTURE:v[0-9]+]], [[APERTURE]]
44 ; CI-DAG: v_cmp_ne_u32_e32 vcc, -1, v0
45 ; CI-DAG: v_cndmask_b32_e32 v[[HI:[0-9]+]], 0, [[VAPERTURE]], vcc
46 ; CI-DAG: v_cndmask_b32_e32 v[[LO:[0-9]+]], 0, v0
48 ; GFX9-DAG: s_mov_b64 s[{{[0-9]+}}:[[HIBASE:[0-9]+]]], src_shared_base
50 ; HSA-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7
52 ; GFX9-DAG: v_mov_b32_e32 v[[VREG_HIBASE:[0-9]+]], s[[HIBASE]]
53 ; GFX9-DAG: v_cmp_ne_u32_e32 vcc, -1, v0
54 ; GFX9-DAG: v_cndmask_b32_e32 v[[LO:[0-9]+]], 0, v0, vcc
55 ; GFX9-DAG: v_cndmask_b32_e32 v[[HI:[0-9]+]], 0, v[[VREG_HIBASE]], vcc
57 ; HSA: flat_store_dword v[[[LO]]:[[HI]]], [[K]]
58 define void @use_group_to_flat_addrspacecast_func(ptr addrspace(3) %ptr) #0 {
59 %stof = addrspacecast ptr addrspace(3) %ptr to ptr
60 store volatile i32 7, ptr %stof
64 ; HSA-LABEL: {{^}}use_private_to_flat_addrspacecast:
66 ; CI-DAG: s_load_dword [[PTR:s[0-9]+]], s[6:7], 0x0{{$}}
67 ; CI-DAG: s_load_dword [[APERTURE:s[0-9]+]], s[4:5], 0x11{{$}}
69 ; CI-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7
70 ; CI-DAG: s_cmp_lg_u32 [[PTR]], -1
71 ; CI-DAG: s_cselect_b32 s[[HI:[0-9]+]], [[APERTURE]], 0
72 ; CI-DAG: s_cselect_b32 s[[LO:[0-9]+]], [[PTR]], 0
74 ; GFX9-DAG: s_load_dword [[PTR:s[0-9]+]], s[4:5], 0x0{{$}}
75 ; GFX9-DAG: s_mov_b64 s[{{[0-9]+}}:[[HIBASE:[0-9]+]]], src_private_base
77 ; GFX9-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7
78 ; GFX9: s_cmp_lg_u32 [[PTR]], -1
79 ; GFX9: s_cselect_b32 s[[LO:[0-9]+]], s[[HIBASE]], 0
80 ; GFX9: s_cselect_b32 s[[HI:[0-9]+]], [[PTR]], 0
82 ; HSA: flat_store_dword v[[[LO]]:[[HI]]], [[K]]
84 ; HSA: .amdhsa_user_sgpr_private_segment_buffer 1
85 ; HSA: .amdhsa_user_sgpr_dispatch_ptr 0
86 ; CI: .amdhsa_user_sgpr_queue_ptr 1
87 ; GFX9: .amdhsa_user_sgpr_queue_ptr 0
89 ; HSA: NumSgprs: {{[0-9]+}}
90 define amdgpu_kernel void @use_private_to_flat_addrspacecast(ptr addrspace(5) %ptr) #0 {
91 %stof = addrspacecast ptr addrspace(5) %ptr to ptr
92 store volatile i32 7, ptr %stof
97 ; HSA-LABEL: {{^}}use_global_to_flat_addrspacecast:
99 ; HSA: s_load_dwordx2 s[[[PTRLO:[0-9]+]]:[[PTRHI:[0-9]+]]]
100 ; HSA-DAG: v_mov_b32_e32 v[[VPTRLO:[0-9]+]], s[[PTRLO]]
101 ; HSA-DAG: v_mov_b32_e32 v[[VPTRHI:[0-9]+]], s[[PTRHI]]
102 ; HSA-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7
103 ; HSA: flat_store_dword v[[[VPTRLO]]:[[VPTRHI]]], [[K]]
105 ; HSA: .amdhsa_user_sgpr_queue_ptr 0
106 define amdgpu_kernel void @use_global_to_flat_addrspacecast(ptr addrspace(1) %ptr) #0 {
107 %stof = addrspacecast ptr addrspace(1) %ptr to ptr
108 store volatile i32 7, ptr %stof
113 ; HSA-LABEL: {{^}}use_constant_to_flat_addrspacecast:
114 ; HSA: s_load_dwordx2 s[[[PTRLO:[0-9]+]]:[[PTRHI:[0-9]+]]]
115 ; HSA-DAG: v_mov_b32_e32 v[[VPTRLO:[0-9]+]], s[[PTRLO]]
116 ; HSA-DAG: v_mov_b32_e32 v[[VPTRHI:[0-9]+]], s[[PTRHI]]
117 ; HSA: flat_load_dword v{{[0-9]+}}, v[[[VPTRLO]]:[[VPTRHI]]]
118 define amdgpu_kernel void @use_constant_to_flat_addrspacecast(ptr addrspace(4) %ptr) #0 {
119 %stof = addrspacecast ptr addrspace(4) %ptr to ptr
120 %ld = load volatile i32, ptr %stof
124 ; HSA-LABEL: {{^}}use_constant_to_global_addrspacecast:
125 ; HSA: s_load_dwordx2 s[[[PTRLO:[0-9]+]]:[[PTRHI:[0-9]+]]]
126 ; CI-DAG: v_mov_b32_e32 v[[VPTRLO:[0-9]+]], s[[PTRLO]]
127 ; CI-DAG: v_mov_b32_e32 v[[VPTRHI:[0-9]+]], s[[PTRHI]]
128 ; CI: {{flat|global}}_load_dword v{{[0-9]+}}, v[[[VPTRLO]]:[[VPTRHI]]]
130 ; GFX9: v_mov_b32_e32 [[ZERO:v[0-9]+]], 0{{$}}
131 ; GFX9: global_load_dword v{{[0-9]+}}, [[ZERO:v[0-9]+]], s[[[PTRLO]]:[[PTRHI]]]
132 define amdgpu_kernel void @use_constant_to_global_addrspacecast(ptr addrspace(4) %ptr) #0 {
133 %stof = addrspacecast ptr addrspace(4) %ptr to ptr addrspace(1)
134 %ld = load volatile i32, ptr addrspace(1) %stof
138 ; HSA-LABEL: {{^}}use_flat_to_group_addrspacecast:
140 ; HSA: s_load_dwordx2 s[[[PTR_LO:[0-9]+]]:[[PTR_HI:[0-9]+]]]
141 ; CI-DAG: v_cmp_ne_u64_e64 s[[[CMP_LO:[0-9]+]]:[[CMP_HI:[0-9]+]]], s[[[PTR_LO]]:[[PTR_HI]]], 0{{$}}
142 ; CI-DAG: s_and_b64 s{{[[0-9]+:[0-9]+]}}, s[[[CMP_LO]]:[[CMP_HI]]], exec
143 ; CI-DAG: s_cselect_b32 [[CASTPTR:s[0-9]+]], s[[PTR_LO]], -1
144 ; CI-DAG: v_mov_b32_e32 [[VCASTPTR:v[0-9]+]], [[CASTPTR]]
145 ; HSA-DAG: v_mov_b32_e32 v[[K:[0-9]+]], 0{{$}}
146 ; GFX9-DAG: s_cmp_lg_u64 s[[[CMP_LO:[0-9]+]]:[[CMP_HI:[0-9]+]]], 0
147 ; GFX9-DAG: s_cselect_b32 s[[PTR_LO]], s[[PTR_LO]], -1
148 ; GFX9-DAG: v_mov_b32_e32 [[CASTPTR:v[0-9]+]], s[[PTR_LO]]
149 ; CI-DAG: ds_write_b32 [[VCASTPTR]], v[[K]]
150 ; GFX9-DAG: ds_write_b32 [[CASTPTR]], v[[K]]
152 ; HSA: .amdhsa_user_sgpr_private_segment_buffer 1
153 ; HSA: .amdhsa_user_sgpr_dispatch_ptr 0
154 ; HSA: .amdhsa_user_sgpr_queue_ptr 0
155 define amdgpu_kernel void @use_flat_to_group_addrspacecast(ptr %ptr) #0 {
156 %ftos = addrspacecast ptr %ptr to ptr addrspace(3)
157 store volatile i32 0, ptr addrspace(3) %ftos
161 ; HSA-LABEL: {{^}}use_flat_to_private_addrspacecast:
163 ; HSA: s_load_dwordx2 s[[[PTR_LO:[0-9]+]]:[[PTR_HI:[0-9]+]]]
164 ; CI-DAG v_cmp_ne_u64_e64 vcc, s[[[PTR_LO]]:[[PTR_HI]]], 0{{$}}
165 ; CI-DAG v_mov_b32_e32 v[[VPTR_LO:[0-9]+]], s[[PTR_LO]]
166 ; CI-DAG v_cndmask_b32_e32 [[CASTPTR:v[0-9]+]], -1, v[[VPTR_LO]]
167 ; CI-DAG: v_cmp_ne_u64_e64 s[[[CMP_LO:[0-9]+]]:[[CMP_HI:[0-9]+]]], s[[[PTR_LO]]:[[PTR_HI]]], 0{{$}}
168 ; CI-DAG: s_and_b64 s{{[[0-9]+:[0-9]+]}}, s[[[CMP_LO]]:[[CMP_HI]]], exec
169 ; CI-DAG: s_cselect_b32 [[CASTPTR:s[0-9]+]], s[[PTR_LO]], -1
170 ; CI-DAG: v_mov_b32_e32 [[VCASTPTR:v[0-9]+]], [[CASTPTR]]
171 ; HSA-DAG: v_mov_b32_e32 v[[K:[0-9]+]], 0{{$}}
172 ; GFX9-DAG: s_cmp_lg_u64 s[[[CMP_LO:[0-9]+]]:[[CMP_HI:[0-9]+]]], 0
173 ; GFX9-DAG: s_cselect_b32 s[[PTR_LO]], s[[PTR_LO]], -1
174 ; GFX9-DAG: v_mov_b32_e32 [[CASTPTR:v[0-9]+]], s[[PTR_LO]]
175 ; CI: buffer_store_dword v[[K]], [[VCASTPTR]], s{{\[[0-9]+:[0-9]+\]}}, 0 offen{{$}}
176 ; GFX9: buffer_store_dword v[[K]], [[CASTPTR]], s{{\[[0-9]+:[0-9]+\]}}, 0 offen{{$}}
178 ; HSA: .amdhsa_user_sgpr_private_segment_buffer 1
179 ; HSA: .amdhsa_user_sgpr_dispatch_ptr 0
180 ; HSA: .amdhsa_user_sgpr_queue_ptr 0
181 define amdgpu_kernel void @use_flat_to_private_addrspacecast(ptr %ptr) #0 {
182 %ftos = addrspacecast ptr %ptr to ptr addrspace(5)
183 store volatile i32 0, ptr addrspace(5) %ftos
187 ; HSA-LABEL: {{^}}use_flat_to_global_addrspacecast:
189 ; HSA: s_load_dwordx2 s[[[PTRLO:[0-9]+]]:[[PTRHI:[0-9]+]]], s[4:5], 0x0
190 ; CI-DAG: v_mov_b32_e32 v[[VPTRLO:[0-9]+]], s[[PTRLO]]
191 ; CI-DAG: v_mov_b32_e32 v[[VPTRHI:[0-9]+]], s[[PTRHI]]
192 ; CI-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 0
193 ; CI: flat_store_dword v[[[VPTRLO]]:[[VPTRHI]]], [[K]]
195 ; GFX9: v_mov_b32_e32 [[ZERO:v[0-9]+]], 0
196 ; GFX9: global_store_dword [[ZERO]], [[ZERO]], s[[[PTRLO]]:[[PTRHI]]{{\]$}}
198 ; HSA: .amdhsa_user_sgpr_queue_ptr 0
199 define amdgpu_kernel void @use_flat_to_global_addrspacecast(ptr %ptr) #0 {
200 %ftos = addrspacecast ptr %ptr to ptr addrspace(1)
201 store volatile i32 0, ptr addrspace(1) %ftos
205 ; HSA-LABEL: {{^}}use_flat_to_constant_addrspacecast:
207 ; HSA: s_load_dwordx2 s[[[PTRLO:[0-9]+]]:[[PTRHI:[0-9]+]]], s[4:5], 0x0
208 ; HSA: s_load_dword s{{[0-9]+}}, s[[[PTRLO]]:[[PTRHI]]], 0x0
210 ; HSA: .amdhsa_user_sgpr_queue_ptr 0
211 define amdgpu_kernel void @use_flat_to_constant_addrspacecast(ptr %ptr) #0 {
212 %ftos = addrspacecast ptr %ptr to ptr addrspace(4)
213 load volatile i32, ptr addrspace(4) %ftos
217 ; HSA-LABEL: {{^}}cast_0_group_to_flat_addrspacecast:
218 ; CI: s_load_dword [[APERTURE:s[0-9]+]], s[4:5], 0x10
219 ; CI-DAG: v_mov_b32_e32 v[[HI:[0-9]+]], [[APERTURE]]
221 ; GFX9-DAG: s_mov_b64 s[{{[0-9]+}}:[[HI:[0-9]+]]], src_shared_base
223 ; HSA-DAG: v_mov_b32_e32 v[[LO:[0-9]+]], 0{{$}}
224 ; HSA-DAG: v_mov_b32_e32 v[[K:[0-9]+]], 7{{$}}
225 ; HSA: {{flat|global}}_store_dword v[[[LO]]:[[HI]]], v[[K]]
226 define amdgpu_kernel void @cast_0_group_to_flat_addrspacecast() #0 {
227 %cast = addrspacecast ptr addrspace(3) null to ptr
228 store volatile i32 7, ptr %cast
232 ; HSA-LABEL: {{^}}cast_0_flat_to_group_addrspacecast:
233 ; HSA-DAG: v_mov_b32_e32 [[PTR:v[0-9]+]], -1{{$}}
234 ; HSA-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7{{$}}
235 ; HSA: ds_write_b32 [[PTR]], [[K]]
236 define amdgpu_kernel void @cast_0_flat_to_group_addrspacecast() #0 {
237 %cast = addrspacecast ptr null to ptr addrspace(3)
238 store volatile i32 7, ptr addrspace(3) %cast
242 ; HSA-LABEL: {{^}}cast_neg1_group_to_flat_addrspacecast:
243 ; HSA: v_mov_b32_e32 v[[LO:[0-9]+]], 0{{$}}
244 ; HSA-DAG: v_mov_b32_e32 v[[K:[0-9]+]], 7{{$}}
245 ; HSA-DAG: v_mov_b32_e32 v[[HI:[0-9]+]], 0{{$}}
246 ; HSA: {{flat|global}}_store_dword v[[[LO]]:[[HI]]], v[[K]]
247 define amdgpu_kernel void @cast_neg1_group_to_flat_addrspacecast() #0 {
248 %cast = addrspacecast ptr addrspace(3) inttoptr (i32 -1 to ptr addrspace(3)) to ptr
249 store volatile i32 7, ptr %cast
253 ; HSA-LABEL: {{^}}cast_neg1_flat_to_group_addrspacecast:
254 ; HSA-DAG: v_mov_b32_e32 [[PTR:v[0-9]+]], -1{{$}}
255 ; HSA-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7{{$}}
256 ; HSA: ds_write_b32 [[PTR]], [[K]]
257 define amdgpu_kernel void @cast_neg1_flat_to_group_addrspacecast() #0 {
258 %cast = addrspacecast ptr inttoptr (i64 -1 to ptr) to ptr addrspace(3)
259 store volatile i32 7, ptr addrspace(3) %cast
263 ; FIXME: Shouldn't need to enable queue ptr
264 ; HSA-LABEL: {{^}}cast_0_private_to_flat_addrspacecast:
265 ; CI: s_load_dword [[APERTURE:s[0-9]+]], s[4:5], 0x11
266 ; CI-DAG: v_mov_b32_e32 v[[HI:[0-9]+]], [[APERTURE]]
268 ; GFX9-DAG: s_mov_b64 s[{{[0-9]+}}:[[HI:[0-9]+]]], src_private_base
270 ; HSA-DAG: v_mov_b32_e32 v[[LO:[0-9]+]], 0{{$}}
271 ; HSA-DAG: v_mov_b32_e32 v[[K:[0-9]+]], 7{{$}}
272 ; HSA: {{flat|global}}_store_dword v[[[LO]]:[[HI]]], v[[K]]
273 define amdgpu_kernel void @cast_0_private_to_flat_addrspacecast() #0 {
274 %cast = addrspacecast ptr addrspace(5) null to ptr
275 store volatile i32 7, ptr %cast
279 ; HSA-LABEL: {{^}}cast_0_flat_to_private_addrspacecast:
280 ; HSA-DAG: v_mov_b32_e32 [[PTR:v[0-9]+]], -1{{$}}
281 ; HSA-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7{{$}}
282 ; HSA: buffer_store_dword [[K]], [[PTR]], s{{\[[0-9]+:[0-9]+\]}}, 0
283 define amdgpu_kernel void @cast_0_flat_to_private_addrspacecast() #0 {
284 %cast = addrspacecast ptr null to ptr addrspace(5)
285 store volatile i32 7, ptr addrspace(5) %cast
290 ; HSA-LABEL: {{^}}cast_neg1_private_to_flat_addrspacecast:
292 ; HSA: v_mov_b32_e32 v[[LO:[0-9]+]], 0{{$}}
293 ; HSA-DAG: v_mov_b32_e32 v[[K:[0-9]+]], 7{{$}}
294 ; HSA-DAG: v_mov_b32_e32 v[[HI:[0-9]+]], 0{{$}}
295 ; HSA: {{flat|global}}_store_dword v[[[LO]]:[[HI]]], v[[K]]
297 ; CI: .amdhsa_user_sgpr_queue_ptr 1
298 ; GFX9: .amdhsa_user_sgpr_queue_ptr 0
299 define amdgpu_kernel void @cast_neg1_private_to_flat_addrspacecast() #0 {
300 %cast = addrspacecast ptr addrspace(5) inttoptr (i32 -1 to ptr addrspace(5)) to ptr
301 store volatile i32 7, ptr %cast
305 ; HSA-LABEL: {{^}}cast_neg1_flat_to_private_addrspacecast:
306 ; HSA-DAG: v_mov_b32_e32 [[PTR:v[0-9]+]], -1{{$}}
307 ; HSA-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7{{$}}
308 ; HSA: buffer_store_dword [[K]], [[PTR]], s{{\[[0-9]+:[0-9]+\]}}, 0
309 define amdgpu_kernel void @cast_neg1_flat_to_private_addrspacecast() #0 {
310 %cast = addrspacecast ptr inttoptr (i64 -1 to ptr) to ptr addrspace(5)
311 store volatile i32 7, ptr addrspace(5) %cast
316 ; Disable optimizations in case there are optimizations added that
317 ; specialize away generic pointer accesses.
319 ; HSA-LABEL: {{^}}branch_use_flat_i32:
320 ; HSA: {{flat|global}}_store_dword {{v\[[0-9]+:[0-9]+\]}}, {{v[0-9]+}}
322 define amdgpu_kernel void @branch_use_flat_i32(ptr addrspace(1) noalias %out, ptr addrspace(1) %gptr, ptr addrspace(3) %lptr, i32 %x, i32 %c) #0 {
324 %cmp = icmp ne i32 %c, 0
325 br i1 %cmp, label %local, label %global
328 %flat_local = addrspacecast ptr addrspace(3) %lptr to ptr
332 %flat_global = addrspacecast ptr addrspace(1) %gptr to ptr
336 %fptr = phi ptr [ %flat_local, %local ], [ %flat_global, %global ]
337 store volatile i32 %x, ptr %fptr, align 4
338 ; %val = load i32, ptr %fptr, align 4
339 ; store i32 %val, ptr addrspace(1) %out, align 4
343 ; Check for prologue initializing special SGPRs pointing to scratch.
344 ; HSA-LABEL: {{^}}store_flat_scratch:
345 ; CI-DAG: s_mov_b32 flat_scratch_lo, s9
346 ; CI-DAG: s_add_i32 [[ADD:s[0-9]+]], s8, s11
347 ; CI-DAG: s_lshr_b32 flat_scratch_hi, [[ADD]], 8
349 ; GFX9: s_add_u32 flat_scratch_lo, s6, s9
350 ; GFX9: s_addc_u32 flat_scratch_hi, s7, 0
352 ; HSA: {{flat|global}}_store_dword
354 ; HSA: {{flat|global}}_load_dword
355 define amdgpu_kernel void @store_flat_scratch(ptr addrspace(1) noalias %out, i32) #0 {
356 %alloca = alloca i32, i32 9, align 4, addrspace(5)
357 %x = call i32 @llvm.amdgcn.workitem.id.x() #2
358 %pptr = getelementptr i32, ptr addrspace(5) %alloca, i32 %x
359 %fptr = addrspacecast ptr addrspace(5) %pptr to ptr
360 store volatile i32 %x, ptr %fptr
362 call void @llvm.amdgcn.s.barrier() #1
363 %reload = load volatile i32, ptr %fptr, align 4
364 store volatile i32 %reload, ptr addrspace(1) %out, align 4
368 ; HSA-LABEL: {{^}}use_constant_to_constant32_addrspacecast
369 ; GFX9: s_load_dwordx2 [[PTRPTR:s\[[0-9]+:[0-9]+\]]], s[4:5], 0x0{{$}}
370 ; GFX9: s_load_dword [[OFFSET:s[0-9]+]], s[4:5], 0x8{{$}}
371 ; GFX9: s_load_dwordx2 s[[[PTR_LO:[0-9]+]]:[[PTR_HI:[0-9]+]]], [[PTRPTR]], 0x0{{$}}
372 ; GFX9: s_mov_b32 s[[PTR_HI]], 0{{$}}
373 ; GFX9: s_add_i32 s[[PTR_LO]], s[[PTR_LO]], [[OFFSET]]
374 ; GFX9: s_load_dword s{{[0-9]+}}, s[[[PTR_LO]]:[[PTR_HI]]], 0x0{{$}}
375 define amdgpu_kernel void @use_constant_to_constant32_addrspacecast(ptr addrspace(4) %ptr.ptr, i32 %offset) #0 {
376 %ptr = load volatile ptr addrspace(4), ptr addrspace(4) %ptr.ptr
377 %addrspacecast = addrspacecast ptr addrspace(4) %ptr to ptr addrspace(6)
378 %gep = getelementptr i8, ptr addrspace(6) %addrspacecast, i32 %offset
379 %load = load volatile i32, ptr addrspace(6) %gep, align 4
383 ; HSA-LABEL: {{^}}use_global_to_constant32_addrspacecast
384 ; GFX9: s_load_dwordx2 [[PTRPTR:s\[[0-9]+:[0-9]+\]]], s[4:5], 0x0{{$}}
385 ; GFX9: s_load_dword [[OFFSET:s[0-9]+]], s[4:5], 0x8{{$}}
386 ; GFX9: s_load_dwordx2 s[[[PTR_LO:[0-9]+]]:[[PTR_HI:[0-9]+]]], [[PTRPTR]], 0x0{{$}}
387 ; GFX9: s_mov_b32 s[[PTR_HI]], 0{{$}}
388 ; GFX9: s_add_i32 s[[PTR_LO]], s[[PTR_LO]], [[OFFSET]]
389 ; GFX9: s_load_dword s{{[0-9]+}}, s[[[PTR_LO]]:[[PTR_HI]]], 0x0{{$}}
390 define amdgpu_kernel void @use_global_to_constant32_addrspacecast(ptr addrspace(4) %ptr.ptr, i32 %offset) #0 {
391 %ptr = load volatile ptr addrspace(1), ptr addrspace(4) %ptr.ptr
392 %addrspacecast = addrspacecast ptr addrspace(1) %ptr to ptr addrspace(6)
393 %gep = getelementptr i8, ptr addrspace(6) %addrspacecast, i32 %offset
394 %load = load volatile i32, ptr addrspace(6) %gep, align 4
398 ; GCN-LABEL: {{^}}use_constant32bit_to_flat_addrspacecast_0:
399 ; GCN: s_load_dword [[PTR:s[0-9]+]],
400 ; GCN: v_mov_b32_e32 v[[HI:[0-9]+]], 0
401 ; GCN: v_mov_b32_e32 v[[LO:[0-9]+]], [[PTR]]
402 ; GCN: flat_load_dword v{{[0-9]+}}, v[[[LO]]:[[HI]]]
403 define amdgpu_kernel void @use_constant32bit_to_flat_addrspacecast_0(ptr addrspace(6) %ptr) #0 {
404 %stof = addrspacecast ptr addrspace(6) %ptr to ptr
405 %load = load volatile i32, ptr %stof
409 ; GCN-LABEL: {{^}}use_constant32bit_to_flat_addrspacecast_1:
410 ; GCN: s_load_dword [[PTR:s[0-9]+]],
411 ; GCN: v_mov_b32_e32 v[[HI:[0-9]+]], 0xffff8000
412 ; GCN: v_mov_b32_e32 v[[LO:[0-9]+]], [[PTR]]
413 ; GCN: flat_load_dword v{{[0-9]+}}, v[[[LO]]:[[HI]]]
414 define amdgpu_kernel void @use_constant32bit_to_flat_addrspacecast_1(ptr addrspace(6) %ptr) #3 {
415 %stof = addrspacecast ptr addrspace(6) %ptr to ptr
416 %load = load volatile i32, ptr %stof
420 declare void @llvm.amdgcn.s.barrier() #1
421 declare i32 @llvm.amdgcn.workitem.id.x() #2
423 attributes #0 = { nounwind }
424 attributes #1 = { nounwind convergent }
425 attributes #2 = { nounwind readnone }
426 attributes #3 = { nounwind "amdgpu-32bit-address-high-bits"="0xffff8000" }
428 !llvm.module.flags = !{!0}
429 !0 = !{i32 1, !"amdhsa_code_object_version", i32 400}