1 ; RUN: llc -march=amdgcn -mcpu=bonaire -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN %s
2 ; RUN: llc -march=amdgcn -mcpu=tonga -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN %s
4 ; Test that doing a shift of a pointer with a constant add will be
5 ; folded into the constant offset addressing mode even if the add has
6 ; multiple uses. This is relevant to accessing 2 separate, adjacent
10 declare i32 @llvm.amdgcn.workitem.id.x() #1
12 @lds0 = addrspace(3) global [512 x float] undef, align 4
13 @lds1 = addrspace(3) global [512 x float] undef, align 4
16 ; Make sure the (add tid, 2) << 2 gets folded into the ds's offset as (tid << 2) + 8
18 ; GCN-LABEL: {{^}}load_shl_base_lds_0:
19 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
20 ; GCN: ds_read_b32 {{v[0-9]+}}, [[PTR]] offset:8
22 define amdgpu_kernel void @load_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
23 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
24 %idx.0 = add nsw i32 %tid.x, 2
25 %arrayidx0 = getelementptr inbounds [512 x float], ptr addrspace(3) @lds0, i32 0, i32 %idx.0
26 %val0 = load float, ptr addrspace(3) %arrayidx0, align 4
27 store i32 %idx.0, ptr addrspace(1) %add_use, align 4
28 store float %val0, ptr addrspace(1) %out
32 ; Make sure once the first use is folded into the addressing mode, the
33 ; remaining add use goes through the normal shl + add constant fold.
35 ; GCN-LABEL: {{^}}load_shl_base_lds_1:
36 ; GCN: v_lshlrev_b32_e32 [[OFS:v[0-9]+]], 2, {{v[0-9]+}}
37 ; GCN: ds_read_b32 [[RESULT:v[0-9]+]], [[OFS]] offset:8
38 ; GCN: v_add_{{[iu]}}32_e32 [[ADDUSE:v[0-9]+]], vcc, 8, v{{[0-9]+}}
39 ; GCN-DAG: buffer_store_dword [[RESULT]]
40 ; GCN-DAG: buffer_store_dword [[ADDUSE]]
42 define amdgpu_kernel void @load_shl_base_lds_1(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
43 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
44 %idx.0 = add nsw i32 %tid.x, 2
45 %arrayidx0 = getelementptr inbounds [512 x float], ptr addrspace(3) @lds0, i32 0, i32 %idx.0
46 %val0 = load float, ptr addrspace(3) %arrayidx0, align 4
47 %shl_add_use = shl i32 %idx.0, 2
48 store i32 %shl_add_use, ptr addrspace(1) %add_use, align 4
49 store float %val0, ptr addrspace(1) %out
53 @maxlds = addrspace(3) global [65536 x i8] undef, align 4
55 ; GCN-LABEL: {{^}}load_shl_base_lds_max_offset
56 ; GCN: ds_read_u8 v{{[0-9]+}}, v{{[0-9]+}} offset:65535
58 define amdgpu_kernel void @load_shl_base_lds_max_offset(ptr addrspace(1) %out, ptr addrspace(3) %lds, ptr addrspace(1) %add_use) #0 {
59 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
60 %idx.0 = add nsw i32 %tid.x, 65535
61 %arrayidx0 = getelementptr inbounds [65536 x i8], ptr addrspace(3) @maxlds, i32 0, i32 %idx.0
62 %val0 = load i8, ptr addrspace(3) %arrayidx0
63 store i32 %idx.0, ptr addrspace(1) %add_use
64 store i8 %val0, ptr addrspace(1) %out
68 ; The two globals are placed adjacent in memory, so the same base
69 ; pointer can be used with an offset into the second one.
71 ; GCN-LABEL: {{^}}load_shl_base_lds_2:
72 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
73 ; GCN: s_mov_b32 m0, -1
74 ; GCN: ds_read2st64_b32 {{v\[[0-9]+:[0-9]+\]}}, [[PTR]] offset0:1 offset1:9
76 define amdgpu_kernel void @load_shl_base_lds_2(ptr addrspace(1) %out) #0 {
77 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
78 %idx.0 = add nsw i32 %tid.x, 64
79 %arrayidx0 = getelementptr inbounds [512 x float], ptr addrspace(3) @lds0, i32 0, i32 %idx.0
80 %val0 = load float, ptr addrspace(3) %arrayidx0, align 4
81 %arrayidx1 = getelementptr inbounds [512 x float], ptr addrspace(3) @lds1, i32 0, i32 %idx.0
82 %val1 = load float, ptr addrspace(3) %arrayidx1, align 4
83 %sum = fadd float %val0, %val1
84 store float %sum, ptr addrspace(1) %out, align 4
88 ; GCN-LABEL: {{^}}store_shl_base_lds_0:
89 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
90 ; GCN: ds_write_b32 [[PTR]], {{v[0-9]+}} offset:8
92 define amdgpu_kernel void @store_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
93 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
94 %idx.0 = add nsw i32 %tid.x, 2
95 %arrayidx0 = getelementptr inbounds [512 x float], ptr addrspace(3) @lds0, i32 0, i32 %idx.0
96 store float 1.0, ptr addrspace(3) %arrayidx0, align 4
97 store i32 %idx.0, ptr addrspace(1) %add_use, align 4
102 ; --------------------------------------------------------------------------------
105 @lds2 = addrspace(3) global [512 x i32] undef, align 4
107 ; define amdgpu_kernel void @atomic_load_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
108 ; %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
109 ; %idx.0 = add nsw i32 %tid.x, 2
110 ; %arrayidx0 = getelementptr inbounds [512 x i32], ptr addrspace(3) @lds2, i32 0, i32 %idx.0
111 ; %val = load atomic i32, ptr addrspace(3) %arrayidx0 seq_cst, align 4
112 ; store i32 %val, ptr addrspace(1) %out, align 4
113 ; store i32 %idx.0, ptr addrspace(1) %add_use, align 4
118 ; GCN-LABEL: {{^}}atomic_cmpxchg_shl_base_lds_0:
119 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
120 ; GCN: ds_cmpst_rtn_b32 {{v[0-9]+}}, [[PTR]], {{v[0-9]+}}, {{v[0-9]+}} offset:8
122 define amdgpu_kernel void @atomic_cmpxchg_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use, i32 %swap) #0 {
123 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
124 %idx.0 = add nsw i32 %tid.x, 2
125 %arrayidx0 = getelementptr inbounds [512 x i32], ptr addrspace(3) @lds2, i32 0, i32 %idx.0
126 %pair = cmpxchg ptr addrspace(3) %arrayidx0, i32 7, i32 %swap seq_cst monotonic
127 %result = extractvalue { i32, i1 } %pair, 0
128 store i32 %result, ptr addrspace(1) %out, align 4
129 store i32 %idx.0, ptr addrspace(1) %add_use, align 4
133 ; GCN-LABEL: {{^}}atomic_swap_shl_base_lds_0:
134 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
135 ; GCN: ds_wrxchg_rtn_b32 {{v[0-9]+}}, [[PTR]], {{v[0-9]+}} offset:8
137 define amdgpu_kernel void @atomic_swap_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
138 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
139 %idx.0 = add nsw i32 %tid.x, 2
140 %arrayidx0 = getelementptr inbounds [512 x i32], ptr addrspace(3) @lds2, i32 0, i32 %idx.0
141 %val = atomicrmw xchg ptr addrspace(3) %arrayidx0, i32 3 seq_cst
142 store i32 %val, ptr addrspace(1) %out, align 4
143 store i32 %idx.0, ptr addrspace(1) %add_use, align 4
147 ; GCN-LABEL: {{^}}atomic_add_shl_base_lds_0:
148 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
149 ; GCN: ds_add_rtn_u32 {{v[0-9]+}}, [[PTR]], {{v[0-9]+}} offset:8
151 define amdgpu_kernel void @atomic_add_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
152 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
153 %idx.0 = add nsw i32 %tid.x, 2
154 %arrayidx0 = getelementptr inbounds [512 x i32], ptr addrspace(3) @lds2, i32 0, i32 %idx.0
155 %val = atomicrmw add ptr addrspace(3) %arrayidx0, i32 3 seq_cst
156 store i32 %val, ptr addrspace(1) %out, align 4
157 store i32 %idx.0, ptr addrspace(1) %add_use, align 4
161 ; GCN-LABEL: {{^}}atomic_sub_shl_base_lds_0:
162 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
163 ; GCN: ds_sub_rtn_u32 {{v[0-9]+}}, [[PTR]], {{v[0-9]+}} offset:8
165 define amdgpu_kernel void @atomic_sub_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
166 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
167 %idx.0 = add nsw i32 %tid.x, 2
168 %arrayidx0 = getelementptr inbounds [512 x i32], ptr addrspace(3) @lds2, i32 0, i32 %idx.0
169 %val = atomicrmw sub ptr addrspace(3) %arrayidx0, i32 3 seq_cst
170 store i32 %val, ptr addrspace(1) %out, align 4
171 store i32 %idx.0, ptr addrspace(1) %add_use, align 4
175 ; GCN-LABEL: {{^}}atomic_and_shl_base_lds_0:
176 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
177 ; GCN: ds_and_rtn_b32 {{v[0-9]+}}, [[PTR]], {{v[0-9]+}} offset:8
179 define amdgpu_kernel void @atomic_and_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
180 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
181 %idx.0 = add nsw i32 %tid.x, 2
182 %arrayidx0 = getelementptr inbounds [512 x i32], ptr addrspace(3) @lds2, i32 0, i32 %idx.0
183 %val = atomicrmw and ptr addrspace(3) %arrayidx0, i32 3 seq_cst
184 store i32 %val, ptr addrspace(1) %out, align 4
185 store i32 %idx.0, ptr addrspace(1) %add_use, align 4
189 ; GCN-LABEL: {{^}}atomic_or_shl_base_lds_0:
190 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
191 ; GCN: ds_or_rtn_b32 {{v[0-9]+}}, [[PTR]], {{v[0-9]+}} offset:8
193 define amdgpu_kernel void @atomic_or_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
194 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
195 %idx.0 = add nsw i32 %tid.x, 2
196 %arrayidx0 = getelementptr inbounds [512 x i32], ptr addrspace(3) @lds2, i32 0, i32 %idx.0
197 %val = atomicrmw or ptr addrspace(3) %arrayidx0, i32 3 seq_cst
198 store i32 %val, ptr addrspace(1) %out, align 4
199 store i32 %idx.0, ptr addrspace(1) %add_use, align 4
203 ; GCN-LABEL: {{^}}atomic_xor_shl_base_lds_0:
204 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
205 ; GCN: ds_xor_rtn_b32 {{v[0-9]+}}, [[PTR]], {{v[0-9]+}} offset:8
207 define amdgpu_kernel void @atomic_xor_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
208 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
209 %idx.0 = add nsw i32 %tid.x, 2
210 %arrayidx0 = getelementptr inbounds [512 x i32], ptr addrspace(3) @lds2, i32 0, i32 %idx.0
211 %val = atomicrmw xor ptr addrspace(3) %arrayidx0, i32 3 seq_cst
212 store i32 %val, ptr addrspace(1) %out, align 4
213 store i32 %idx.0, ptr addrspace(1) %add_use, align 4
217 ; define amdgpu_kernel void @atomic_nand_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
218 ; %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
219 ; %idx.0 = add nsw i32 %tid.x, 2
220 ; %arrayidx0 = getelementptr inbounds [512 x i32], ptr addrspace(3) @lds2, i32 0, i32 %idx.0
221 ; %val = atomicrmw nand ptr addrspace(3) %arrayidx0, i32 3 seq_cst
222 ; store i32 %val, ptr addrspace(1) %out, align 4
223 ; store i32 %idx.0, ptr addrspace(1) %add_use, align 4
227 ; GCN-LABEL: {{^}}atomic_min_shl_base_lds_0:
228 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
229 ; GCN: ds_min_rtn_i32 {{v[0-9]+}}, [[PTR]], {{v[0-9]+}} offset:8
231 define amdgpu_kernel void @atomic_min_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
232 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
233 %idx.0 = add nsw i32 %tid.x, 2
234 %arrayidx0 = getelementptr inbounds [512 x i32], ptr addrspace(3) @lds2, i32 0, i32 %idx.0
235 %val = atomicrmw min ptr addrspace(3) %arrayidx0, i32 3 seq_cst
236 store i32 %val, ptr addrspace(1) %out, align 4
237 store i32 %idx.0, ptr addrspace(1) %add_use, align 4
241 ; GCN-LABEL: {{^}}atomic_max_shl_base_lds_0:
242 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
243 ; GCN: ds_max_rtn_i32 {{v[0-9]+}}, [[PTR]], {{v[0-9]+}} offset:8
245 define amdgpu_kernel void @atomic_max_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
246 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
247 %idx.0 = add nsw i32 %tid.x, 2
248 %arrayidx0 = getelementptr inbounds [512 x i32], ptr addrspace(3) @lds2, i32 0, i32 %idx.0
249 %val = atomicrmw max ptr addrspace(3) %arrayidx0, i32 3 seq_cst
250 store i32 %val, ptr addrspace(1) %out, align 4
251 store i32 %idx.0, ptr addrspace(1) %add_use, align 4
255 ; GCN-LABEL: {{^}}atomic_umin_shl_base_lds_0:
256 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
257 ; GCN: ds_min_rtn_u32 {{v[0-9]+}}, [[PTR]], {{v[0-9]+}} offset:8
259 define amdgpu_kernel void @atomic_umin_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
260 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
261 %idx.0 = add nsw i32 %tid.x, 2
262 %arrayidx0 = getelementptr inbounds [512 x i32], ptr addrspace(3) @lds2, i32 0, i32 %idx.0
263 %val = atomicrmw umin ptr addrspace(3) %arrayidx0, i32 3 seq_cst
264 store i32 %val, ptr addrspace(1) %out, align 4
265 store i32 %idx.0, ptr addrspace(1) %add_use, align 4
269 ; GCN-LABEL: {{^}}atomic_umax_shl_base_lds_0:
270 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
271 ; GCN: ds_max_rtn_u32 {{v[0-9]+}}, [[PTR]], {{v[0-9]+}} offset:8
273 define amdgpu_kernel void @atomic_umax_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
274 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
275 %idx.0 = add nsw i32 %tid.x, 2
276 %arrayidx0 = getelementptr inbounds [512 x i32], ptr addrspace(3) @lds2, i32 0, i32 %idx.0
277 %val = atomicrmw umax ptr addrspace(3) %arrayidx0, i32 3 seq_cst
278 store i32 %val, ptr addrspace(1) %out, align 4
279 store i32 %idx.0, ptr addrspace(1) %add_use, align 4
283 ; GCN-LABEL: {{^}}atomic_inc_shl_base_lds_0:
284 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
285 ; GCN: ds_inc_rtn_u32 {{v[0-9]+}}, [[PTR]], {{v[0-9]+}} offset:8
287 define amdgpu_kernel void @atomic_inc_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
288 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
289 %idx.0 = add nsw i32 %tid.x, 2
290 %arrayidx0 = getelementptr inbounds [512 x i32], ptr addrspace(3) @lds2, i32 0, i32 %idx.0
291 %val = atomicrmw uinc_wrap ptr addrspace(3) %arrayidx0, i32 31 seq_cst
292 store i32 %val, ptr addrspace(1) %out, align 4
293 store i32 %idx.0, ptr addrspace(1) %add_use, align 4
297 ; GCN-LABEL: {{^}}atomic_dec_shl_base_lds_0:
298 ; GCN: v_lshlrev_b32_e32 [[PTR:v[0-9]+]], 2, {{v[0-9]+}}
299 ; GCN: ds_dec_rtn_u32 {{v[0-9]+}}, [[PTR]], {{v[0-9]+}} offset:8
301 define amdgpu_kernel void @atomic_dec_shl_base_lds_0(ptr addrspace(1) %out, ptr addrspace(1) %add_use) #0 {
302 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
303 %idx.0 = add nsw i32 %tid.x, 2
304 %arrayidx0 = getelementptr inbounds [512 x i32], ptr addrspace(3) @lds2, i32 0, i32 %idx.0
305 %val = atomicrmw udec_wrap ptr addrspace(3) %arrayidx0, i32 31 seq_cst
306 store i32 %val, ptr addrspace(1) %out, align 4
307 store i32 %idx.0, ptr addrspace(1) %add_use, align 4
311 ; GCN-LABEL: {{^}}shl_add_ptr_combine_2use_lds:
312 ; GCN: v_lshlrev_b32_e32 [[SCALE0:v[0-9]+]], 3, v0
313 ; GCN: v_lshlrev_b32_e32 [[SCALE1:v[0-9]+]], 4, v0
314 ; GCN: ds_write_b32 [[SCALE0]], v{{[0-9]+}} offset:32
315 ; GCN: ds_write_b32 [[SCALE1]], v{{[0-9]+}} offset:64
316 define void @shl_add_ptr_combine_2use_lds(i32 %idx) #0 {
317 %idx.add = add nuw i32 %idx, 4
318 %shl0 = shl i32 %idx.add, 3
319 %shl1 = shl i32 %idx.add, 4
320 %ptr0 = inttoptr i32 %shl0 to ptr addrspace(3)
321 %ptr1 = inttoptr i32 %shl1 to ptr addrspace(3)
322 store volatile i32 9, ptr addrspace(3) %ptr0
323 store volatile i32 10, ptr addrspace(3) %ptr1
327 ; GCN-LABEL: {{^}}shl_add_ptr_combine_2use_max_lds_offset:
328 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE0:v[0-9]+]], 3, v0
329 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE1:v[0-9]+]], 4, v0
330 ; GCN-DAG: ds_write_b32 [[SCALE0]], v{{[0-9]+}} offset:65528
331 ; GCN-DAG: v_add_{{[iu]}}32_e32 [[ADD1:v[0-9]+]], vcc, 0x1fff0, [[SCALE1]]
332 ; GCN: ds_write_b32 [[ADD1]], v{{[0-9]+$}}
333 define void @shl_add_ptr_combine_2use_max_lds_offset(i32 %idx) #0 {
334 %idx.add = add nuw i32 %idx, 8191
335 %shl0 = shl i32 %idx.add, 3
336 %shl1 = shl i32 %idx.add, 4
337 %ptr0 = inttoptr i32 %shl0 to ptr addrspace(3)
338 %ptr1 = inttoptr i32 %shl1 to ptr addrspace(3)
339 store volatile i32 9, ptr addrspace(3) %ptr0
340 store volatile i32 10, ptr addrspace(3) %ptr1
344 ; GCN-LABEL: {{^}}shl_add_ptr_combine_2use_both_max_lds_offset:
345 ; GCN: v_add_{{[iu]}}32_e32 [[ADD:v[0-9]+]], vcc, 0x1000, v0
346 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE0:v[0-9]+]], 4, [[ADD]]
347 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE1:v[0-9]+]], 5, [[ADD]]
348 ; GCN-DAG: ds_write_b32 [[SCALE0]], v{{[0-9]+$}}
349 ; GCN: ds_write_b32 [[SCALE1]], v{{[0-9]+$}}
350 define void @shl_add_ptr_combine_2use_both_max_lds_offset(i32 %idx) #0 {
351 %idx.add = add nuw i32 %idx, 4096
352 %shl0 = shl i32 %idx.add, 4
353 %shl1 = shl i32 %idx.add, 5
354 %ptr0 = inttoptr i32 %shl0 to ptr addrspace(3)
355 %ptr1 = inttoptr i32 %shl1 to ptr addrspace(3)
356 store volatile i32 9, ptr addrspace(3) %ptr0
357 store volatile i32 10, ptr addrspace(3) %ptr1
361 ; GCN-LABEL: {{^}}shl_add_ptr_combine_2use_private:
362 ; GCN: v_lshlrev_b32_e32 [[SCALE0:v[0-9]+]], 2, v0
363 ; GCN: v_lshlrev_b32_e32 [[SCALE1:v[0-9]+]], 3, v0
364 ; GCN: buffer_store_dword v{{[0-9]+}}, [[SCALE0]], s[0:3], 0 offen offset:16
365 ; GCN: buffer_store_dword v{{[0-9]+}}, [[SCALE1]], s[0:3], 0 offen offset:32
366 define void @shl_add_ptr_combine_2use_private(i16 zeroext %idx.arg) #0 {
367 %idx = zext i16 %idx.arg to i32
368 %idx.add = add nuw i32 %idx, 4
369 %shl0 = shl i32 %idx.add, 2
370 %shl1 = shl i32 %idx.add, 3
371 %ptr0 = inttoptr i32 %shl0 to ptr addrspace(5)
372 %ptr1 = inttoptr i32 %shl1 to ptr addrspace(5)
373 store volatile i32 9, ptr addrspace(5) %ptr0
374 store volatile i32 10, ptr addrspace(5) %ptr1
378 ; GCN-LABEL: {{^}}shl_add_ptr_combine_2use_max_private_offset:
379 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE0:v[0-9]+]], 3, v0
380 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE1:v[0-9]+]], 4, v0
381 ; GCN-DAG: buffer_store_dword v{{[0-9]+}}, [[SCALE0]], s[0:3], 0 offen offset:4088
382 ; GCN-DAG: v_add_{{[iu]}}32_e32 [[ADD:v[0-9]+]], vcc, 0x1ff0, [[SCALE1]]
383 ; GCN: buffer_store_dword v{{[0-9]+}}, [[ADD]], s[0:3], 0 offen{{$}}
384 define void @shl_add_ptr_combine_2use_max_private_offset(i16 zeroext %idx.arg) #0 {
385 %idx = zext i16 %idx.arg to i32
386 %idx.add = add nuw i32 %idx, 511
387 %shl0 = shl i32 %idx.add, 3
388 %shl1 = shl i32 %idx.add, 4
389 %ptr0 = inttoptr i32 %shl0 to ptr addrspace(5)
390 %ptr1 = inttoptr i32 %shl1 to ptr addrspace(5)
391 store volatile i32 9, ptr addrspace(5) %ptr0
392 store volatile i32 10, ptr addrspace(5) %ptr1
395 ; GCN-LABEL: {{^}}shl_add_ptr_combine_2use_both_max_private_offset:
396 ; GCN: v_add_{{[iu]}}32_e32 [[ADD:v[0-9]+]], vcc, 0x100, v0
397 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE0:v[0-9]+]], 4, [[ADD]]
398 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE1:v[0-9]+]], 5, [[ADD]]
399 ; GCN-DAG: buffer_store_dword v{{[0-9]+}}, [[SCALE0]], s[0:3], 0 offen{{$}}
400 ; GCN: buffer_store_dword v{{[0-9]+}}, [[SCALE1]], s[0:3], 0 offen{{$}}
401 define void @shl_add_ptr_combine_2use_both_max_private_offset(i16 zeroext %idx.arg) #0 {
402 %idx = zext i16 %idx.arg to i32
403 %idx.add = add nuw i32 %idx, 256
404 %shl0 = shl i32 %idx.add, 4
405 %shl1 = shl i32 %idx.add, 5
406 %ptr0 = inttoptr i32 %shl0 to ptr addrspace(5)
407 %ptr1 = inttoptr i32 %shl1 to ptr addrspace(5)
408 store volatile i32 9, ptr addrspace(5) %ptr0
409 store volatile i32 10, ptr addrspace(5) %ptr1
413 ; GCN-LABEL: {{^}}shl_or_ptr_combine_2use_lds:
414 ; GCN-DAG: ds_write_b32 v{{[0-9]+}}, v{{[0-9]+}} offset:8
415 ; GCN-DAG: ds_write_b32 v{{[0-9]+}}, v{{[0-9]+}} offset:16
416 define void @shl_or_ptr_combine_2use_lds(i32 %idx) #0 {
417 %idx.shl = shl i32 %idx, 1
418 %idx.add = or i32 %idx.shl, 1
419 %shl0 = shl i32 %idx.add, 3
420 %shl1 = shl i32 %idx.add, 4
421 %ptr0 = inttoptr i32 %shl0 to ptr addrspace(3)
422 %ptr1 = inttoptr i32 %shl1 to ptr addrspace(3)
423 store volatile i32 9, ptr addrspace(3) %ptr0
424 store volatile i32 10, ptr addrspace(3) %ptr1
427 ; GCN-LABEL: {{^}}shl_or_ptr_not_combine_2use_lds:
428 ; GCN: v_or_b32_e32 [[OR:v[0-9]+]], 1, v0
429 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE0:v[0-9]+]], 3, [[OR]]
430 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE1:v[0-9]+]], 4, [[OR]]
431 ; GCN-DAG: ds_write_b32 [[SCALE0]], v{{[0-9]+}}{{$}}
432 ; GCN-DAG: ds_write_b32 [[SCALE1]], v{{[0-9]+}}{{$}}
433 define void @shl_or_ptr_not_combine_2use_lds(i32 %idx) #0 {
434 %idx.add = or i32 %idx, 1
435 %shl0 = shl i32 %idx.add, 3
436 %shl1 = shl i32 %idx.add, 4
437 %ptr0 = inttoptr i32 %shl0 to ptr addrspace(3)
438 %ptr1 = inttoptr i32 %shl1 to ptr addrspace(3)
439 store volatile i32 9, ptr addrspace(3) %ptr0
440 store volatile i32 10, ptr addrspace(3) %ptr1
444 attributes #0 = { nounwind }
445 attributes #1 = { nounwind readnone }