1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=kaveri -earlycse-debug-hash -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s
4 define amdgpu_kernel void @v_sad_u32_pat1(ptr addrspace(1) %out, i32 %a, i32 %b, i32 %c) {
5 ; GCN-LABEL: v_sad_u32_pat1:
7 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[8:9], 0x2
8 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[8:9], 0x0
9 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
10 ; GCN-NEXT: v_mov_b32_e32 v0, s1
11 ; GCN-NEXT: v_mov_b32_e32 v1, s2
12 ; GCN-NEXT: v_sad_u32 v2, s0, v0, v1
13 ; GCN-NEXT: v_mov_b32_e32 v0, s4
14 ; GCN-NEXT: v_mov_b32_e32 v1, s5
15 ; GCN-NEXT: flat_store_dword v[0:1], v2
17 %icmp0 = icmp ugt i32 %a, %b
18 %t0 = select i1 %icmp0, i32 %a, i32 %b
20 %icmp1 = icmp ule i32 %a, %b
21 %t1 = select i1 %icmp1, i32 %a, i32 %b
23 %ret0 = sub i32 %t0, %t1
24 %ret = add i32 %ret0, %c
26 store i32 %ret, ptr addrspace(1) %out
30 define amdgpu_kernel void @v_sad_u32_constant_pat1(ptr addrspace(1) %out, i32 %a) {
31 ; GCN-LABEL: v_sad_u32_constant_pat1:
33 ; GCN-NEXT: s_load_dword s2, s[8:9], 0x2
34 ; GCN-NEXT: s_load_dwordx2 s[0:1], s[8:9], 0x0
35 ; GCN-NEXT: v_mov_b32_e32 v0, 0x5a
36 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
37 ; GCN-NEXT: v_sad_u32 v2, s2, v0, 20
38 ; GCN-NEXT: v_mov_b32_e32 v0, s0
39 ; GCN-NEXT: v_mov_b32_e32 v1, s1
40 ; GCN-NEXT: flat_store_dword v[0:1], v2
42 %icmp0 = icmp ugt i32 %a, 90
43 %t0 = select i1 %icmp0, i32 %a, i32 90
45 %icmp1 = icmp ule i32 %a, 90
46 %t1 = select i1 %icmp1, i32 %a, i32 90
48 %ret0 = sub i32 %t0, %t1
49 %ret = add i32 %ret0, 20
51 store i32 %ret, ptr addrspace(1) %out
55 define amdgpu_kernel void @v_sad_u32_pat2(ptr addrspace(1) %out, i32 %a, i32 %b, i32 %c) {
56 ; GCN-LABEL: v_sad_u32_pat2:
58 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[8:9], 0x2
59 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[8:9], 0x0
60 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
61 ; GCN-NEXT: v_mov_b32_e32 v0, s1
62 ; GCN-NEXT: v_mov_b32_e32 v1, s2
63 ; GCN-NEXT: v_sad_u32 v2, s0, v0, v1
64 ; GCN-NEXT: v_mov_b32_e32 v0, s4
65 ; GCN-NEXT: v_mov_b32_e32 v1, s5
66 ; GCN-NEXT: flat_store_dword v[0:1], v2
68 %icmp0 = icmp ugt i32 %a, %b
69 %sub0 = sub i32 %a, %b
70 %sub1 = sub i32 %b, %a
71 %ret0 = select i1 %icmp0, i32 %sub0, i32 %sub1
73 %ret = add i32 %ret0, %c
75 store i32 %ret, ptr addrspace(1) %out
79 define amdgpu_kernel void @v_sad_u32_multi_use_sub_pat1(ptr addrspace(1) %out, i32 %a, i32 %b, i32 %c) {
80 ; GCN-LABEL: v_sad_u32_multi_use_sub_pat1:
82 ; GCN-NEXT: s_mov_b64 s[18:19], s[2:3]
83 ; GCN-NEXT: s_mov_b64 s[16:17], s[0:1]
84 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[8:9], 0x2
85 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[8:9], 0x0
86 ; GCN-NEXT: s_add_u32 s16, s16, s15
87 ; GCN-NEXT: s_addc_u32 s17, s17, 0
88 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
89 ; GCN-NEXT: s_min_u32 s3, s0, s1
90 ; GCN-NEXT: s_max_u32 s0, s0, s1
91 ; GCN-NEXT: s_sub_i32 s0, s0, s3
92 ; GCN-NEXT: v_mov_b32_e32 v0, s4
93 ; GCN-NEXT: v_mov_b32_e32 v2, s0
94 ; GCN-NEXT: s_add_i32 s0, s0, s2
95 ; GCN-NEXT: v_mov_b32_e32 v1, s5
96 ; GCN-NEXT: buffer_store_dword v2, v0, s[16:19], 0 offen
97 ; GCN-NEXT: s_waitcnt vmcnt(0)
98 ; GCN-NEXT: v_mov_b32_e32 v2, s0
99 ; GCN-NEXT: flat_store_dword v[0:1], v2
101 %icmp0 = icmp ugt i32 %a, %b
102 %t0 = select i1 %icmp0, i32 %a, i32 %b
104 %icmp1 = icmp ule i32 %a, %b
105 %t1 = select i1 %icmp1, i32 %a, i32 %b
107 %ret0 = sub i32 %t0, %t1
108 store volatile i32 %ret0, ptr addrspace(5) undef
109 %ret = add i32 %ret0, %c
111 store i32 %ret, ptr addrspace(1) %out
115 define amdgpu_kernel void @v_sad_u32_multi_use_add_pat1(ptr addrspace(1) %out, i32 %a, i32 %b, i32 %c) {
116 ; GCN-LABEL: v_sad_u32_multi_use_add_pat1:
118 ; GCN-NEXT: s_mov_b64 s[18:19], s[2:3]
119 ; GCN-NEXT: s_mov_b64 s[16:17], s[0:1]
120 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[8:9], 0x2
121 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[8:9], 0x0
122 ; GCN-NEXT: s_add_u32 s16, s16, s15
123 ; GCN-NEXT: s_addc_u32 s17, s17, 0
124 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
125 ; GCN-NEXT: v_mov_b32_e32 v2, s1
126 ; GCN-NEXT: v_mov_b32_e32 v3, s2
127 ; GCN-NEXT: v_mov_b32_e32 v0, s4
128 ; GCN-NEXT: v_mov_b32_e32 v1, s5
129 ; GCN-NEXT: v_sad_u32 v2, s0, v2, v3
130 ; GCN-NEXT: buffer_store_dword v2, v0, s[16:19], 0 offen
131 ; GCN-NEXT: s_waitcnt vmcnt(0)
132 ; GCN-NEXT: flat_store_dword v[0:1], v2
134 %icmp0 = icmp ugt i32 %a, %b
135 %t0 = select i1 %icmp0, i32 %a, i32 %b
137 %icmp1 = icmp ule i32 %a, %b
138 %t1 = select i1 %icmp1, i32 %a, i32 %b
140 %ret0 = sub i32 %t0, %t1
141 %ret = add i32 %ret0, %c
142 store volatile i32 %ret, ptr addrspace(5) undef
143 store i32 %ret, ptr addrspace(1) %out
147 define amdgpu_kernel void @v_sad_u32_multi_use_max_pat1(ptr addrspace(1) %out, i32 %a, i32 %b, i32 %c) {
148 ; GCN-LABEL: v_sad_u32_multi_use_max_pat1:
150 ; GCN-NEXT: s_mov_b64 s[18:19], s[2:3]
151 ; GCN-NEXT: s_mov_b64 s[16:17], s[0:1]
152 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[8:9], 0x2
153 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[8:9], 0x0
154 ; GCN-NEXT: s_add_u32 s16, s16, s15
155 ; GCN-NEXT: s_addc_u32 s17, s17, 0
156 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
157 ; GCN-NEXT: s_max_u32 s3, s0, s1
158 ; GCN-NEXT: v_mov_b32_e32 v0, s1
159 ; GCN-NEXT: v_mov_b32_e32 v1, s2
160 ; GCN-NEXT: v_mov_b32_e32 v2, s3
161 ; GCN-NEXT: v_sad_u32 v3, s0, v0, v1
162 ; GCN-NEXT: buffer_store_dword v2, v0, s[16:19], 0 offen
163 ; GCN-NEXT: s_waitcnt vmcnt(0)
164 ; GCN-NEXT: v_mov_b32_e32 v0, s4
165 ; GCN-NEXT: v_mov_b32_e32 v1, s5
166 ; GCN-NEXT: flat_store_dword v[0:1], v3
168 %icmp0 = icmp ugt i32 %a, %b
169 %t0 = select i1 %icmp0, i32 %a, i32 %b
170 store volatile i32 %t0, ptr addrspace(5) undef
172 %icmp1 = icmp ule i32 %a, %b
173 %t1 = select i1 %icmp1, i32 %a, i32 %b
175 %ret0 = sub i32 %t0, %t1
176 %ret = add i32 %ret0, %c
178 store i32 %ret, ptr addrspace(1) %out
182 define amdgpu_kernel void @v_sad_u32_multi_use_min_pat1(ptr addrspace(1) %out, i32 %a, i32 %b, i32 %c) {
183 ; GCN-LABEL: v_sad_u32_multi_use_min_pat1:
185 ; GCN-NEXT: s_mov_b64 s[18:19], s[2:3]
186 ; GCN-NEXT: s_mov_b64 s[16:17], s[0:1]
187 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[8:9], 0x2
188 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[8:9], 0x0
189 ; GCN-NEXT: s_add_u32 s16, s16, s15
190 ; GCN-NEXT: s_addc_u32 s17, s17, 0
191 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
192 ; GCN-NEXT: s_min_u32 s3, s0, s1
193 ; GCN-NEXT: v_mov_b32_e32 v0, s1
194 ; GCN-NEXT: v_mov_b32_e32 v1, s2
195 ; GCN-NEXT: v_mov_b32_e32 v2, s3
196 ; GCN-NEXT: v_sad_u32 v3, s0, v0, v1
197 ; GCN-NEXT: buffer_store_dword v2, v0, s[16:19], 0 offen
198 ; GCN-NEXT: s_waitcnt vmcnt(0)
199 ; GCN-NEXT: v_mov_b32_e32 v0, s4
200 ; GCN-NEXT: v_mov_b32_e32 v1, s5
201 ; GCN-NEXT: flat_store_dword v[0:1], v3
203 %icmp0 = icmp ugt i32 %a, %b
204 %t0 = select i1 %icmp0, i32 %a, i32 %b
206 %icmp1 = icmp ule i32 %a, %b
207 %t1 = select i1 %icmp1, i32 %a, i32 %b
209 store volatile i32 %t1, ptr addrspace(5) undef
211 %ret0 = sub i32 %t0, %t1
212 %ret = add i32 %ret0, %c
214 store i32 %ret, ptr addrspace(1) %out
218 define amdgpu_kernel void @v_sad_u32_multi_use_sub_pat2(ptr addrspace(1) %out, i32 %a, i32 %b, i32 %c) {
219 ; GCN-LABEL: v_sad_u32_multi_use_sub_pat2:
221 ; GCN-NEXT: s_mov_b64 s[18:19], s[2:3]
222 ; GCN-NEXT: s_mov_b64 s[16:17], s[0:1]
223 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[8:9], 0x2
224 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[8:9], 0x0
225 ; GCN-NEXT: s_add_u32 s16, s16, s15
226 ; GCN-NEXT: s_addc_u32 s17, s17, 0
227 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
228 ; GCN-NEXT: s_sub_i32 s3, s0, s1
229 ; GCN-NEXT: v_mov_b32_e32 v0, s1
230 ; GCN-NEXT: v_mov_b32_e32 v1, s2
231 ; GCN-NEXT: v_mov_b32_e32 v2, s3
232 ; GCN-NEXT: v_sad_u32 v3, s0, v0, v1
233 ; GCN-NEXT: buffer_store_dword v2, v0, s[16:19], 0 offen
234 ; GCN-NEXT: s_waitcnt vmcnt(0)
235 ; GCN-NEXT: v_mov_b32_e32 v0, s4
236 ; GCN-NEXT: v_mov_b32_e32 v1, s5
237 ; GCN-NEXT: flat_store_dword v[0:1], v3
239 %icmp0 = icmp ugt i32 %a, %b
240 %sub0 = sub i32 %a, %b
241 store volatile i32 %sub0, ptr addrspace(5) undef
242 %sub1 = sub i32 %b, %a
243 %ret0 = select i1 %icmp0, i32 %sub0, i32 %sub1
245 %ret = add i32 %ret0, %c
247 store i32 %ret, ptr addrspace(1) %out
251 define amdgpu_kernel void @v_sad_u32_multi_use_select_pat2(ptr addrspace(1) %out, i32 %a, i32 %b, i32 %c) {
252 ; GCN-LABEL: v_sad_u32_multi_use_select_pat2:
254 ; GCN-NEXT: s_mov_b64 s[18:19], s[2:3]
255 ; GCN-NEXT: s_mov_b64 s[16:17], s[0:1]
256 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[8:9], 0x2
257 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[8:9], 0x0
258 ; GCN-NEXT: s_add_u32 s16, s16, s15
259 ; GCN-NEXT: s_addc_u32 s17, s17, 0
260 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
261 ; GCN-NEXT: s_min_u32 s3, s0, s1
262 ; GCN-NEXT: s_max_u32 s0, s0, s1
263 ; GCN-NEXT: s_sub_i32 s0, s0, s3
264 ; GCN-NEXT: v_mov_b32_e32 v0, s4
265 ; GCN-NEXT: v_mov_b32_e32 v2, s0
266 ; GCN-NEXT: s_add_i32 s0, s0, s2
267 ; GCN-NEXT: v_mov_b32_e32 v1, s5
268 ; GCN-NEXT: buffer_store_dword v2, v0, s[16:19], 0 offen
269 ; GCN-NEXT: s_waitcnt vmcnt(0)
270 ; GCN-NEXT: v_mov_b32_e32 v2, s0
271 ; GCN-NEXT: flat_store_dword v[0:1], v2
273 %icmp0 = icmp ugt i32 %a, %b
274 %sub0 = sub i32 %a, %b
275 %sub1 = sub i32 %b, %a
276 %ret0 = select i1 %icmp0, i32 %sub0, i32 %sub1
277 store volatile i32 %ret0, ptr addrspace(5) undef
279 %ret = add i32 %ret0, %c
281 store i32 %ret, ptr addrspace(1) %out
285 define amdgpu_kernel void @v_sad_u32_vector_pat1(ptr addrspace(1) %out, <4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
286 ; GCN-LABEL: v_sad_u32_vector_pat1:
288 ; GCN-NEXT: s_load_dwordx8 s[0:7], s[8:9], 0x4
289 ; GCN-NEXT: s_load_dwordx4 s[12:15], s[8:9], 0xc
290 ; GCN-NEXT: s_load_dwordx2 s[8:9], s[8:9], 0x0
291 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
292 ; GCN-NEXT: v_mov_b32_e32 v0, s7
293 ; GCN-NEXT: v_mov_b32_e32 v1, s15
294 ; GCN-NEXT: v_mov_b32_e32 v2, s6
295 ; GCN-NEXT: v_sad_u32 v3, s3, v0, v1
296 ; GCN-NEXT: v_mov_b32_e32 v0, s14
297 ; GCN-NEXT: v_sad_u32 v2, s2, v2, v0
298 ; GCN-NEXT: v_mov_b32_e32 v0, s5
299 ; GCN-NEXT: v_mov_b32_e32 v1, s13
300 ; GCN-NEXT: v_sad_u32 v1, s1, v0, v1
301 ; GCN-NEXT: v_mov_b32_e32 v0, s4
302 ; GCN-NEXT: v_mov_b32_e32 v4, s12
303 ; GCN-NEXT: v_sad_u32 v0, s0, v0, v4
304 ; GCN-NEXT: v_mov_b32_e32 v4, s8
305 ; GCN-NEXT: v_mov_b32_e32 v5, s9
306 ; GCN-NEXT: flat_store_dwordx4 v[4:5], v[0:3]
308 %icmp0 = icmp ugt <4 x i32> %a, %b
309 %t0 = select <4 x i1> %icmp0, <4 x i32> %a, <4 x i32> %b
311 %icmp1 = icmp ule <4 x i32> %a, %b
312 %t1 = select <4 x i1> %icmp1, <4 x i32> %a, <4 x i32> %b
314 %ret0 = sub <4 x i32> %t0, %t1
315 %ret = add <4 x i32> %ret0, %c
317 store <4 x i32> %ret, ptr addrspace(1) %out
321 define amdgpu_kernel void @v_sad_u32_vector_pat2(ptr addrspace(1) %out, <4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
322 ; GCN-LABEL: v_sad_u32_vector_pat2:
324 ; GCN-NEXT: s_load_dwordx8 s[0:7], s[8:9], 0x4
325 ; GCN-NEXT: s_load_dwordx4 s[12:15], s[8:9], 0xc
326 ; GCN-NEXT: s_load_dwordx2 s[8:9], s[8:9], 0x0
327 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
328 ; GCN-NEXT: v_mov_b32_e32 v0, s7
329 ; GCN-NEXT: v_mov_b32_e32 v1, s15
330 ; GCN-NEXT: v_mov_b32_e32 v2, s6
331 ; GCN-NEXT: v_sad_u32 v3, s3, v0, v1
332 ; GCN-NEXT: v_mov_b32_e32 v0, s14
333 ; GCN-NEXT: v_sad_u32 v2, s2, v2, v0
334 ; GCN-NEXT: v_mov_b32_e32 v0, s5
335 ; GCN-NEXT: v_mov_b32_e32 v1, s13
336 ; GCN-NEXT: v_sad_u32 v1, s1, v0, v1
337 ; GCN-NEXT: v_mov_b32_e32 v0, s4
338 ; GCN-NEXT: v_mov_b32_e32 v4, s12
339 ; GCN-NEXT: v_sad_u32 v0, s0, v0, v4
340 ; GCN-NEXT: v_mov_b32_e32 v4, s8
341 ; GCN-NEXT: v_mov_b32_e32 v5, s9
342 ; GCN-NEXT: flat_store_dwordx4 v[4:5], v[0:3]
344 %icmp0 = icmp ugt <4 x i32> %a, %b
345 %sub0 = sub <4 x i32> %a, %b
346 %sub1 = sub <4 x i32> %b, %a
347 %ret0 = select <4 x i1> %icmp0, <4 x i32> %sub0, <4 x i32> %sub1
349 %ret = add <4 x i32> %ret0, %c
351 store <4 x i32> %ret, ptr addrspace(1) %out
355 define amdgpu_kernel void @v_sad_u32_i16_pat1(ptr addrspace(1) %out, i16 %a, i16 %b, i16 %c) {
356 ; GCN-LABEL: v_sad_u32_i16_pat1:
358 ; GCN-NEXT: s_load_dword s4, s[8:9], 0x2
359 ; GCN-NEXT: s_load_dwordx2 s[0:1], s[8:9], 0x2
360 ; GCN-NEXT: s_load_dwordx2 s[2:3], s[8:9], 0x0
361 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
362 ; GCN-NEXT: s_and_b32 s4, s4, 0xffff
363 ; GCN-NEXT: s_lshr_b32 s0, s0, 16
364 ; GCN-NEXT: v_mov_b32_e32 v0, s1
365 ; GCN-NEXT: v_mov_b32_e32 v1, s0
366 ; GCN-NEXT: v_sad_u32 v2, s4, v1, v0
367 ; GCN-NEXT: v_mov_b32_e32 v0, s2
368 ; GCN-NEXT: v_mov_b32_e32 v1, s3
369 ; GCN-NEXT: flat_store_short v[0:1], v2
371 %icmp0 = icmp ugt i16 %a, %b
372 %t0 = select i1 %icmp0, i16 %a, i16 %b
374 %icmp1 = icmp ule i16 %a, %b
375 %t1 = select i1 %icmp1, i16 %a, i16 %b
377 %ret0 = sub i16 %t0, %t1
378 %ret = add i16 %ret0, %c
380 store i16 %ret, ptr addrspace(1) %out
384 define amdgpu_kernel void @v_sad_u32_i16_pat2(ptr addrspace(1) %out) {
385 ; GCN-LABEL: v_sad_u32_i16_pat2:
387 ; GCN-NEXT: flat_load_ushort v0, v[0:1] glc
388 ; GCN-NEXT: s_waitcnt vmcnt(0)
389 ; GCN-NEXT: s_load_dwordx2 s[0:1], s[8:9], 0x0
390 ; GCN-NEXT: flat_load_ushort v1, v[0:1] glc
391 ; GCN-NEXT: s_waitcnt vmcnt(0)
392 ; GCN-NEXT: flat_load_ushort v2, v[0:1] glc
393 ; GCN-NEXT: s_waitcnt vmcnt(0)
394 ; GCN-NEXT: v_sad_u32 v2, v0, v1, v2
395 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
396 ; GCN-NEXT: v_mov_b32_e32 v0, s0
397 ; GCN-NEXT: v_mov_b32_e32 v1, s1
398 ; GCN-NEXT: flat_store_short v[0:1], v2
400 %a = load volatile i16, ptr addrspace(1) undef
401 %b = load volatile i16, ptr addrspace(1) undef
402 %c = load volatile i16, ptr addrspace(1) undef
403 %icmp0 = icmp ugt i16 %a, %b
404 %sub0 = sub i16 %a, %b
405 %sub1 = sub i16 %b, %a
406 %ret0 = select i1 %icmp0, i16 %sub0, i16 %sub1
408 %ret = add i16 %ret0, %c
410 store i16 %ret, ptr addrspace(1) %out
414 define amdgpu_kernel void @v_sad_u32_i8_pat1(ptr addrspace(1) %out, i8 %a, i8 %b, i8 %c) {
415 ; GCN-LABEL: v_sad_u32_i8_pat1:
417 ; GCN-NEXT: s_load_dword s2, s[8:9], 0x2
418 ; GCN-NEXT: s_load_dwordx2 s[0:1], s[8:9], 0x0
419 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
420 ; GCN-NEXT: s_and_b32 s3, s2, 0xff
421 ; GCN-NEXT: s_bfe_u32 s4, s2, 0x80008
422 ; GCN-NEXT: s_lshr_b32 s2, s2, 16
423 ; GCN-NEXT: v_mov_b32_e32 v0, s4
424 ; GCN-NEXT: v_mov_b32_e32 v1, s2
425 ; GCN-NEXT: v_sad_u32 v2, s3, v0, v1
426 ; GCN-NEXT: v_mov_b32_e32 v0, s0
427 ; GCN-NEXT: v_mov_b32_e32 v1, s1
428 ; GCN-NEXT: flat_store_byte v[0:1], v2
430 %icmp0 = icmp ugt i8 %a, %b
431 %t0 = select i1 %icmp0, i8 %a, i8 %b
433 %icmp1 = icmp ule i8 %a, %b
434 %t1 = select i1 %icmp1, i8 %a, i8 %b
436 %ret0 = sub i8 %t0, %t1
437 %ret = add i8 %ret0, %c
439 store i8 %ret, ptr addrspace(1) %out
443 define amdgpu_kernel void @v_sad_u32_i8_pat2(ptr addrspace(1) %out) {
444 ; GCN-LABEL: v_sad_u32_i8_pat2:
446 ; GCN-NEXT: flat_load_ubyte v0, v[0:1] glc
447 ; GCN-NEXT: s_waitcnt vmcnt(0)
448 ; GCN-NEXT: s_load_dwordx2 s[0:1], s[8:9], 0x0
449 ; GCN-NEXT: flat_load_ubyte v1, v[0:1] glc
450 ; GCN-NEXT: s_waitcnt vmcnt(0)
451 ; GCN-NEXT: flat_load_ubyte v2, v[0:1] glc
452 ; GCN-NEXT: s_waitcnt vmcnt(0)
453 ; GCN-NEXT: v_sad_u32 v2, v0, v1, v2
454 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
455 ; GCN-NEXT: v_mov_b32_e32 v0, s0
456 ; GCN-NEXT: v_mov_b32_e32 v1, s1
457 ; GCN-NEXT: flat_store_byte v[0:1], v2
459 %a = load volatile i8, ptr addrspace(1) undef
460 %b = load volatile i8, ptr addrspace(1) undef
461 %c = load volatile i8, ptr addrspace(1) undef
462 %icmp0 = icmp ugt i8 %a, %b
463 %sub0 = sub i8 %a, %b
464 %sub1 = sub i8 %b, %a
465 %ret0 = select i1 %icmp0, i8 %sub0, i8 %sub1
467 %ret = add i8 %ret0, %c
469 store i8 %ret, ptr addrspace(1) %out
473 define amdgpu_kernel void @s_sad_u32_i8_pat2(ptr addrspace(1) %out, i8 zeroext %a, i8 zeroext %b, i8 zeroext %c) {
474 ; GCN-LABEL: s_sad_u32_i8_pat2:
476 ; GCN-NEXT: s_load_dword s2, s[8:9], 0x2
477 ; GCN-NEXT: s_load_dwordx2 s[0:1], s[8:9], 0x0
478 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
479 ; GCN-NEXT: s_and_b32 s3, s2, 0xff
480 ; GCN-NEXT: s_bfe_u32 s4, s2, 0x80008
481 ; GCN-NEXT: s_lshr_b32 s2, s2, 16
482 ; GCN-NEXT: v_mov_b32_e32 v0, s4
483 ; GCN-NEXT: v_mov_b32_e32 v1, s2
484 ; GCN-NEXT: v_sad_u32 v2, s3, v0, v1
485 ; GCN-NEXT: v_mov_b32_e32 v0, s0
486 ; GCN-NEXT: v_mov_b32_e32 v1, s1
487 ; GCN-NEXT: flat_store_byte v[0:1], v2
489 %icmp0 = icmp ugt i8 %a, %b
490 %sub0 = sub i8 %a, %b
491 %sub1 = sub i8 %b, %a
492 %ret0 = select i1 %icmp0, i8 %sub0, i8 %sub1
494 %ret = add i8 %ret0, %c
496 store i8 %ret, ptr addrspace(1) %out
500 define amdgpu_kernel void @v_sad_u32_mismatched_operands_pat1(ptr addrspace(1) %out, i32 %a, i32 %b, i32 %c, i32 %d) {
501 ; GCN-LABEL: v_sad_u32_mismatched_operands_pat1:
503 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[8:9], 0x2
504 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[8:9], 0x0
505 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
506 ; GCN-NEXT: s_max_u32 s6, s0, s1
507 ; GCN-NEXT: s_cmp_le_u32 s0, s1
508 ; GCN-NEXT: s_cselect_b32 s0, s0, s3
509 ; GCN-NEXT: s_sub_i32 s0, s6, s0
510 ; GCN-NEXT: s_add_i32 s0, s0, s2
511 ; GCN-NEXT: v_mov_b32_e32 v0, s4
512 ; GCN-NEXT: v_mov_b32_e32 v1, s5
513 ; GCN-NEXT: v_mov_b32_e32 v2, s0
514 ; GCN-NEXT: flat_store_dword v[0:1], v2
516 %icmp0 = icmp ugt i32 %a, %b
517 %t0 = select i1 %icmp0, i32 %a, i32 %b
519 %icmp1 = icmp ule i32 %a, %b
520 %t1 = select i1 %icmp1, i32 %a, i32 %d
522 %ret0 = sub i32 %t0, %t1
523 %ret = add i32 %ret0, %c
525 store i32 %ret, ptr addrspace(1) %out
529 define amdgpu_kernel void @v_sad_u32_mismatched_operands_pat2(ptr addrspace(1) %out, i32 %a, i32 %b, i32 %c, i32 %d) {
530 ; GCN-LABEL: v_sad_u32_mismatched_operands_pat2:
532 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[8:9], 0x2
533 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[8:9], 0x0
534 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
535 ; GCN-NEXT: s_sub_i32 s3, s0, s3
536 ; GCN-NEXT: s_sub_i32 s6, s1, s0
537 ; GCN-NEXT: s_cmp_lt_u32 s1, s0
538 ; GCN-NEXT: s_cselect_b32 s0, s3, s6
539 ; GCN-NEXT: s_add_i32 s0, s0, s2
540 ; GCN-NEXT: v_mov_b32_e32 v0, s4
541 ; GCN-NEXT: v_mov_b32_e32 v1, s5
542 ; GCN-NEXT: v_mov_b32_e32 v2, s0
543 ; GCN-NEXT: flat_store_dword v[0:1], v2
545 %icmp0 = icmp ugt i32 %a, %b
546 %sub0 = sub i32 %a, %d
547 %sub1 = sub i32 %b, %a
548 %ret0 = select i1 %icmp0, i32 %sub0, i32 %sub1
550 %ret = add i32 %ret0, %c
552 store i32 %ret, ptr addrspace(1) %out