1 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=kaveri -mattr=-promote-alloca -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=HSA -check-prefix=CI %s
2 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -mattr=-promote-alloca -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=HSA -check-prefix=GFX9 %s
4 ; HSA-LABEL: {{^}}use_group_to_flat_addrspacecast:
6 ; CI-DAG: s_load_dword [[PTR:s[0-9]+]], s[6:7], 0x0{{$}}
7 ; CI-DAG: s_load_dword [[APERTURE:s[0-9]+]], s[4:5], 0x10{{$}}
8 ; CI-DAG: s_cmp_lg_u32 [[PTR]], -1
9 ; CI-DAG: s_cselect_b32 s[[HI:[0-9]+]], [[APERTURE]], 0
10 ; CI-DAG: s_cselect_b32 s[[LO:[0-9]+]], [[PTR]], 0
12 ; GFX9-DAG: s_mov_b64 s[{{[0-9]+}}:[[HIBASE:[0-9]+]]], src_shared_base
14 ; HSA-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7
15 ; GFX9-DAG: s_load_dword [[PTR:s[0-9]+]], s[4:5], 0x0{{$}}
17 ; GFX9: s_cmp_lg_u32 [[PTR]], -1
18 ; GFX9-DAG: s_cselect_b32 s[[LO:[0-9]+]], s[[HIBASE]], 0
19 ; GFX9-DAG: s_cselect_b32 s[[HI:[0-9]+]], [[PTR]], 0
21 ; HSA: flat_store_dword v[[[LO]]:[[HI]]], [[K]]
23 ; HSA: .amdhsa_user_sgpr_private_segment_buffer 1
24 ; HSA: .amdhsa_user_sgpr_dispatch_ptr 0
25 ; CI: .amdhsa_user_sgpr_queue_ptr 1
26 ; GFX9: .amdhsa_user_sgpr_queue_ptr 0
28 ; At most 2 digits. Make sure src_shared_base is not counted as a high
31 ; HSA: NumSgprs: {{[0-9]+}}
32 define amdgpu_kernel void @use_group_to_flat_addrspacecast(ptr addrspace(3) %ptr) #0 {
33 %stof = addrspacecast ptr addrspace(3) %ptr to ptr
34 store volatile i32 7, ptr %stof
38 ; Test handling inside a non-kernel
39 ; HSA-LABEL: {{^}}use_group_to_flat_addrspacecast_func:
40 ; CI-DAG: s_load_dword [[APERTURE:s[0-9]+]], s[6:7], 0x10{{$}}
41 ; CI-DAG: v_mov_b32_e32 [[VAPERTURE:v[0-9]+]], [[APERTURE]]
42 ; CI-DAG: v_cmp_ne_u32_e32 vcc, -1, v0
43 ; CI-DAG: v_cndmask_b32_e32 v[[HI:[0-9]+]], 0, [[VAPERTURE]], vcc
44 ; CI-DAG: v_cndmask_b32_e32 v[[LO:[0-9]+]], 0, v0
46 ; GFX9-DAG: s_mov_b64 s[{{[0-9]+}}:[[HIBASE:[0-9]+]]], src_shared_base
48 ; HSA-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7
50 ; GFX9-DAG: v_mov_b32_e32 v[[VREG_HIBASE:[0-9]+]], s[[HIBASE]]
51 ; GFX9-DAG: v_cmp_ne_u32_e32 vcc, -1, v0
52 ; GFX9-DAG: v_cndmask_b32_e32 v[[LO:[0-9]+]], 0, v0, vcc
53 ; GFX9-DAG: v_cndmask_b32_e32 v[[HI:[0-9]+]], 0, v[[VREG_HIBASE]], vcc
55 ; HSA: flat_store_dword v[[[LO]]:[[HI]]], [[K]]
56 define void @use_group_to_flat_addrspacecast_func(ptr addrspace(3) %ptr) #0 {
57 %stof = addrspacecast ptr addrspace(3) %ptr to ptr
58 store volatile i32 7, ptr %stof
62 ; HSA-LABEL: {{^}}use_private_to_flat_addrspacecast:
64 ; CI-DAG: s_load_dword [[PTR:s[0-9]+]], s[6:7], 0x0{{$}}
65 ; CI-DAG: s_load_dword [[APERTURE:s[0-9]+]], s[4:5], 0x11{{$}}
67 ; CI-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7
68 ; CI-DAG: s_cmp_lg_u32 [[PTR]], -1
69 ; CI-DAG: s_cselect_b32 s[[HI:[0-9]+]], [[APERTURE]], 0
70 ; CI-DAG: s_cselect_b32 s[[LO:[0-9]+]], [[PTR]], 0
72 ; GFX9-DAG: s_load_dword [[PTR:s[0-9]+]], s[4:5], 0x0{{$}}
73 ; GFX9-DAG: s_mov_b64 s[{{[0-9]+}}:[[HIBASE:[0-9]+]]], src_private_base
75 ; GFX9-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7
76 ; GFX9: s_cmp_lg_u32 [[PTR]], -1
77 ; GFX9: s_cselect_b32 s[[LO:[0-9]+]], s[[HIBASE]], 0
78 ; GFX9: s_cselect_b32 s[[HI:[0-9]+]], [[PTR]], 0
80 ; HSA: flat_store_dword v[[[LO]]:[[HI]]], [[K]]
82 ; HSA: .amdhsa_user_sgpr_private_segment_buffer 1
83 ; HSA: .amdhsa_user_sgpr_dispatch_ptr 0
84 ; CI: .amdhsa_user_sgpr_queue_ptr 1
85 ; GFX9: .amdhsa_user_sgpr_queue_ptr 0
87 ; HSA: NumSgprs: {{[0-9]+}}
88 define amdgpu_kernel void @use_private_to_flat_addrspacecast(ptr addrspace(5) %ptr) #0 {
89 %stof = addrspacecast ptr addrspace(5) %ptr to ptr
90 store volatile i32 7, ptr %stof
95 ; HSA-LABEL: {{^}}use_global_to_flat_addrspacecast:
97 ; HSA: s_load_dwordx2 s[[[PTRLO:[0-9]+]]:[[PTRHI:[0-9]+]]]
98 ; HSA-DAG: v_mov_b32_e32 v[[VPTRLO:[0-9]+]], s[[PTRLO]]
99 ; HSA-DAG: v_mov_b32_e32 v[[VPTRHI:[0-9]+]], s[[PTRHI]]
100 ; HSA-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7
101 ; HSA: flat_store_dword v[[[VPTRLO]]:[[VPTRHI]]], [[K]]
103 ; HSA: .amdhsa_user_sgpr_queue_ptr 0
104 define amdgpu_kernel void @use_global_to_flat_addrspacecast(ptr addrspace(1) %ptr) #0 {
105 %stof = addrspacecast ptr addrspace(1) %ptr to ptr
106 store volatile i32 7, ptr %stof
111 ; HSA-LABEl: {{^}}use_constant_to_flat_addrspacecast:
112 ; HSA: s_load_dwordx2 s[[[PTRLO:[0-9]+]]:[[PTRHI:[0-9]+]]]
113 ; HSA-DAG: v_mov_b32_e32 v[[VPTRLO:[0-9]+]], s[[PTRLO]]
114 ; HSA-DAG: v_mov_b32_e32 v[[VPTRHI:[0-9]+]], s[[PTRHI]]
115 ; HSA: flat_load_dword v{{[0-9]+}}, v[[[VPTRLO]]:[[VPTRHI]]]
116 define amdgpu_kernel void @use_constant_to_flat_addrspacecast(ptr addrspace(4) %ptr) #0 {
117 %stof = addrspacecast ptr addrspace(4) %ptr to ptr
118 %ld = load volatile i32, ptr %stof
122 ; HSA-LABEl: {{^}}use_constant_to_global_addrspacecast:
123 ; HSA: s_load_dwordx2 s[[[PTRLO:[0-9]+]]:[[PTRHI:[0-9]+]]]
124 ; CI-DAG: v_mov_b32_e32 v[[VPTRLO:[0-9]+]], s[[PTRLO]]
125 ; CI-DAG: v_mov_b32_e32 v[[VPTRHI:[0-9]+]], s[[PTRHI]]
126 ; CI: {{flat|global}}_load_dword v{{[0-9]+}}, v[[[VPTRLO]]:[[VPTRHI]]]
128 ; GFX9: v_mov_b32_e32 [[ZERO:v[0-9]+]], 0{{$}}
129 ; GFX9: global_load_dword v{{[0-9]+}}, [[ZERO:v[0-9]+]], s[[[PTRLO]]:[[PTRHI]]]
130 define amdgpu_kernel void @use_constant_to_global_addrspacecast(ptr addrspace(4) %ptr) #0 {
131 %stof = addrspacecast ptr addrspace(4) %ptr to ptr addrspace(1)
132 %ld = load volatile i32, ptr addrspace(1) %stof
136 ; HSA-LABEL: {{^}}use_flat_to_group_addrspacecast:
138 ; HSA: s_load_dwordx2 s[[[PTR_LO:[0-9]+]]:[[PTR_HI:[0-9]+]]]
139 ; CI-DAG: v_cmp_ne_u64_e64 s[[[CMP_LO:[0-9]+]]:[[CMP_HI:[0-9]+]]], s[[[PTR_LO]]:[[PTR_HI]]], 0{{$}}
140 ; CI-DAG: s_and_b64 s{{[[0-9]+:[0-9]+]}}, s[[[CMP_LO]]:[[CMP_HI]]], exec
141 ; CI-DAG: s_cselect_b32 [[CASTPTR:s[0-9]+]], s[[PTR_LO]], -1
142 ; CI-DAG: v_mov_b32_e32 [[VCASTPTR:v[0-9]+]], [[CASTPTR]]
143 ; HSA-DAG: v_mov_b32_e32 v[[K:[0-9]+]], 0{{$}}
144 ; GFX9-DAG: s_cmp_lg_u64 s[[[CMP_LO:[0-9]+]]:[[CMP_HI:[0-9]+]]], 0
145 ; GFX9-DAG: s_cselect_b32 s[[PTR_LO]], s[[PTR_LO]], -1
146 ; GFX9-DAG: v_mov_b32_e32 [[CASTPTR:v[0-9]+]], s[[PTR_LO]]
147 ; CI-DAG: ds_write_b32 [[VCASTPTR]], v[[K]]
148 ; GFX9-DAG: ds_write_b32 [[CASTPTR]], v[[K]]
150 ; HSA: .amdhsa_user_sgpr_private_segment_buffer 1
151 ; HSA: .amdhsa_user_sgpr_dispatch_ptr 0
152 ; HSA: .amdhsa_user_sgpr_queue_ptr 0
153 define amdgpu_kernel void @use_flat_to_group_addrspacecast(ptr %ptr) #0 {
154 %ftos = addrspacecast ptr %ptr to ptr addrspace(3)
155 store volatile i32 0, ptr addrspace(3) %ftos
159 ; HSA-LABEL: {{^}}use_flat_to_private_addrspacecast:
161 ; HSA: s_load_dwordx2 s[[[PTR_LO:[0-9]+]]:[[PTR_HI:[0-9]+]]]
162 ; CI-DAG v_cmp_ne_u64_e64 vcc, s[[[PTR_LO]]:[[PTR_HI]]], 0{{$}}
163 ; CI-DAG v_mov_b32_e32 v[[VPTR_LO:[0-9]+]], s[[PTR_LO]]
164 ; CI-DAG v_cndmask_b32_e32 [[CASTPTR:v[0-9]+]], -1, v[[VPTR_LO]]
165 ; CI-DAG: v_cmp_ne_u64_e64 s[[[CMP_LO:[0-9]+]]:[[CMP_HI:[0-9]+]]], s[[[PTR_LO]]:[[PTR_HI]]], 0{{$}}
166 ; CI-DAG: s_and_b64 s{{[[0-9]+:[0-9]+]}}, s[[[CMP_LO]]:[[CMP_HI]]], exec
167 ; CI-DAG: s_cselect_b32 [[CASTPTR:s[0-9]+]], s[[PTR_LO]], -1
168 ; CI-DAG: v_mov_b32_e32 [[VCASTPTR:v[0-9]+]], [[CASTPTR]]
169 ; HSA-DAG: v_mov_b32_e32 v[[K:[0-9]+]], 0{{$}}
170 ; GFX9-DAG: s_cmp_lg_u64 s[[[CMP_LO:[0-9]+]]:[[CMP_HI:[0-9]+]]], 0
171 ; GFX9-DAG: s_cselect_b32 s[[PTR_LO]], s[[PTR_LO]], -1
172 ; GFX9-DAG: v_mov_b32_e32 [[CASTPTR:v[0-9]+]], s[[PTR_LO]]
173 ; CI: buffer_store_dword v[[K]], [[VCASTPTR]], s{{\[[0-9]+:[0-9]+\]}}, 0 offen{{$}}
174 ; GFX9: buffer_store_dword v[[K]], [[CASTPTR]], s{{\[[0-9]+:[0-9]+\]}}, 0 offen{{$}}
176 ; HSA: .amdhsa_user_sgpr_private_segment_buffer 1
177 ; HSA: .amdhsa_user_sgpr_dispatch_ptr 0
178 ; HSA: .amdhsa_user_sgpr_queue_ptr 0
179 define amdgpu_kernel void @use_flat_to_private_addrspacecast(ptr %ptr) #0 {
180 %ftos = addrspacecast ptr %ptr to ptr addrspace(5)
181 store volatile i32 0, ptr addrspace(5) %ftos
185 ; HSA-LABEL: {{^}}use_flat_to_global_addrspacecast:
187 ; HSA: s_load_dwordx2 s[[[PTRLO:[0-9]+]]:[[PTRHI:[0-9]+]]], s[4:5], 0x0
188 ; CI-DAG: v_mov_b32_e32 v[[VPTRLO:[0-9]+]], s[[PTRLO]]
189 ; CI-DAG: v_mov_b32_e32 v[[VPTRHI:[0-9]+]], s[[PTRHI]]
190 ; CI-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 0
191 ; CI: flat_store_dword v[[[VPTRLO]]:[[VPTRHI]]], [[K]]
193 ; GFX9: v_mov_b32_e32 [[ZERO:v[0-9]+]], 0
194 ; GFX9: global_store_dword [[ZERO]], [[ZERO]], s[[[PTRLO]]:[[PTRHI]]{{\]$}}
196 ; HSA: .amdhsa_user_sgpr_queue_ptr 0
197 define amdgpu_kernel void @use_flat_to_global_addrspacecast(ptr %ptr) #0 {
198 %ftos = addrspacecast ptr %ptr to ptr addrspace(1)
199 store volatile i32 0, ptr addrspace(1) %ftos
203 ; HSA-LABEL: {{^}}use_flat_to_constant_addrspacecast:
205 ; HSA: s_load_dwordx2 s[[[PTRLO:[0-9]+]]:[[PTRHI:[0-9]+]]], s[4:5], 0x0
206 ; HSA: s_load_dword s{{[0-9]+}}, s[[[PTRLO]]:[[PTRHI]]], 0x0
208 ; HSA: .amdhsa_user_sgpr_queue_ptr 0
209 define amdgpu_kernel void @use_flat_to_constant_addrspacecast(ptr %ptr) #0 {
210 %ftos = addrspacecast ptr %ptr to ptr addrspace(4)
211 load volatile i32, ptr addrspace(4) %ftos
215 ; HSA-LABEL: {{^}}cast_0_group_to_flat_addrspacecast:
216 ; CI: s_load_dword [[APERTURE:s[0-9]+]], s[4:5], 0x10
217 ; CI-DAG: v_mov_b32_e32 v[[HI:[0-9]+]], [[APERTURE]]
219 ; GFX9-DAG: s_mov_b64 s[{{[0-9]+}}:[[HI:[0-9]+]]], src_shared_base
221 ; HSA-DAG: v_mov_b32_e32 v[[LO:[0-9]+]], 0{{$}}
222 ; HSA-DAG: v_mov_b32_e32 v[[K:[0-9]+]], 7{{$}}
223 ; HSA: {{flat|global}}_store_dword v[[[LO]]:[[HI]]], v[[K]]
224 define amdgpu_kernel void @cast_0_group_to_flat_addrspacecast() #0 {
225 %cast = addrspacecast ptr addrspace(3) null to ptr
226 store volatile i32 7, ptr %cast
230 ; HSA-LABEL: {{^}}cast_0_flat_to_group_addrspacecast:
231 ; HSA-DAG: v_mov_b32_e32 [[PTR:v[0-9]+]], -1{{$}}
232 ; HSA-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7{{$}}
233 ; HSA: ds_write_b32 [[PTR]], [[K]]
234 define amdgpu_kernel void @cast_0_flat_to_group_addrspacecast() #0 {
235 %cast = addrspacecast ptr null to ptr addrspace(3)
236 store volatile i32 7, ptr addrspace(3) %cast
240 ; HSA-LABEL: {{^}}cast_neg1_group_to_flat_addrspacecast:
241 ; HSA: v_mov_b32_e32 v[[LO:[0-9]+]], 0{{$}}
242 ; HSA-DAG: v_mov_b32_e32 v[[K:[0-9]+]], 7{{$}}
243 ; HSA-DAG: v_mov_b32_e32 v[[HI:[0-9]+]], 0{{$}}
244 ; HSA: {{flat|global}}_store_dword v[[[LO]]:[[HI]]], v[[K]]
245 define amdgpu_kernel void @cast_neg1_group_to_flat_addrspacecast() #0 {
246 %cast = addrspacecast ptr addrspace(3) inttoptr (i32 -1 to ptr addrspace(3)) to ptr
247 store volatile i32 7, ptr %cast
251 ; HSA-LABEL: {{^}}cast_neg1_flat_to_group_addrspacecast:
252 ; HSA-DAG: v_mov_b32_e32 [[PTR:v[0-9]+]], -1{{$}}
253 ; HSA-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7{{$}}
254 ; HSA: ds_write_b32 [[PTR]], [[K]]
255 define amdgpu_kernel void @cast_neg1_flat_to_group_addrspacecast() #0 {
256 %cast = addrspacecast ptr inttoptr (i64 -1 to ptr) to ptr addrspace(3)
257 store volatile i32 7, ptr addrspace(3) %cast
261 ; FIXME: Shouldn't need to enable queue ptr
262 ; HSA-LABEL: {{^}}cast_0_private_to_flat_addrspacecast:
263 ; CI: s_load_dword [[APERTURE:s[0-9]+]], s[4:5], 0x11
264 ; CI-DAG: v_mov_b32_e32 v[[HI:[0-9]+]], [[APERTURE]]
266 ; GFX9-DAG: s_mov_b64 s[{{[0-9]+}}:[[HI:[0-9]+]]], src_private_base
268 ; HSA-DAG: v_mov_b32_e32 v[[LO:[0-9]+]], 0{{$}}
269 ; HSA-DAG: v_mov_b32_e32 v[[K:[0-9]+]], 7{{$}}
270 ; HSA: {{flat|global}}_store_dword v[[[LO]]:[[HI]]], v[[K]]
271 define amdgpu_kernel void @cast_0_private_to_flat_addrspacecast() #0 {
272 %cast = addrspacecast ptr addrspace(5) null to ptr
273 store volatile i32 7, ptr %cast
277 ; HSA-LABEL: {{^}}cast_0_flat_to_private_addrspacecast:
278 ; HSA-DAG: v_mov_b32_e32 [[PTR:v[0-9]+]], -1{{$}}
279 ; HSA-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7{{$}}
280 ; HSA: buffer_store_dword [[K]], [[PTR]], s{{\[[0-9]+:[0-9]+\]}}, 0
281 define amdgpu_kernel void @cast_0_flat_to_private_addrspacecast() #0 {
282 %cast = addrspacecast ptr null to ptr addrspace(5)
283 store volatile i32 7, ptr addrspace(5) %cast
288 ; HSA-LABEL: {{^}}cast_neg1_private_to_flat_addrspacecast:
290 ; HSA: v_mov_b32_e32 v[[LO:[0-9]+]], 0{{$}}
291 ; HSA-DAG: v_mov_b32_e32 v[[K:[0-9]+]], 7{{$}}
292 ; HSA-DAG: v_mov_b32_e32 v[[HI:[0-9]+]], 0{{$}}
293 ; HSA: {{flat|global}}_store_dword v[[[LO]]:[[HI]]], v[[K]]
295 ; CI: .amdhsa_user_sgpr_queue_ptr 1
296 ; GFX9: .amdhsa_user_sgpr_queue_ptr 0
297 define amdgpu_kernel void @cast_neg1_private_to_flat_addrspacecast() #0 {
298 %cast = addrspacecast ptr addrspace(5) inttoptr (i32 -1 to ptr addrspace(5)) to ptr
299 store volatile i32 7, ptr %cast
303 ; HSA-LABEL: {{^}}cast_neg1_flat_to_private_addrspacecast:
304 ; HSA-DAG: v_mov_b32_e32 [[PTR:v[0-9]+]], -1{{$}}
305 ; HSA-DAG: v_mov_b32_e32 [[K:v[0-9]+]], 7{{$}}
306 ; HSA: buffer_store_dword [[K]], [[PTR]], s{{\[[0-9]+:[0-9]+\]}}, 0
307 define amdgpu_kernel void @cast_neg1_flat_to_private_addrspacecast() #0 {
308 %cast = addrspacecast ptr inttoptr (i64 -1 to ptr) to ptr addrspace(5)
309 store volatile i32 7, ptr addrspace(5) %cast
314 ; Disable optimizations in case there are optimizations added that
315 ; specialize away generic pointer accesses.
317 ; HSA-LABEL: {{^}}branch_use_flat_i32:
318 ; HSA: {{flat|global}}_store_dword {{v\[[0-9]+:[0-9]+\]}}, {{v[0-9]+}}
320 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 {
322 %cmp = icmp ne i32 %c, 0
323 br i1 %cmp, label %local, label %global
326 %flat_local = addrspacecast ptr addrspace(3) %lptr to ptr
330 %flat_global = addrspacecast ptr addrspace(1) %gptr to ptr
334 %fptr = phi ptr [ %flat_local, %local ], [ %flat_global, %global ]
335 store volatile i32 %x, ptr %fptr, align 4
336 ; %val = load i32, ptr %fptr, align 4
337 ; store i32 %val, ptr addrspace(1) %out, align 4
341 ; Check for prologue initializing special SGPRs pointing to scratch.
342 ; HSA-LABEL: {{^}}store_flat_scratch:
343 ; CI-DAG: s_mov_b32 flat_scratch_lo, s9
344 ; CI-DAG: s_add_i32 [[ADD:s[0-9]+]], s8, s11
345 ; CI-DAG: s_lshr_b32 flat_scratch_hi, [[ADD]], 8
347 ; GFX9: s_add_u32 flat_scratch_lo, s6, s9
348 ; GFX9: s_addc_u32 flat_scratch_hi, s7, 0
350 ; HSA: {{flat|global}}_store_dword
352 ; HSA: {{flat|global}}_load_dword
353 define amdgpu_kernel void @store_flat_scratch(ptr addrspace(1) noalias %out, i32) #0 {
354 %alloca = alloca i32, i32 9, align 4, addrspace(5)
355 %x = call i32 @llvm.amdgcn.workitem.id.x() #2
356 %pptr = getelementptr i32, ptr addrspace(5) %alloca, i32 %x
357 %fptr = addrspacecast ptr addrspace(5) %pptr to ptr
358 store volatile i32 %x, ptr %fptr
360 call void @llvm.amdgcn.s.barrier() #1
361 %reload = load volatile i32, ptr %fptr, align 4
362 store volatile i32 %reload, ptr addrspace(1) %out, align 4
366 ; HSA-LABEL: {{^}}use_constant_to_constant32_addrspacecast
367 ; GFX9: s_load_dwordx2 [[PTRPTR:s\[[0-9]+:[0-9]+\]]], s[4:5], 0x0{{$}}
368 ; GFX9: s_load_dword [[OFFSET:s[0-9]+]], s[4:5], 0x8{{$}}
369 ; GFX9: s_load_dwordx2 s[[[PTR_LO:[0-9]+]]:[[PTR_HI:[0-9]+]]], [[PTRPTR]], 0x0{{$}}
370 ; GFX9: s_mov_b32 s[[PTR_HI]], 0{{$}}
371 ; GFX9: s_add_i32 s[[PTR_LO]], s[[PTR_LO]], [[OFFSET]]
372 ; GFX9: s_load_dword s{{[0-9]+}}, s[[[PTR_LO]]:[[PTR_HI]]], 0x0{{$}}
373 define amdgpu_kernel void @use_constant_to_constant32_addrspacecast(ptr addrspace(4) %ptr.ptr, i32 %offset) #0 {
374 %ptr = load volatile ptr addrspace(4), ptr addrspace(4) %ptr.ptr
375 %addrspacecast = addrspacecast ptr addrspace(4) %ptr to ptr addrspace(6)
376 %gep = getelementptr i8, ptr addrspace(6) %addrspacecast, i32 %offset
377 %load = load volatile i32, ptr addrspace(6) %gep, align 4
381 ; HSA-LABEL: {{^}}use_global_to_constant32_addrspacecast
382 ; GFX9: s_load_dwordx2 [[PTRPTR:s\[[0-9]+:[0-9]+\]]], s[4:5], 0x0{{$}}
383 ; GFX9: s_load_dword [[OFFSET:s[0-9]+]], s[4:5], 0x8{{$}}
384 ; GFX9: s_load_dwordx2 s[[[PTR_LO:[0-9]+]]:[[PTR_HI:[0-9]+]]], [[PTRPTR]], 0x0{{$}}
385 ; GFX9: s_mov_b32 s[[PTR_HI]], 0{{$}}
386 ; GFX9: s_add_i32 s[[PTR_LO]], s[[PTR_LO]], [[OFFSET]]
387 ; GFX9: s_load_dword s{{[0-9]+}}, s[[[PTR_LO]]:[[PTR_HI]]], 0x0{{$}}
388 define amdgpu_kernel void @use_global_to_constant32_addrspacecast(ptr addrspace(4) %ptr.ptr, i32 %offset) #0 {
389 %ptr = load volatile ptr addrspace(1), ptr addrspace(4) %ptr.ptr
390 %addrspacecast = addrspacecast ptr addrspace(1) %ptr to ptr addrspace(6)
391 %gep = getelementptr i8, ptr addrspace(6) %addrspacecast, i32 %offset
392 %load = load volatile i32, ptr addrspace(6) %gep, align 4
396 ; GCN-LABEL: {{^}}use_constant32bit_to_flat_addrspacecast_0:
397 ; GCN: s_load_dword [[PTR:s[0-9]+]],
398 ; GCN: v_mov_b32_e32 v[[HI:[0-9]+]], 0
399 ; GCN: v_mov_b32_e32 v[[LO:[0-9]+]], [[PTR]]
400 ; GCN: flat_load_dword v{{[0-9]+}}, v[[[LO]]:[[HI]]]
401 define amdgpu_kernel void @use_constant32bit_to_flat_addrspacecast_0(ptr addrspace(6) %ptr) #0 {
402 %stof = addrspacecast ptr addrspace(6) %ptr to ptr
403 %load = load volatile i32, ptr %stof
407 ; GCN-LABEL: {{^}}use_constant32bit_to_flat_addrspacecast_1:
408 ; GCN: s_load_dword [[PTR:s[0-9]+]],
409 ; GCN: v_mov_b32_e32 v[[HI:[0-9]+]], 0xffff8000
410 ; GCN: v_mov_b32_e32 v[[LO:[0-9]+]], [[PTR]]
411 ; GCN: flat_load_dword v{{[0-9]+}}, v[[[LO]]:[[HI]]]
412 define amdgpu_kernel void @use_constant32bit_to_flat_addrspacecast_1(ptr addrspace(6) %ptr) #3 {
413 %stof = addrspacecast ptr addrspace(6) %ptr to ptr
414 %load = load volatile i32, ptr %stof
418 declare void @llvm.amdgcn.s.barrier() #1
419 declare i32 @llvm.amdgcn.workitem.id.x() #2
421 attributes #0 = { nounwind }
422 attributes #1 = { nounwind convergent }
423 attributes #2 = { nounwind readnone }
424 attributes #3 = { nounwind "amdgpu-32bit-address-high-bits"="0xffff8000" }
426 !llvm.module.flags = !{!0}
427 !0 = !{i32 1, !"amdgpu_code_object_version", i32 400}