1 ; RUN: llc -march=amdgcn -mtriple=amdgcn-- -verify-machineinstrs < %s | FileCheck -allow-deprecated-dag-overlap -check-prefix=GCN -check-prefix=FUNC %s
2 ; RUN: llc -march=r600 -mtriple=r600-- -mcpu=redwood -verify-machineinstrs < %s | FileCheck -allow-deprecated-dag-overlap -check-prefix=R600 -check-prefix=FUNC %s
4 declare i32 @llvm.r600.read.tidig.x() nounwind readnone
6 ; FUNC-LABEL: {{^}}setcc_v2i32:
7 ; R600-DAG: SETE_INT * T{{[0-9]+\.[XYZW]}}, KC0[3].X, KC0[3].Z
8 ; R600-DAG: SETE_INT * T{{[0-9]+\.[XYZW]}}, KC0[2].W, KC0[3].Y
10 ; GCN: v_cmp_eq_u32_e32
11 ; GCN: v_cmp_eq_u32_e32
12 define amdgpu_kernel void @setcc_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> %a, <2 x i32> %b) #0 {
13 %result = icmp eq <2 x i32> %a, %b
14 %sext = sext <2 x i1> %result to <2 x i32>
15 store <2 x i32> %sext, <2 x i32> addrspace(1)* %out
19 ; FUNC-LABEL: {{^}}setcc_v4i32:
20 ; R600-DAG: SETE_INT * T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}}
21 ; R600-DAG: SETE_INT * T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}}
22 ; R600-DAG: SETE_INT * T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}}
23 ; R600-DAG: SETE_INT * T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}}
25 ; GCN: v_cmp_eq_u32_e32
26 ; GCN: v_cmp_eq_u32_e32
27 ; GCN: v_cmp_eq_u32_e32
28 ; GCN: v_cmp_eq_u32_e32
29 define amdgpu_kernel void @setcc_v4i32(<4 x i32> addrspace(1)* %out, <4 x i32> addrspace(1)* %in) #0 {
30 %b_ptr = getelementptr <4 x i32>, <4 x i32> addrspace(1)* %in, i32 1
31 %a = load <4 x i32>, <4 x i32> addrspace(1)* %in
32 %b = load <4 x i32>, <4 x i32> addrspace(1)* %b_ptr
33 %result = icmp eq <4 x i32> %a, %b
34 %sext = sext <4 x i1> %result to <4 x i32>
35 store <4 x i32> %sext, <4 x i32> addrspace(1)* %out
39 ;;;==========================================================================;;;
41 ;;;==========================================================================;;;
43 ; FUNC-LABEL: {{^}}f32_oeq:
46 define amdgpu_kernel void @f32_oeq(i32 addrspace(1)* %out, float %a, float %b) #0 {
48 %0 = fcmp oeq float %a, %b
49 %1 = sext i1 %0 to i32
50 store i32 %1, i32 addrspace(1)* %out
54 ; FUNC-LABEL: {{^}}f32_ogt:
57 define amdgpu_kernel void @f32_ogt(i32 addrspace(1)* %out, float %a, float %b) #0 {
59 %0 = fcmp ogt float %a, %b
60 %1 = sext i1 %0 to i32
61 store i32 %1, i32 addrspace(1)* %out
65 ; FUNC-LABEL: {{^}}f32_oge:
68 define amdgpu_kernel void @f32_oge(i32 addrspace(1)* %out, float %a, float %b) #0 {
70 %0 = fcmp oge float %a, %b
71 %1 = sext i1 %0 to i32
72 store i32 %1, i32 addrspace(1)* %out
76 ; FUNC-LABEL: {{^}}f32_olt:
79 define amdgpu_kernel void @f32_olt(i32 addrspace(1)* %out, float %a, float %b) #0 {
81 %0 = fcmp olt float %a, %b
82 %1 = sext i1 %0 to i32
83 store i32 %1, i32 addrspace(1)* %out
87 ; FUNC-LABEL: {{^}}f32_ole:
90 define amdgpu_kernel void @f32_ole(i32 addrspace(1)* %out, float %a, float %b) #0 {
92 %0 = fcmp ole float %a, %b
93 %1 = sext i1 %0 to i32
94 store i32 %1, i32 addrspace(1)* %out
98 ; FUNC-LABEL: {{^}}f32_one:
100 ; R600-DAG: SETE_DX10
102 ; R600-DAG: SETNE_DX10
104 ; R600-DAG: SETNE_INT
106 ; GCN: v_cmp_lg_f32_e32 vcc
107 ; GCN-NEXT: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1, vcc
108 define amdgpu_kernel void @f32_one(i32 addrspace(1)* %out, float %a, float %b) #0 {
110 %0 = fcmp one float %a, %b
111 %1 = sext i1 %0 to i32
112 store i32 %1, i32 addrspace(1)* %out
116 ; FUNC-LABEL: {{^}}f32_ord:
117 ; R600-DAG: SETE_DX10
118 ; R600-DAG: SETE_DX10
120 ; R600-DAG: SETNE_INT
122 define amdgpu_kernel void @f32_ord(i32 addrspace(1)* %out, float %a, float %b) #0 {
124 %0 = fcmp ord float %a, %b
125 %1 = sext i1 %0 to i32
126 store i32 %1, i32 addrspace(1)* %out
130 ; FUNC-LABEL: {{^}}f32_ueq:
131 ; R600-DAG: SETNE_DX10
132 ; R600-DAG: SETNE_DX10
134 ; R600-DAG: SETE_DX10
136 ; R600-DAG: SETNE_INT
138 ; GCN: v_cmp_nlg_f32_e32 vcc
139 ; GCN-NEXT: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1, vcc
140 define amdgpu_kernel void @f32_ueq(i32 addrspace(1)* %out, float %a, float %b) #0 {
142 %0 = fcmp ueq float %a, %b
143 %1 = sext i1 %0 to i32
144 store i32 %1, i32 addrspace(1)* %out
148 ; FUNC-LABEL: {{^}}f32_ugt:
151 ; GCN: v_cmp_nle_f32_e32 vcc
152 ; GCN-NEXT: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1, vcc
153 define amdgpu_kernel void @f32_ugt(i32 addrspace(1)* %out, float %a, float %b) #0 {
155 %0 = fcmp ugt float %a, %b
156 %1 = sext i1 %0 to i32
157 store i32 %1, i32 addrspace(1)* %out
161 ; FUNC-LABEL: {{^}}f32_uge:
165 ; GCN: v_cmp_nlt_f32_e32 vcc
166 ; GCN-NEXT: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1, vcc
167 define amdgpu_kernel void @f32_uge(i32 addrspace(1)* %out, float %a, float %b) #0 {
169 %0 = fcmp uge float %a, %b
170 %1 = sext i1 %0 to i32
171 store i32 %1, i32 addrspace(1)* %out
175 ; FUNC-LABEL: {{^}}f32_ult:
179 ; GCN: v_cmp_nge_f32_e32 vcc
180 ; GCN-NEXT: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1, vcc
181 define amdgpu_kernel void @f32_ult(i32 addrspace(1)* %out, float %a, float %b) #0 {
183 %0 = fcmp ult float %a, %b
184 %1 = sext i1 %0 to i32
185 store i32 %1, i32 addrspace(1)* %out
189 ; FUNC-LABEL: {{^}}f32_ule:
193 ; GCN: v_cmp_ngt_f32_e32 vcc
194 ; GCN-NEXT: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1, vcc
195 define amdgpu_kernel void @f32_ule(i32 addrspace(1)* %out, float %a, float %b) #0 {
197 %0 = fcmp ule float %a, %b
198 %1 = sext i1 %0 to i32
199 store i32 %1, i32 addrspace(1)* %out
203 ; FUNC-LABEL: {{^}}f32_une:
206 define amdgpu_kernel void @f32_une(i32 addrspace(1)* %out, float %a, float %b) #0 {
208 %0 = fcmp une float %a, %b
209 %1 = sext i1 %0 to i32
210 store i32 %1, i32 addrspace(1)* %out
214 ; FUNC-LABEL: {{^}}f32_uno:
220 define amdgpu_kernel void @f32_uno(i32 addrspace(1)* %out, float %a, float %b) #0 {
222 %0 = fcmp uno float %a, %b
223 %1 = sext i1 %0 to i32
224 store i32 %1, i32 addrspace(1)* %out
228 ;;;==========================================================================;;;
229 ;; 32-bit integer comparisons
230 ;;;==========================================================================;;;
232 ; FUNC-LABEL: {{^}}i32_eq:
235 define amdgpu_kernel void @i32_eq(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
237 %0 = icmp eq i32 %a, %b
238 %1 = sext i1 %0 to i32
239 store i32 %1, i32 addrspace(1)* %out
243 ; FUNC-LABEL: {{^}}i32_ne:
246 define amdgpu_kernel void @i32_ne(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
248 %0 = icmp ne i32 %a, %b
249 %1 = sext i1 %0 to i32
250 store i32 %1, i32 addrspace(1)* %out
254 ; FUNC-LABEL: {{^}}i32_ugt:
257 define amdgpu_kernel void @i32_ugt(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
259 %0 = icmp ugt i32 %a, %b
260 %1 = sext i1 %0 to i32
261 store i32 %1, i32 addrspace(1)* %out
265 ; FUNC-LABEL: {{^}}i32_uge:
268 define amdgpu_kernel void @i32_uge(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
270 %0 = icmp uge i32 %a, %b
271 %1 = sext i1 %0 to i32
272 store i32 %1, i32 addrspace(1)* %out
276 ; FUNC-LABEL: {{^}}i32_ult:
279 define amdgpu_kernel void @i32_ult(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
281 %0 = icmp ult i32 %a, %b
282 %1 = sext i1 %0 to i32
283 store i32 %1, i32 addrspace(1)* %out
287 ; FUNC-LABEL: {{^}}i32_ule:
290 define amdgpu_kernel void @i32_ule(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
292 %0 = icmp ule i32 %a, %b
293 %1 = sext i1 %0 to i32
294 store i32 %1, i32 addrspace(1)* %out
298 ; FUNC-LABEL: {{^}}i32_sgt:
301 define amdgpu_kernel void @i32_sgt(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
303 %0 = icmp sgt i32 %a, %b
304 %1 = sext i1 %0 to i32
305 store i32 %1, i32 addrspace(1)* %out
309 ; FUNC-LABEL: {{^}}i32_sge:
312 define amdgpu_kernel void @i32_sge(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
314 %0 = icmp sge i32 %a, %b
315 %1 = sext i1 %0 to i32
316 store i32 %1, i32 addrspace(1)* %out
320 ; FUNC-LABEL: {{^}}i32_slt:
323 define amdgpu_kernel void @i32_slt(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
325 %0 = icmp slt i32 %a, %b
326 %1 = sext i1 %0 to i32
327 store i32 %1, i32 addrspace(1)* %out
331 ; FUNC-LABEL: {{^}}i32_sle:
334 define amdgpu_kernel void @i32_sle(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
336 %0 = icmp sle i32 %a, %b
337 %1 = sext i1 %0 to i32
338 store i32 %1, i32 addrspace(1)* %out
342 ; FIXME: This does 4 compares
343 ; FUNC-LABEL: {{^}}v3i32_eq:
344 ; GCN-DAG: v_cmp_eq_u32
345 ; GCN-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
346 ; GCN-DAG: v_cmp_eq_u32
347 ; GCN-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
348 ; GCN-DAG: v_cmp_eq_u32
349 ; GCN-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
351 define amdgpu_kernel void @v3i32_eq(<3 x i32> addrspace(1)* %out, <3 x i32> addrspace(1)* %ptra, <3 x i32> addrspace(1)* %ptrb) #0 {
352 %tid = call i32 @llvm.r600.read.tidig.x() nounwind readnone
353 %gep.a = getelementptr <3 x i32>, <3 x i32> addrspace(1)* %ptra, i32 %tid
354 %gep.b = getelementptr <3 x i32>, <3 x i32> addrspace(1)* %ptrb, i32 %tid
355 %gep.out = getelementptr <3 x i32>, <3 x i32> addrspace(1)* %out, i32 %tid
356 %a = load <3 x i32>, <3 x i32> addrspace(1)* %gep.a
357 %b = load <3 x i32>, <3 x i32> addrspace(1)* %gep.b
358 %cmp = icmp eq <3 x i32> %a, %b
359 %ext = sext <3 x i1> %cmp to <3 x i32>
360 store <3 x i32> %ext, <3 x i32> addrspace(1)* %gep.out
364 ; FUNC-LABEL: {{^}}v3i8_eq:
365 ; GCN-DAG: v_cmp_eq_u32
366 ; GCN-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
367 ; GCN-DAG: v_cmp_eq_u32
368 ; GCN-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
369 ; GCN-DAG: v_cmp_eq_u32
370 ; GCN-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
372 define amdgpu_kernel void @v3i8_eq(<3 x i8> addrspace(1)* %out, <3 x i8> addrspace(1)* %ptra, <3 x i8> addrspace(1)* %ptrb) #0 {
373 %tid = call i32 @llvm.r600.read.tidig.x() nounwind readnone
374 %gep.a = getelementptr <3 x i8>, <3 x i8> addrspace(1)* %ptra, i32 %tid
375 %gep.b = getelementptr <3 x i8>, <3 x i8> addrspace(1)* %ptrb, i32 %tid
376 %gep.out = getelementptr <3 x i8>, <3 x i8> addrspace(1)* %out, i32 %tid
377 %a = load <3 x i8>, <3 x i8> addrspace(1)* %gep.a
378 %b = load <3 x i8>, <3 x i8> addrspace(1)* %gep.b
379 %cmp = icmp eq <3 x i8> %a, %b
380 %ext = sext <3 x i1> %cmp to <3 x i8>
381 store <3 x i8> %ext, <3 x i8> addrspace(1)* %gep.out
385 ; Make sure we don't try to emit i1 setcc ops
386 ; FUNC-LABEL: setcc-i1
387 ; GCN: s_and_b32 [[AND:s[0-9]+]], s{{[0-9]+}}, 1
388 ; GCN: s_cmp_eq_u32 [[AND]], 0
389 define amdgpu_kernel void @setcc-i1(i32 %in) #0 {
390 %and = and i32 %in, 1
391 %cmp = icmp eq i32 %and, 0
392 br i1 %cmp, label %endif, label %if
399 ; FUNC-LABEL: setcc-i1-and-xor
400 ; GCN-DAG: v_cmp_nge_f32_e64 [[A:s\[[0-9]+:[0-9]+\]]], s{{[0-9]+}}, 0{{$}}
401 ; GCN-DAG: v_cmp_nle_f32_e64 [[B:s\[[0-9]+:[0-9]+\]]], s{{[0-9]+}}, 1.0
402 ; GCN: s_or_b64 s[2:3], [[A]], [[B]]
403 define amdgpu_kernel void @setcc-i1-and-xor(i32 addrspace(1)* %out, float %cond) #0 {
405 %tmp5 = fcmp oge float %cond, 0.000000e+00
406 %tmp7 = fcmp ole float %cond, 1.000000e+00
407 %tmp9 = and i1 %tmp5, %tmp7
408 %tmp11 = xor i1 %tmp9, 1
409 br i1 %tmp11, label %bb2, label %bb1
412 store i32 0, i32 addrspace(1)* %out
419 ; FUNC-LABEL: setcc_v2i32_expand
422 define amdgpu_kernel void @setcc_v2i32_expand(
423 <2 x i32> addrspace(1)* %a,
424 <2 x i32> addrspace(1)* %b,
425 <2 x i32> addrspace(1)* %c,
426 <2 x float> addrspace(1)* %r) {
428 %a.val = load <2 x i32>, <2 x i32> addrspace(1)* %a
429 %b.val = load <2 x i32>, <2 x i32> addrspace(1)* %b
430 %c.val = load <2 x i32>, <2 x i32> addrspace(1)* %c
432 %icmp.val.1 = icmp sgt <2 x i32> %a.val, <i32 1, i32 1>
433 %zext.val.1 = zext <2 x i1> %icmp.val.1 to <2 x i32>
434 %shl.val.1 = shl nuw <2 x i32> %zext.val.1, <i32 31, i32 31>
435 %xor.val.1 = xor <2 x i32> %shl.val.1, %b.val
436 %bitcast.val.1 = bitcast <2 x i32> %xor.val.1 to <2 x float>
437 %icmp.val.2 = icmp sgt <2 x i32> %c.val, <i32 1199570944, i32 1199570944>
438 %select.val.1 = select <2 x i1> %icmp.val.2, <2 x float> <float 1.000000e+00, float 1.000000e+00>, <2 x float> %bitcast.val.1
440 store <2 x float> %select.val.1, <2 x float> addrspace(1)* %r
444 ; FUNC-LABEL: setcc_v4i32_expand
449 define amdgpu_kernel void @setcc_v4i32_expand(
450 <4 x i32> addrspace(1)* %a,
451 <4 x i32> addrspace(1)* %b,
452 <4 x i32> addrspace(1)* %c,
453 <4 x float> addrspace(1)* %r) {
455 %a.val = load <4 x i32>, <4 x i32> addrspace(1)* %a
456 %b.val = load <4 x i32>, <4 x i32> addrspace(1)* %b
457 %c.val = load <4 x i32>, <4 x i32> addrspace(1)* %c
459 %icmp.val.1 = icmp sgt <4 x i32> %a.val, <i32 1, i32 1, i32 1, i32 1>
460 %zext.val.1 = zext <4 x i1> %icmp.val.1 to <4 x i32>
461 %shl.val.1 = shl nuw <4 x i32> %zext.val.1, <i32 31, i32 31, i32 31, i32 31>
462 %xor.val.1 = xor <4 x i32> %shl.val.1, %b.val
463 %bitcast.val.1 = bitcast <4 x i32> %xor.val.1 to <4 x float>
464 %icmp.val.2 = icmp sgt <4 x i32> %c.val, <i32 1199570944, i32 1199570944, i32 1199570944, i32 1199570944>
465 %select.val.1 = select <4 x i1> %icmp.val.2, <4 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, <4 x float> %bitcast.val.1
467 store <4 x float> %select.val.1, <4 x float> addrspace(1)* %r
471 attributes #0 = { nounwind }