Revert rGe6ccb57bb3f6b761f2310e97fd6ca99eff42f73e "[SLP] Add cost model for `llvm...
[llvm-project.git] / llvm / test / CodeGen / AMDGPU / shl_add_ptr.ll
blob30cecc085776d8369afeb7e561924e019d2bbc82
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
7 ; LDS globals.
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
21 ; GCN: s_endpgm
22 define amdgpu_kernel void @load_shl_base_lds_0(float addrspace(1)* %out, i32 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], [512 x float] addrspace(3)* @lds0, i32 0, i32 %idx.0
26   %val0 = load float, float addrspace(3)* %arrayidx0, align 4
27   store i32 %idx.0, i32 addrspace(1)* %add_use, align 4
28   store float %val0, float addrspace(1)* %out
29   ret void
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]]
41 ; GCN: s_endpgm
42 define amdgpu_kernel void @load_shl_base_lds_1(float addrspace(1)* %out, i32 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], [512 x float] addrspace(3)* @lds0, i32 0, i32 %idx.0
46   %val0 = load float, float addrspace(3)* %arrayidx0, align 4
47   %shl_add_use = shl i32 %idx.0, 2
48   store i32 %shl_add_use, i32 addrspace(1)* %add_use, align 4
49   store float %val0, float addrspace(1)* %out
50   ret void
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
57 ; GCN: s_endpgm
58 define amdgpu_kernel void @load_shl_base_lds_max_offset(i8 addrspace(1)* %out, i8 addrspace(3)* %lds, i32 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], [65536 x i8] addrspace(3)* @maxlds, i32 0, i32 %idx.0
62   %val0 = load i8, i8 addrspace(3)* %arrayidx0
63   store i32 %idx.0, i32 addrspace(1)* %add_use
64   store i8 %val0, i8 addrspace(1)* %out
65   ret void
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
75 ; GCN: s_endpgm
76 define amdgpu_kernel void @load_shl_base_lds_2(float 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], [512 x float] addrspace(3)* @lds0, i32 0, i32 %idx.0
80   %val0 = load float, float addrspace(3)* %arrayidx0, align 4
81   %arrayidx1 = getelementptr inbounds [512 x float], [512 x float] addrspace(3)* @lds1, i32 0, i32 %idx.0
82   %val1 = load float, float addrspace(3)* %arrayidx1, align 4
83   %sum = fadd float %val0, %val1
84   store float %sum, float addrspace(1)* %out, align 4
85   ret void
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
91 ; GCN: s_endpgm
92 define amdgpu_kernel void @store_shl_base_lds_0(float addrspace(1)* %out, i32 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], [512 x float] addrspace(3)* @lds0, i32 0, i32 %idx.0
96   store float 1.0, float addrspace(3)* %arrayidx0, align 4
97   store i32 %idx.0, i32 addrspace(1)* %add_use, align 4
98   ret void
102 ; --------------------------------------------------------------------------------
103 ; Atomics.
105 @lds2 = addrspace(3) global [512 x i32] undef, align 4
107 ; define amdgpu_kernel void @atomic_load_shl_base_lds_0(i32 addrspace(1)* %out, i32 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], [512 x i32] addrspace(3)* @lds2, i32 0, i32 %idx.0
111 ;   %val = load atomic i32, i32 addrspace(3)* %arrayidx0 seq_cst, align 4
112 ;   store i32 %val, i32 addrspace(1)* %out, align 4
113 ;   store i32 %idx.0, i32 addrspace(1)* %add_use, align 4
114 ;   ret void
115 ; }
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
121 ; GCN: s_endpgm
122 define amdgpu_kernel void @atomic_cmpxchg_shl_base_lds_0(i32 addrspace(1)* %out, i32 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], [512 x i32] addrspace(3)* @lds2, i32 0, i32 %idx.0
126   %pair = cmpxchg i32 addrspace(3)* %arrayidx0, i32 7, i32 %swap seq_cst monotonic
127   %result = extractvalue { i32, i1 } %pair, 0
128   store i32 %result, i32 addrspace(1)* %out, align 4
129   store i32 %idx.0, i32 addrspace(1)* %add_use, align 4
130   ret void
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
136 ; GCN: s_endpgm
137 define amdgpu_kernel void @atomic_swap_shl_base_lds_0(i32 addrspace(1)* %out, i32 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], [512 x i32] addrspace(3)* @lds2, i32 0, i32 %idx.0
141   %val = atomicrmw xchg i32 addrspace(3)* %arrayidx0, i32 3 seq_cst
142   store i32 %val, i32 addrspace(1)* %out, align 4
143   store i32 %idx.0, i32 addrspace(1)* %add_use, align 4
144   ret void
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
150 ; GCN: s_endpgm
151 define amdgpu_kernel void @atomic_add_shl_base_lds_0(i32 addrspace(1)* %out, i32 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], [512 x i32] addrspace(3)* @lds2, i32 0, i32 %idx.0
155   %val = atomicrmw add i32 addrspace(3)* %arrayidx0, i32 3 seq_cst
156   store i32 %val, i32 addrspace(1)* %out, align 4
157   store i32 %idx.0, i32 addrspace(1)* %add_use, align 4
158   ret void
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
164 ; GCN: s_endpgm
165 define amdgpu_kernel void @atomic_sub_shl_base_lds_0(i32 addrspace(1)* %out, i32 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], [512 x i32] addrspace(3)* @lds2, i32 0, i32 %idx.0
169   %val = atomicrmw sub i32 addrspace(3)* %arrayidx0, i32 3 seq_cst
170   store i32 %val, i32 addrspace(1)* %out, align 4
171   store i32 %idx.0, i32 addrspace(1)* %add_use, align 4
172   ret void
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
178 ; GCN: s_endpgm
179 define amdgpu_kernel void @atomic_and_shl_base_lds_0(i32 addrspace(1)* %out, i32 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], [512 x i32] addrspace(3)* @lds2, i32 0, i32 %idx.0
183   %val = atomicrmw and i32 addrspace(3)* %arrayidx0, i32 3 seq_cst
184   store i32 %val, i32 addrspace(1)* %out, align 4
185   store i32 %idx.0, i32 addrspace(1)* %add_use, align 4
186   ret void
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
192 ; GCN: s_endpgm
193 define amdgpu_kernel void @atomic_or_shl_base_lds_0(i32 addrspace(1)* %out, i32 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], [512 x i32] addrspace(3)* @lds2, i32 0, i32 %idx.0
197   %val = atomicrmw or i32 addrspace(3)* %arrayidx0, i32 3 seq_cst
198   store i32 %val, i32 addrspace(1)* %out, align 4
199   store i32 %idx.0, i32 addrspace(1)* %add_use, align 4
200   ret void
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
206 ; GCN: s_endpgm
207 define amdgpu_kernel void @atomic_xor_shl_base_lds_0(i32 addrspace(1)* %out, i32 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], [512 x i32] addrspace(3)* @lds2, i32 0, i32 %idx.0
211   %val = atomicrmw xor i32 addrspace(3)* %arrayidx0, i32 3 seq_cst
212   store i32 %val, i32 addrspace(1)* %out, align 4
213   store i32 %idx.0, i32 addrspace(1)* %add_use, align 4
214   ret void
217 ; define amdgpu_kernel void @atomic_nand_shl_base_lds_0(i32 addrspace(1)* %out, i32 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], [512 x i32] addrspace(3)* @lds2, i32 0, i32 %idx.0
221 ;   %val = atomicrmw nand i32 addrspace(3)* %arrayidx0, i32 3 seq_cst
222 ;   store i32 %val, i32 addrspace(1)* %out, align 4
223 ;   store i32 %idx.0, i32 addrspace(1)* %add_use, align 4
224 ;   ret void
225 ; }
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
230 ; GCN: s_endpgm
231 define amdgpu_kernel void @atomic_min_shl_base_lds_0(i32 addrspace(1)* %out, i32 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], [512 x i32] addrspace(3)* @lds2, i32 0, i32 %idx.0
235   %val = atomicrmw min i32 addrspace(3)* %arrayidx0, i32 3 seq_cst
236   store i32 %val, i32 addrspace(1)* %out, align 4
237   store i32 %idx.0, i32 addrspace(1)* %add_use, align 4
238   ret void
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
244 ; GCN: s_endpgm
245 define amdgpu_kernel void @atomic_max_shl_base_lds_0(i32 addrspace(1)* %out, i32 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], [512 x i32] addrspace(3)* @lds2, i32 0, i32 %idx.0
249   %val = atomicrmw max i32 addrspace(3)* %arrayidx0, i32 3 seq_cst
250   store i32 %val, i32 addrspace(1)* %out, align 4
251   store i32 %idx.0, i32 addrspace(1)* %add_use, align 4
252   ret void
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
258 ; GCN: s_endpgm
259 define amdgpu_kernel void @atomic_umin_shl_base_lds_0(i32 addrspace(1)* %out, i32 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], [512 x i32] addrspace(3)* @lds2, i32 0, i32 %idx.0
263   %val = atomicrmw umin i32 addrspace(3)* %arrayidx0, i32 3 seq_cst
264   store i32 %val, i32 addrspace(1)* %out, align 4
265   store i32 %idx.0, i32 addrspace(1)* %add_use, align 4
266   ret void
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
272 ; GCN: s_endpgm
273 define amdgpu_kernel void @atomic_umax_shl_base_lds_0(i32 addrspace(1)* %out, i32 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], [512 x i32] addrspace(3)* @lds2, i32 0, i32 %idx.0
277   %val = atomicrmw umax i32 addrspace(3)* %arrayidx0, i32 3 seq_cst
278   store i32 %val, i32 addrspace(1)* %out, align 4
279   store i32 %idx.0, i32 addrspace(1)* %add_use, align 4
280   ret void
283 ; GCN-LABEL: {{^}}shl_add_ptr_combine_2use_lds:
284 ; GCN: v_lshlrev_b32_e32 [[SCALE0:v[0-9]+]], 3, v0
285 ; GCN: v_lshlrev_b32_e32 [[SCALE1:v[0-9]+]], 4, v0
286 ; GCN: ds_write_b32 [[SCALE0]], v{{[0-9]+}} offset:32
287 ; GCN: ds_write_b32 [[SCALE1]], v{{[0-9]+}} offset:64
288 define void @shl_add_ptr_combine_2use_lds(i32 %idx) #0 {
289   %idx.add = add nuw i32 %idx, 4
290   %shl0 = shl i32 %idx.add, 3
291   %shl1 = shl i32 %idx.add, 4
292   %ptr0 = inttoptr i32 %shl0 to i32 addrspace(3)*
293   %ptr1 = inttoptr i32 %shl1 to i32 addrspace(3)*
294   store volatile i32 9, i32 addrspace(3)* %ptr0
295   store volatile i32 10, i32 addrspace(3)* %ptr1
296   ret void
299 ; GCN-LABEL: {{^}}shl_add_ptr_combine_2use_max_lds_offset:
300 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE0:v[0-9]+]], 3, v0
301 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE1:v[0-9]+]], 4, v0
302 ; GCN-DAG: ds_write_b32 [[SCALE0]], v{{[0-9]+}} offset:65528
303 ; GCN-DAG: v_add_{{[iu]}}32_e32 [[ADD1:v[0-9]+]], vcc, 0x1fff0, [[SCALE1]]
304 ; GCN: ds_write_b32 [[ADD1]], v{{[0-9]+$}}
305 define void @shl_add_ptr_combine_2use_max_lds_offset(i32 %idx) #0 {
306   %idx.add = add nuw i32 %idx, 8191
307   %shl0 = shl i32 %idx.add, 3
308   %shl1 = shl i32 %idx.add, 4
309   %ptr0 = inttoptr i32 %shl0 to i32 addrspace(3)*
310   %ptr1 = inttoptr i32 %shl1 to i32 addrspace(3)*
311   store volatile i32 9, i32 addrspace(3)* %ptr0
312   store volatile i32 10, i32 addrspace(3)* %ptr1
313   ret void
316 ; GCN-LABEL: {{^}}shl_add_ptr_combine_2use_both_max_lds_offset:
317 ; GCN: v_add_{{[iu]}}32_e32 [[ADD:v[0-9]+]], vcc, 0x1000, v0
318 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE0:v[0-9]+]], 4, [[ADD]]
319 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE1:v[0-9]+]], 5, [[ADD]]
320 ; GCN-DAG: ds_write_b32 [[SCALE0]], v{{[0-9]+$}}
321 ; GCN: ds_write_b32 [[SCALE1]], v{{[0-9]+$}}
322 define void @shl_add_ptr_combine_2use_both_max_lds_offset(i32 %idx) #0 {
323   %idx.add = add nuw i32 %idx, 4096
324   %shl0 = shl i32 %idx.add, 4
325   %shl1 = shl i32 %idx.add, 5
326   %ptr0 = inttoptr i32 %shl0 to i32 addrspace(3)*
327   %ptr1 = inttoptr i32 %shl1 to i32 addrspace(3)*
328   store volatile i32 9, i32 addrspace(3)* %ptr0
329   store volatile i32 10, i32 addrspace(3)* %ptr1
330   ret void
333 ; GCN-LABEL: {{^}}shl_add_ptr_combine_2use_private:
334 ; GCN: v_lshlrev_b32_e32 [[SCALE0:v[0-9]+]], 2, v0
335 ; GCN: v_lshlrev_b32_e32 [[SCALE1:v[0-9]+]], 3, v0
336 ; GCN: buffer_store_dword v{{[0-9]+}}, [[SCALE0]], s[0:3], 0 offen offset:16
337 ; GCN: buffer_store_dword v{{[0-9]+}}, [[SCALE1]], s[0:3], 0 offen offset:32
338 define void @shl_add_ptr_combine_2use_private(i16 zeroext %idx.arg) #0 {
339   %idx = zext i16 %idx.arg to i32
340   %idx.add = add nuw i32 %idx, 4
341   %shl0 = shl i32 %idx.add, 2
342   %shl1 = shl i32 %idx.add, 3
343   %ptr0 = inttoptr i32 %shl0 to i32 addrspace(5)*
344   %ptr1 = inttoptr i32 %shl1 to i32 addrspace(5)*
345   store volatile i32 9, i32 addrspace(5)* %ptr0
346   store volatile i32 10, i32 addrspace(5)* %ptr1
347   ret void
350 ; GCN-LABEL: {{^}}shl_add_ptr_combine_2use_max_private_offset:
351 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE0:v[0-9]+]], 3, v0
352 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE1:v[0-9]+]], 4, v0
353 ; GCN-DAG: buffer_store_dword v{{[0-9]+}}, [[SCALE0]], s[0:3], 0 offen offset:4088
354 ; GCN-DAG: v_add_{{[iu]}}32_e32 [[ADD:v[0-9]+]], vcc, 0x1ff0, [[SCALE1]]
355 ; GCN: buffer_store_dword v{{[0-9]+}}, [[ADD]], s[0:3], 0 offen{{$}}
356 define void @shl_add_ptr_combine_2use_max_private_offset(i16 zeroext %idx.arg) #0 {
357   %idx = zext i16 %idx.arg to i32
358   %idx.add = add nuw i32 %idx, 511
359   %shl0 = shl i32 %idx.add, 3
360   %shl1 = shl i32 %idx.add, 4
361   %ptr0 = inttoptr i32 %shl0 to i32 addrspace(5)*
362   %ptr1 = inttoptr i32 %shl1 to i32 addrspace(5)*
363   store volatile i32 9, i32 addrspace(5)* %ptr0
364   store volatile i32 10, i32 addrspace(5)* %ptr1
365   ret void
367 ; GCN-LABEL: {{^}}shl_add_ptr_combine_2use_both_max_private_offset:
368 ; GCN: v_add_{{[iu]}}32_e32 [[ADD:v[0-9]+]], vcc, 0x100, v0
369 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE0:v[0-9]+]], 4, [[ADD]]
370 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE1:v[0-9]+]], 5, [[ADD]]
371 ; GCN-DAG: buffer_store_dword v{{[0-9]+}}, [[SCALE0]], s[0:3], 0 offen{{$}}
372 ; GCN: buffer_store_dword v{{[0-9]+}}, [[SCALE1]], s[0:3], 0 offen{{$}}
373 define void @shl_add_ptr_combine_2use_both_max_private_offset(i16 zeroext %idx.arg) #0 {
374   %idx = zext i16 %idx.arg to i32
375   %idx.add = add nuw i32 %idx, 256
376   %shl0 = shl i32 %idx.add, 4
377   %shl1 = shl i32 %idx.add, 5
378   %ptr0 = inttoptr i32 %shl0 to i32 addrspace(5)*
379   %ptr1 = inttoptr i32 %shl1 to i32 addrspace(5)*
380   store volatile i32 9, i32 addrspace(5)* %ptr0
381   store volatile i32 10, i32 addrspace(5)* %ptr1
382   ret void
385 ; FIXME: This or should fold into an offset on the write
386 ; GCN-LABEL: {{^}}shl_or_ptr_combine_2use_lds:
387 ; GCN: v_lshlrev_b32_e32 [[SCALE0:v[0-9]+]], 3, v0
388 ; GCN: v_or_b32_e32 [[SCALE1:v[0-9]+]], 32, [[SCALE0]]
389 ; GCN: v_lshlrev_b32_e32 [[SCALE2:v[0-9]+]], 4, v0
390 ; GCN: ds_write_b32 [[SCALE1]], v{{[0-9]+}}
391 ; GCN: ds_write_b32 [[SCALE2]], v{{[0-9]+}} offset:64
392 define void @shl_or_ptr_combine_2use_lds(i32 %idx) #0 {
393   %idx.add = or i32 %idx, 4
394   %shl0 = shl i32 %idx.add, 3
395   %shl1 = shl i32 %idx.add, 4
396   %ptr0 = inttoptr i32 %shl0 to i32 addrspace(3)*
397   %ptr1 = inttoptr i32 %shl1 to i32 addrspace(3)*
398   store volatile i32 9, i32 addrspace(3)* %ptr0
399   store volatile i32 10, i32 addrspace(3)* %ptr1
400   ret void
403 ; GCN-LABEL: {{^}}shl_or_ptr_combine_2use_max_lds_offset:
404 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE0:v[0-9]+]], 3, v0
405 ; GCN-DAG: v_lshlrev_b32_e32 [[SCALE1:v[0-9]+]], 4, v0
406 ; GCN-DAG: ds_write_b32 [[SCALE0]], v{{[0-9]+}} offset:65528
407 ; GCN-DAG: v_or_b32_e32 [[ADD1:v[0-9]+]], 0x1fff0, [[SCALE1]]
408 ; GCN: ds_write_b32 [[ADD1]], v{{[0-9]+$}}
409 define void @shl_or_ptr_combine_2use_max_lds_offset(i32 %idx) #0 {
410   %idx.add = or i32 %idx, 8191
411   %shl0 = shl i32 %idx.add, 3
412   %shl1 = shl i32 %idx.add, 4
413   %ptr0 = inttoptr i32 %shl0 to i32 addrspace(3)*
414   %ptr1 = inttoptr i32 %shl1 to i32 addrspace(3)*
415   store volatile i32 9, i32 addrspace(3)* %ptr0
416   store volatile i32 10, i32 addrspace(3)* %ptr1
417   ret void
420 attributes #0 = { nounwind }
421 attributes #1 = { nounwind readnone }