1 ; RUN: llc -march=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=SI %s
2 ; RUN: llc -march=amdgcn -mcpu=bonaire -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=CI %s
4 declare i32 @llvm.r600.read.tidig.x() #0
5 declare i32 @llvm.r600.read.tidig.y() #0
7 ; In this test both the pointer and the offset operands to the
8 ; BUFFER_LOAD instructions end up being stored in vgprs. This
9 ; requires us to add the pointer and offset together, store the
10 ; result in the offset operand (vaddr), and then store 0 in an
11 ; sgpr register pair and use that for the pointer operand
12 ; (low 64-bits of srsrc).
14 ; GCN-LABEL: {{^}}mubuf:
16 ; Make sure we aren't using VGPRs for the source operand of s_mov_b64
17 ; GCN-NOT: s_mov_b64 s[{{[0-9]+:[0-9]+}}], v
19 ; Make sure we aren't using VGPR's for the srsrc operand of BUFFER_LOAD_*
21 ; GCN: buffer_load_ubyte v{{[0-9]+}}, v[{{[0-9]+:[0-9]+}}], s[{{[0-9]+:[0-9]+}}], 0 addr64
22 ; GCN: buffer_load_ubyte v{{[0-9]+}}, v[{{[0-9]+:[0-9]+}}], s[{{[0-9]+:[0-9]+}}], 0 addr64
24 define void @mubuf(i32 addrspace(1)* %out, i8 addrspace(1)* %in) #1 {
26 %tmp = call i32 @llvm.r600.read.tidig.x()
27 %tmp1 = call i32 @llvm.r600.read.tidig.y()
28 %tmp2 = sext i32 %tmp to i64
29 %tmp3 = sext i32 %tmp1 to i64
32 loop: ; preds = %loop, %entry
33 %tmp4 = phi i64 [ 0, %entry ], [ %tmp5, %loop ]
34 %tmp5 = add i64 %tmp2, %tmp4
35 %tmp6 = getelementptr i8, i8 addrspace(1)* %in, i64 %tmp5
36 %tmp7 = load i8, i8 addrspace(1)* %tmp6, align 1
37 %tmp8 = or i64 %tmp5, 1
38 %tmp9 = getelementptr i8, i8 addrspace(1)* %in, i64 %tmp8
39 %tmp10 = load i8, i8 addrspace(1)* %tmp9, align 1
40 %tmp11 = add i8 %tmp7, %tmp10
41 %tmp12 = sext i8 %tmp11 to i32
42 store i32 %tmp12, i32 addrspace(1)* %out
43 %tmp13 = icmp slt i64 %tmp5, 10
44 br i1 %tmp13, label %loop, label %done
50 ; Test moving an SMRD instruction to the VALU
52 ; GCN-LABEL: {{^}}smrd_valu:
53 ; GCN: buffer_load_dword [[OUT:v[0-9]+]]
54 ; GCN: buffer_store_dword [[OUT]]
55 define void @smrd_valu(i32 addrspace(2)* addrspace(1)* %in, i32 %a, i32 %b, i32 addrspace(1)* %out) #1 {
57 %tmp = icmp ne i32 %a, 0
58 br i1 %tmp, label %if, label %else
61 %tmp1 = load i32 addrspace(2)*, i32 addrspace(2)* addrspace(1)* %in
64 else: ; preds = %entry
65 %tmp2 = getelementptr i32 addrspace(2)*, i32 addrspace(2)* addrspace(1)* %in
66 %tmp3 = load i32 addrspace(2)*, i32 addrspace(2)* addrspace(1)* %tmp2
69 endif: ; preds = %else, %if
70 %tmp4 = phi i32 addrspace(2)* [ %tmp1, %if ], [ %tmp3, %else ]
71 %tmp5 = getelementptr i32, i32 addrspace(2)* %tmp4, i32 3000
72 %tmp6 = load i32, i32 addrspace(2)* %tmp5
73 store i32 %tmp6, i32 addrspace(1)* %out
77 ; Test moving an SMRD with an immediate offset to the VALU
79 ; GCN-LABEL: {{^}}smrd_valu2:
80 ; GCN: buffer_load_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:16{{$}}
81 define void @smrd_valu2(i32 addrspace(1)* %out, [8 x i32] addrspace(2)* %in) #1 {
83 %tmp = call i32 @llvm.r600.read.tidig.x() #0
84 %tmp1 = add i32 %tmp, 4
85 %tmp2 = getelementptr [8 x i32], [8 x i32] addrspace(2)* %in, i32 %tmp, i32 4
86 %tmp3 = load i32, i32 addrspace(2)* %tmp2
87 store i32 %tmp3, i32 addrspace(1)* %out
91 ; Use a big offset that will use the SMRD literal offset on CI
92 ; GCN-LABEL: {{^}}smrd_valu_ci_offset:
93 ; GCN: s_movk_i32 s[[OFFSET:[0-9]+]], 0x4e20{{$}}
94 ; GCN: buffer_load_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[}}[[OFFSET]]:{{[0-9]+}}], 0 addr64{{$}}
96 ; GCN: buffer_store_dword
97 define void @smrd_valu_ci_offset(i32 addrspace(1)* %out, i32 addrspace(2)* %in, i32 %c) #1 {
99 %tmp = call i32 @llvm.r600.read.tidig.x() #0
100 %tmp2 = getelementptr i32, i32 addrspace(2)* %in, i32 %tmp
101 %tmp3 = getelementptr i32, i32 addrspace(2)* %tmp2, i32 5000
102 %tmp4 = load i32, i32 addrspace(2)* %tmp3
103 %tmp5 = add i32 %tmp4, %c
104 store i32 %tmp5, i32 addrspace(1)* %out
108 ; GCN-LABEL: {{^}}smrd_valu_ci_offset_x2:
109 ; GCN: s_mov_b32 s[[OFFSET:[0-9]+]], 0x9c40{{$}}
110 ; GCN: buffer_load_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[}}[[OFFSET]]:{{[0-9]+}}], 0 addr64{{$}}
111 ; GCN: v_or_b32_e32 {{v[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}
112 ; GCN: v_or_b32_e32 {{v[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}
113 ; GCN: buffer_store_dwordx2
114 define void @smrd_valu_ci_offset_x2(i64 addrspace(1)* %out, i64 addrspace(2)* %in, i64 %c) #1 {
116 %tmp = call i32 @llvm.r600.read.tidig.x() #0
117 %tmp2 = getelementptr i64, i64 addrspace(2)* %in, i32 %tmp
118 %tmp3 = getelementptr i64, i64 addrspace(2)* %tmp2, i32 5000
119 %tmp4 = load i64, i64 addrspace(2)* %tmp3
120 %tmp5 = or i64 %tmp4, %c
121 store i64 %tmp5, i64 addrspace(1)* %out
125 ; GCN-LABEL: {{^}}smrd_valu_ci_offset_x4:
126 ; GCN: s_movk_i32 s[[OFFSET:[0-9]+]], 0x4d20{{$}}
127 ; GCN: buffer_load_dwordx4 v{{\[[0-9]+:[0-9]+\]}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[}}[[OFFSET]]:{{[0-9]+}}], 0 addr64{{$}}
128 ; GCN: v_or_b32_e32 {{v[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}
129 ; GCN: v_or_b32_e32 {{v[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}
130 ; GCN: v_or_b32_e32 {{v[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}
131 ; GCN: v_or_b32_e32 {{v[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}
132 ; GCN: buffer_store_dwordx4
133 define void @smrd_valu_ci_offset_x4(<4 x i32> addrspace(1)* %out, <4 x i32> addrspace(2)* %in, <4 x i32> %c) #1 {
135 %tmp = call i32 @llvm.r600.read.tidig.x() #0
136 %tmp2 = getelementptr <4 x i32>, <4 x i32> addrspace(2)* %in, i32 %tmp
137 %tmp3 = getelementptr <4 x i32>, <4 x i32> addrspace(2)* %tmp2, i32 1234
138 %tmp4 = load <4 x i32>, <4 x i32> addrspace(2)* %tmp3
139 %tmp5 = or <4 x i32> %tmp4, %c
140 store <4 x i32> %tmp5, <4 x i32> addrspace(1)* %out
144 ; Original scalar load uses SGPR offset on SI and 32-bit literal on
147 ; GCN-LABEL: {{^}}smrd_valu_ci_offset_x8:
148 ; GCN: s_mov_b32 s[[OFFSET0:[0-9]+]], 0x9a40{{$}}
149 ; GCN: buffer_load_dwordx4 v{{\[[0-9]+:[0-9]+\]}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[}}[[OFFSET0]]:{{[0-9]+}}], 0 addr64{{$}}
151 ; SI: s_add_i32 s[[OFFSET1:[0-9]+]], s[[OFFSET0]], 16
152 ; SI: buffer_load_dwordx4 v{{\[[0-9]+:[0-9]+\]}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[}}[[OFFSET1]]:{{[0-9]+}}], 0 addr64{{$}}
154 ; CI: s_mov_b32 s[[OFFSET1:[0-9]+]], 0x9a50{{$}}
155 ; CI: buffer_load_dwordx4 v{{\[[0-9]+:[0-9]+\]}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[}}[[OFFSET1]]:{{[0-9]+}}], 0 addr64{{$}}
157 ; GCN: v_or_b32_e32 {{v[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}
158 ; GCN: v_or_b32_e32 {{v[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}
159 ; GCN: v_or_b32_e32 {{v[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}
160 ; GCN: v_or_b32_e32 {{v[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}
161 ; GCN: v_or_b32_e32 {{v[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}
162 ; GCN: v_or_b32_e32 {{v[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}
163 ; GCN: v_or_b32_e32 {{v[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}
164 ; GCN: v_or_b32_e32 {{v[0-9]+}}, {{s[0-9]+}}, {{v[0-9]+}}
165 ; GCN: buffer_store_dword
166 ; GCN: buffer_store_dword
167 ; GCN: buffer_store_dword
168 ; GCN: buffer_store_dword
169 ; GCN: buffer_store_dword
170 ; GCN: buffer_store_dword
171 ; GCN: buffer_store_dword
172 ; GCN: buffer_store_dword
173 define void @smrd_valu_ci_offset_x8(<8 x i32> addrspace(1)* %out, <8 x i32> addrspace(2)* %in, <8 x i32> %c) #1 {
175 %tmp = call i32 @llvm.r600.read.tidig.x() #0
176 %tmp2 = getelementptr <8 x i32>, <8 x i32> addrspace(2)* %in, i32 %tmp
177 %tmp3 = getelementptr <8 x i32>, <8 x i32> addrspace(2)* %tmp2, i32 1234
178 %tmp4 = load <8 x i32>, <8 x i32> addrspace(2)* %tmp3
179 %tmp5 = or <8 x i32> %tmp4, %c
180 store <8 x i32> %tmp5, <8 x i32> addrspace(1)* %out
184 ; GCN-LABEL: {{^}}smrd_valu2_salu_user:
185 ; GCN: buffer_load_dword [[MOVED:v[0-9]+]], v{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:16{{$}}
186 ; GCN: v_add_i32_e32 [[ADD:v[0-9]+]], vcc, s{{[0-9]+}}, [[MOVED]]
187 ; GCN: buffer_store_dword [[ADD]]
188 define void @smrd_valu2_salu_user(i32 addrspace(1)* %out, [8 x i32] addrspace(2)* %in, i32 %a) #1 {
190 %tmp = call i32 @llvm.r600.read.tidig.x() #0
191 %tmp1 = add i32 %tmp, 4
192 %tmp2 = getelementptr [8 x i32], [8 x i32] addrspace(2)* %in, i32 %tmp, i32 4
193 %tmp3 = load i32, i32 addrspace(2)* %tmp2
194 %tmp4 = add i32 %tmp3, %a
195 store i32 %tmp4, i32 addrspace(1)* %out
199 ; GCN-LABEL: {{^}}smrd_valu2_max_smrd_offset:
200 ; GCN: buffer_load_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:1020{{$}}
201 define void @smrd_valu2_max_smrd_offset(i32 addrspace(1)* %out, [1024 x i32] addrspace(2)* %in) #1 {
203 %tmp = call i32 @llvm.r600.read.tidig.x() #0
204 %tmp1 = add i32 %tmp, 4
205 %tmp2 = getelementptr [1024 x i32], [1024 x i32] addrspace(2)* %in, i32 %tmp, i32 255
206 %tmp3 = load i32, i32 addrspace(2)* %tmp2
207 store i32 %tmp3, i32 addrspace(1)* %out
211 ; Offset is too big to fit in SMRD 8-bit offset, but small enough to
212 ; fit in MUBUF offset.
213 ; FIXME: We should be using the offset but we don't
215 ; GCN-LABEL: {{^}}smrd_valu2_mubuf_offset:
216 ; SI: s_movk_i32 s[[OFFSET:[0-9]+]], 0x400{{$}}
217 ; SI: buffer_load_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[}}[[OFFSET]]:{{[0-9]+\]}}, 0 addr64{{$}}
219 ; CI: buffer_load_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:1024{{$}}
220 define void @smrd_valu2_mubuf_offset(i32 addrspace(1)* %out, [1024 x i32] addrspace(2)* %in) #1 {
222 %tmp = call i32 @llvm.r600.read.tidig.x() #0
223 %tmp1 = add i32 %tmp, 4
224 %tmp2 = getelementptr [1024 x i32], [1024 x i32] addrspace(2)* %in, i32 %tmp, i32 256
225 %tmp3 = load i32, i32 addrspace(2)* %tmp2
226 store i32 %tmp3, i32 addrspace(1)* %out
230 ; GCN-LABEL: {{^}}s_load_imm_v8i32:
231 ; GCN: buffer_load_dwordx4
232 ; GCN: buffer_load_dwordx4
233 define void @s_load_imm_v8i32(<8 x i32> addrspace(1)* %out, i32 addrspace(2)* nocapture readonly %in) #1 {
235 %tmp0 = tail call i32 @llvm.r600.read.tidig.x()
236 %tmp1 = getelementptr inbounds i32, i32 addrspace(2)* %in, i32 %tmp0
237 %tmp2 = bitcast i32 addrspace(2)* %tmp1 to <8 x i32> addrspace(2)*
238 %tmp3 = load <8 x i32>, <8 x i32> addrspace(2)* %tmp2, align 4
239 store <8 x i32> %tmp3, <8 x i32> addrspace(1)* %out, align 32
243 ; GCN-LABEL: {{^}}s_load_imm_v8i32_salu_user:
244 ; GCN: buffer_load_dwordx4
245 ; GCN: buffer_load_dwordx4
253 ; GCN: buffer_store_dword
254 define void @s_load_imm_v8i32_salu_user(i32 addrspace(1)* %out, i32 addrspace(2)* nocapture readonly %in) #1 {
256 %tmp0 = tail call i32 @llvm.r600.read.tidig.x()
257 %tmp1 = getelementptr inbounds i32, i32 addrspace(2)* %in, i32 %tmp0
258 %tmp2 = bitcast i32 addrspace(2)* %tmp1 to <8 x i32> addrspace(2)*
259 %tmp3 = load <8 x i32>, <8 x i32> addrspace(2)* %tmp2, align 4
261 %elt0 = extractelement <8 x i32> %tmp3, i32 0
262 %elt1 = extractelement <8 x i32> %tmp3, i32 1
263 %elt2 = extractelement <8 x i32> %tmp3, i32 2
264 %elt3 = extractelement <8 x i32> %tmp3, i32 3
265 %elt4 = extractelement <8 x i32> %tmp3, i32 4
266 %elt5 = extractelement <8 x i32> %tmp3, i32 5
267 %elt6 = extractelement <8 x i32> %tmp3, i32 6
268 %elt7 = extractelement <8 x i32> %tmp3, i32 7
270 %add0 = add i32 %elt0, %elt1
271 %add1 = add i32 %add0, %elt2
272 %add2 = add i32 %add1, %elt3
273 %add3 = add i32 %add2, %elt4
274 %add4 = add i32 %add3, %elt5
275 %add5 = add i32 %add4, %elt6
276 %add6 = add i32 %add5, %elt7
278 store i32 %add6, i32 addrspace(1)* %out
282 ; GCN-LABEL: {{^}}s_load_imm_v16i32:
283 ; GCN: buffer_load_dwordx4
284 ; GCN: buffer_load_dwordx4
285 ; GCN: buffer_load_dwordx4
286 ; GCN: buffer_load_dwordx4
287 define void @s_load_imm_v16i32(<16 x i32> addrspace(1)* %out, i32 addrspace(2)* nocapture readonly %in) #1 {
289 %tmp0 = tail call i32 @llvm.r600.read.tidig.x() #1
290 %tmp1 = getelementptr inbounds i32, i32 addrspace(2)* %in, i32 %tmp0
291 %tmp2 = bitcast i32 addrspace(2)* %tmp1 to <16 x i32> addrspace(2)*
292 %tmp3 = load <16 x i32>, <16 x i32> addrspace(2)* %tmp2, align 4
293 store <16 x i32> %tmp3, <16 x i32> addrspace(1)* %out, align 32
297 ; GCN-LABEL: {{^}}s_load_imm_v16i32_salu_user:
298 ; GCN: buffer_load_dwordx4
299 ; GCN: buffer_load_dwordx4
300 ; GCN: buffer_load_dwordx4
301 ; GCN: buffer_load_dwordx4
317 ; GCN: buffer_store_dword
318 define void @s_load_imm_v16i32_salu_user(i32 addrspace(1)* %out, i32 addrspace(2)* nocapture readonly %in) #1 {
320 %tmp0 = tail call i32 @llvm.r600.read.tidig.x() #1
321 %tmp1 = getelementptr inbounds i32, i32 addrspace(2)* %in, i32 %tmp0
322 %tmp2 = bitcast i32 addrspace(2)* %tmp1 to <16 x i32> addrspace(2)*
323 %tmp3 = load <16 x i32>, <16 x i32> addrspace(2)* %tmp2, align 4
325 %elt0 = extractelement <16 x i32> %tmp3, i32 0
326 %elt1 = extractelement <16 x i32> %tmp3, i32 1
327 %elt2 = extractelement <16 x i32> %tmp3, i32 2
328 %elt3 = extractelement <16 x i32> %tmp3, i32 3
329 %elt4 = extractelement <16 x i32> %tmp3, i32 4
330 %elt5 = extractelement <16 x i32> %tmp3, i32 5
331 %elt6 = extractelement <16 x i32> %tmp3, i32 6
332 %elt7 = extractelement <16 x i32> %tmp3, i32 7
333 %elt8 = extractelement <16 x i32> %tmp3, i32 8
334 %elt9 = extractelement <16 x i32> %tmp3, i32 9
335 %elt10 = extractelement <16 x i32> %tmp3, i32 10
336 %elt11 = extractelement <16 x i32> %tmp3, i32 11
337 %elt12 = extractelement <16 x i32> %tmp3, i32 12
338 %elt13 = extractelement <16 x i32> %tmp3, i32 13
339 %elt14 = extractelement <16 x i32> %tmp3, i32 14
340 %elt15 = extractelement <16 x i32> %tmp3, i32 15
342 %add0 = add i32 %elt0, %elt1
343 %add1 = add i32 %add0, %elt2
344 %add2 = add i32 %add1, %elt3
345 %add3 = add i32 %add2, %elt4
346 %add4 = add i32 %add3, %elt5
347 %add5 = add i32 %add4, %elt6
348 %add6 = add i32 %add5, %elt7
349 %add7 = add i32 %add6, %elt8
350 %add8 = add i32 %add7, %elt9
351 %add9 = add i32 %add8, %elt10
352 %add10 = add i32 %add9, %elt11
353 %add11 = add i32 %add10, %elt12
354 %add12 = add i32 %add11, %elt13
355 %add13 = add i32 %add12, %elt14
356 %add14 = add i32 %add13, %elt15
358 store i32 %add14, i32 addrspace(1)* %out
362 attributes #0 = { nounwind readnone }
363 attributes #1 = { nounwind }