1 ; RUN: llc -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.amdgcn.workitem.id.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
12 define amdgpu_kernel void @setcc_v2i32(ptr 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, ptr 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]}}
29 define amdgpu_kernel void @setcc_v4i32(ptr addrspace(1) %out, ptr addrspace(1) %in) #0 {
30 %b_ptr = getelementptr <4 x i32>, ptr addrspace(1) %in, i32 1
31 %a = load <4 x i32>, ptr addrspace(1) %in
32 %b = load <4 x i32>, ptr 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, ptr addrspace(1) %out
39 ;;;==========================================================================;;;
41 ;;;==========================================================================;;;
43 ; FUNC-LABEL: {{^}}f32_oeq:
46 define amdgpu_kernel void @f32_oeq(ptr 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, ptr addrspace(1) %out
54 ; FUNC-LABEL: {{^}}f32_ogt:
57 define amdgpu_kernel void @f32_ogt(ptr 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, ptr addrspace(1) %out
65 ; FUNC-LABEL: {{^}}f32_oge:
68 define amdgpu_kernel void @f32_oge(ptr 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, ptr addrspace(1) %out
76 ; FUNC-LABEL: {{^}}f32_olt:
79 define amdgpu_kernel void @f32_olt(ptr 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, ptr addrspace(1) %out
87 ; FUNC-LABEL: {{^}}f32_ole:
90 define amdgpu_kernel void @f32_ole(ptr 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, ptr addrspace(1) %out
98 ; FUNC-LABEL: {{^}}f32_one:
99 ; R600-DAG: SETGT_DX10
100 ; R600-DAG: SETGT_DX10
102 ; R600-DAG: SETNE_INT
104 ; GCN: v_cmp_lg_f32_e32 vcc
105 ; GCN-NEXT: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1, vcc
106 define amdgpu_kernel void @f32_one(ptr addrspace(1) %out, float %a, float %b) #0 {
108 %0 = fcmp one float %a, %b
109 %1 = sext i1 %0 to i32
110 store i32 %1, ptr addrspace(1) %out
114 ; FUNC-LABEL: {{^}}f32_ord:
115 ; R600-DAG: SETE_DX10
116 ; R600-DAG: SETE_DX10
118 ; R600-DAG: SETNE_INT
120 define amdgpu_kernel void @f32_ord(ptr addrspace(1) %out, float %a, float %b) #0 {
122 %0 = fcmp ord float %a, %b
123 %1 = sext i1 %0 to i32
124 store i32 %1, ptr addrspace(1) %out
128 ; FUNC-LABEL: {{^}}f32_ueq:
129 ; R600-DAG: SETGT_DX10
130 ; R600-DAG: SETGT_DX10
134 ; GCN: v_cmp_nlg_f32_e32 vcc
135 ; GCN-NEXT: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1, vcc
136 define amdgpu_kernel void @f32_ueq(ptr addrspace(1) %out, float %a, float %b) #0 {
138 %0 = fcmp ueq float %a, %b
139 %1 = sext i1 %0 to i32
140 store i32 %1, ptr addrspace(1) %out
144 ; FUNC-LABEL: {{^}}f32_ugt:
147 ; GCN: v_cmp_nle_f32_e32 vcc
148 ; GCN-NEXT: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1, vcc
149 define amdgpu_kernel void @f32_ugt(ptr addrspace(1) %out, float %a, float %b) #0 {
151 %0 = fcmp ugt float %a, %b
152 %1 = sext i1 %0 to i32
153 store i32 %1, ptr addrspace(1) %out
157 ; FUNC-LABEL: {{^}}f32_uge:
161 ; GCN: v_cmp_nlt_f32_e32 vcc
162 ; GCN-NEXT: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1, vcc
163 define amdgpu_kernel void @f32_uge(ptr addrspace(1) %out, float %a, float %b) #0 {
165 %0 = fcmp uge float %a, %b
166 %1 = sext i1 %0 to i32
167 store i32 %1, ptr addrspace(1) %out
171 ; FUNC-LABEL: {{^}}f32_ult:
175 ; GCN: v_cmp_nge_f32_e32 vcc
176 ; GCN-NEXT: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1, vcc
177 define amdgpu_kernel void @f32_ult(ptr addrspace(1) %out, float %a, float %b) #0 {
179 %0 = fcmp ult float %a, %b
180 %1 = sext i1 %0 to i32
181 store i32 %1, ptr addrspace(1) %out
185 ; FUNC-LABEL: {{^}}f32_ule:
189 ; GCN: v_cmp_ngt_f32_e32 vcc
190 ; GCN-NEXT: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1, vcc
191 define amdgpu_kernel void @f32_ule(ptr addrspace(1) %out, float %a, float %b) #0 {
193 %0 = fcmp ule float %a, %b
194 %1 = sext i1 %0 to i32
195 store i32 %1, ptr addrspace(1) %out
199 ; FUNC-LABEL: {{^}}f32_une:
202 define amdgpu_kernel void @f32_une(ptr addrspace(1) %out, float %a, float %b) #0 {
204 %0 = fcmp une float %a, %b
205 %1 = sext i1 %0 to i32
206 store i32 %1, ptr addrspace(1) %out
210 ; FUNC-LABEL: {{^}}f32_uno:
216 define amdgpu_kernel void @f32_uno(ptr addrspace(1) %out, float %a, float %b) #0 {
218 %0 = fcmp uno float %a, %b
219 %1 = sext i1 %0 to i32
220 store i32 %1, ptr addrspace(1) %out
224 ;;;==========================================================================;;;
225 ;; 32-bit integer comparisons
226 ;;;==========================================================================;;;
228 ; FUNC-LABEL: {{^}}i32_eq:
231 define amdgpu_kernel void @i32_eq(ptr addrspace(1) %out, i32 %a, i32 %b) #0 {
233 %0 = icmp eq i32 %a, %b
234 %1 = sext i1 %0 to i32
235 store i32 %1, ptr addrspace(1) %out
239 ; FUNC-LABEL: {{^}}i32_ne:
242 define amdgpu_kernel void @i32_ne(ptr addrspace(1) %out, i32 %a, i32 %b) #0 {
244 %0 = icmp ne i32 %a, %b
245 %1 = sext i1 %0 to i32
246 store i32 %1, ptr addrspace(1) %out
250 ; FUNC-LABEL: {{^}}i32_ugt:
253 define amdgpu_kernel void @i32_ugt(ptr addrspace(1) %out, i32 %a, i32 %b) #0 {
255 %0 = icmp ugt i32 %a, %b
256 %1 = sext i1 %0 to i32
257 store i32 %1, ptr addrspace(1) %out
261 ; FUNC-LABEL: {{^}}i32_uge:
264 define amdgpu_kernel void @i32_uge(ptr addrspace(1) %out, i32 %a, i32 %b) #0 {
266 %0 = icmp uge i32 %a, %b
267 %1 = sext i1 %0 to i32
268 store i32 %1, ptr addrspace(1) %out
272 ; FUNC-LABEL: {{^}}i32_ult:
275 define amdgpu_kernel void @i32_ult(ptr addrspace(1) %out, i32 %a, i32 %b) #0 {
277 %0 = icmp ult i32 %a, %b
278 %1 = sext i1 %0 to i32
279 store i32 %1, ptr addrspace(1) %out
283 ; FUNC-LABEL: {{^}}i32_ule:
286 define amdgpu_kernel void @i32_ule(ptr addrspace(1) %out, i32 %a, i32 %b) #0 {
288 %0 = icmp ule i32 %a, %b
289 %1 = sext i1 %0 to i32
290 store i32 %1, ptr addrspace(1) %out
294 ; FUNC-LABEL: {{^}}i32_sgt:
297 define amdgpu_kernel void @i32_sgt(ptr addrspace(1) %out, i32 %a, i32 %b) #0 {
299 %0 = icmp sgt i32 %a, %b
300 %1 = sext i1 %0 to i32
301 store i32 %1, ptr addrspace(1) %out
305 ; FUNC-LABEL: {{^}}i32_sge:
308 define amdgpu_kernel void @i32_sge(ptr addrspace(1) %out, i32 %a, i32 %b) #0 {
310 %0 = icmp sge i32 %a, %b
311 %1 = sext i1 %0 to i32
312 store i32 %1, ptr addrspace(1) %out
316 ; FUNC-LABEL: {{^}}i32_slt:
319 define amdgpu_kernel void @i32_slt(ptr addrspace(1) %out, i32 %a, i32 %b) #0 {
321 %0 = icmp slt i32 %a, %b
322 %1 = sext i1 %0 to i32
323 store i32 %1, ptr addrspace(1) %out
327 ; FUNC-LABEL: {{^}}i32_sle:
330 define amdgpu_kernel void @i32_sle(ptr addrspace(1) %out, i32 %a, i32 %b) #0 {
332 %0 = icmp sle i32 %a, %b
333 %1 = sext i1 %0 to i32
334 store i32 %1, ptr addrspace(1) %out
338 ; FIXME: This does 4 compares
339 ; FUNC-LABEL: {{^}}v3i32_eq:
340 ; GCN-DAG: v_cmp_eq_u32
341 ; GCN-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
342 ; GCN-DAG: v_cmp_eq_u32
343 ; GCN-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
344 ; GCN-DAG: v_cmp_eq_u32
345 ; GCN-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
347 define amdgpu_kernel void @v3i32_eq(ptr addrspace(1) %out, ptr addrspace(1) %ptra, ptr addrspace(1) %ptrb) #0 {
348 %tid = call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
349 %gep.a = getelementptr <3 x i32>, ptr addrspace(1) %ptra, i32 %tid
350 %gep.b = getelementptr <3 x i32>, ptr addrspace(1) %ptrb, i32 %tid
351 %gep.out = getelementptr <3 x i32>, ptr addrspace(1) %out, i32 %tid
352 %a = load <3 x i32>, ptr addrspace(1) %gep.a
353 %b = load <3 x i32>, ptr addrspace(1) %gep.b
354 %cmp = icmp eq <3 x i32> %a, %b
355 %ext = sext <3 x i1> %cmp to <3 x i32>
356 store <3 x i32> %ext, ptr addrspace(1) %gep.out
360 ; FUNC-LABEL: {{^}}v3i8_eq:
361 ; GCN-DAG: v_cmp_eq_u32
362 ; GCN-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
363 ; GCN-DAG: v_cmp_eq_u32
364 ; GCN-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
365 ; GCN-DAG: v_cmp_eq_u32
366 ; GCN-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
368 define amdgpu_kernel void @v3i8_eq(ptr addrspace(1) %out, ptr addrspace(1) %ptra, ptr addrspace(1) %ptrb) #0 {
369 %tid = call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
370 %gep.a = getelementptr <3 x i8>, ptr addrspace(1) %ptra, i32 %tid
371 %gep.b = getelementptr <3 x i8>, ptr addrspace(1) %ptrb, i32 %tid
372 %gep.out = getelementptr <3 x i8>, ptr addrspace(1) %out, i32 %tid
373 %a = load <3 x i8>, ptr addrspace(1) %gep.a
374 %b = load <3 x i8>, ptr addrspace(1) %gep.b
375 %cmp = icmp eq <3 x i8> %a, %b
376 %ext = sext <3 x i1> %cmp to <3 x i8>
377 store <3 x i8> %ext, ptr addrspace(1) %gep.out
381 ; Make sure we don't try to emit i1 setcc ops
382 ; FUNC-LABEL: setcc-i1
383 ; GCN: s_bitcmp0_b32 s{{[0-9]+}}, 0
384 define amdgpu_kernel void @setcc-i1(i32 %in) #0 {
385 %and = and i32 %in, 1
386 %cmp = icmp eq i32 %and, 0
387 br i1 %cmp, label %endif, label %if
394 ; FUNC-LABEL: setcc-i1-and-xor
395 ; GCN-DAG: v_cmp_nge_f32_e64 [[A:s\[[0-9]+:[0-9]+\]]], s{{[0-9]+}}, 0{{$}}
396 ; GCN-DAG: v_cmp_nle_f32_e64 [[B:s\[[0-9]+:[0-9]+\]]], s{{[0-9]+}}, 1.0
397 ; GCN: s_or_b64 s[2:3], [[A]], [[B]]
398 define amdgpu_kernel void @setcc-i1-and-xor(ptr addrspace(1) %out, float %cond) #0 {
400 %tmp5 = fcmp oge float %cond, 0.000000e+00
401 %tmp7 = fcmp ole float %cond, 1.000000e+00
402 %tmp9 = and i1 %tmp5, %tmp7
403 %tmp11 = xor i1 %tmp9, 1
404 br i1 %tmp11, label %bb2, label %bb1
407 store i32 0, ptr addrspace(1) %out
414 ; FUNC-LABEL: setcc_v2i32_expand
417 define amdgpu_kernel void @setcc_v2i32_expand(
421 ptr addrspace(1) %r) {
423 %a.val = load <2 x i32>, ptr addrspace(1) %a
424 %b.val = load <2 x i32>, ptr addrspace(1) %b
425 %c.val = load <2 x i32>, ptr addrspace(1) %c
427 %icmp.val.1 = icmp sgt <2 x i32> %a.val, <i32 1, i32 1>
428 %zext.val.1 = zext <2 x i1> %icmp.val.1 to <2 x i32>
429 %shl.val.1 = shl nuw <2 x i32> %zext.val.1, <i32 31, i32 31>
430 %xor.val.1 = xor <2 x i32> %shl.val.1, %b.val
431 %bitcast.val.1 = bitcast <2 x i32> %xor.val.1 to <2 x float>
432 %icmp.val.2 = icmp sgt <2 x i32> %c.val, <i32 1199570944, i32 1199570944>
433 %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
435 store <2 x float> %select.val.1, ptr addrspace(1) %r
439 ; FUNC-LABEL: setcc_v4i32_expand
444 define amdgpu_kernel void @setcc_v4i32_expand(
448 ptr addrspace(1) %r) {
450 %a.val = load <4 x i32>, ptr addrspace(1) %a
451 %b.val = load <4 x i32>, ptr addrspace(1) %b
452 %c.val = load <4 x i32>, ptr addrspace(1) %c
454 %icmp.val.1 = icmp sgt <4 x i32> %a.val, <i32 1, i32 1, i32 1, i32 1>
455 %zext.val.1 = zext <4 x i1> %icmp.val.1 to <4 x i32>
456 %shl.val.1 = shl nuw <4 x i32> %zext.val.1, <i32 31, i32 31, i32 31, i32 31>
457 %xor.val.1 = xor <4 x i32> %shl.val.1, %b.val
458 %bitcast.val.1 = bitcast <4 x i32> %xor.val.1 to <4 x float>
459 %icmp.val.2 = icmp sgt <4 x i32> %c.val, <i32 1199570944, i32 1199570944, i32 1199570944, i32 1199570944>
460 %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
462 store <4 x float> %select.val.1, ptr addrspace(1) %r
466 attributes #0 = { nounwind }