1 ; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc64le-unknown-unknown \
2 ; RUN: -enable-ppc-quad-precision -ppc-asm-full-reg-names < %s | FileCheck %s
3 ; RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple=powerpc64le-unknown-unknown \
4 ; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=CHECK-PWR8 \
5 ; RUN: -implicit-check-not "\<setb\>"
7 ; Test different patterns with type i64
9 ; select_cc lhs, rhs, -1, (zext (setcc lhs, rhs, setne)), setlt
10 define i64 @setb1(i64 %a, i64 %b) {
11 %t1 = icmp slt i64 %a, %b
12 %t2 = icmp ne i64 %a, %b
13 %t3 = zext i1 %t2 to i64
14 %t4 = select i1 %t1, i64 -1, i64 %t3
19 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
20 ; CHECK-NEXT: setb r3, cr0
25 ; CHECK-PWR8-LABEL: setb1
28 ; CHECK-PWR8-DAG: cmpd
29 ; CHECK-PWR8-DAG: addic
30 ; CHECK-PWR8-DAG: subfe
35 ; select_cc lhs, rhs, -1, (zext (setcc rhs, lhs, setne)), setgt
36 define i64 @setb2(i64 %a, i64 %b) {
37 %t1 = icmp sgt i64 %b, %a
38 %t2 = icmp ne i64 %a, %b
39 %t3 = zext i1 %t2 to i64
40 %t4 = select i1 %t1, i64 -1, i64 %t3
45 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
46 ; CHECK-NEXT: setb r3, cr0
51 ; CHECK-PWR8-LABEL: setb2
54 ; CHECK-PWR8-DAG: cmpd
55 ; CHECK-PWR8-DAG: addic
56 ; CHECK-PWR8-DAG: subfe
61 ; select_cc lhs, rhs, -1, (zext (setcc rhs, lhs, setne)), setlt
62 define i64 @setb3(i64 %a, i64 %b) {
63 %t1 = icmp slt i64 %a, %b
64 %t2 = icmp ne i64 %b, %a
65 %t3 = zext i1 %t2 to i64
66 %t4 = select i1 %t1, i64 -1, i64 %t3
71 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
72 ; CHECK-NEXT: setb r3, cr0
77 ; CHECK-PWR8-LABEL: setb3
80 ; CHECK-PWR8-DAG: cmpd
81 ; CHECK-PWR8-DAG: addic
82 ; CHECK-PWR8-DAG: subfe
87 ; select_cc lhs, rhs, -1, (zext (setcc lhs, rhs, setne)), setgt
88 define i64 @setb4(i64 %a, i64 %b) {
89 %t1 = icmp sgt i64 %b, %a
90 %t2 = icmp ne i64 %b, %a
91 %t3 = zext i1 %t2 to i64
92 %t4 = select i1 %t1, i64 -1, i64 %t3
97 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
98 ; CHECK-NEXT: setb r3, cr0
103 ; CHECK-PWR8-LABEL: setb4
104 ; CHECK-PWR8-DAG: xor
106 ; CHECK-PWR8-DAG: cmpd
107 ; CHECK-PWR8-DAG: addic
108 ; CHECK-PWR8-DAG: subfe
113 ; select_cc lhs, rhs, -1, (zext (setcc lhs, rhs, setgt)), setlt
114 define i64 @setb5(i64 %a, i64 %b) {
115 %t1 = icmp slt i64 %a, %b
116 %t2 = icmp sgt i64 %a, %b
117 %t3 = zext i1 %t2 to i64
118 %t4 = select i1 %t1, i64 -1, i64 %t3
120 ; CHECK-LABEL: setb5:
124 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
125 ; CHECK-NEXT: setb r3, cr0
131 ; CHECK-PWR8-LABEL: setb5
132 ; CHECK-PWR8-DAG: sradi
133 ; CHECK-PWR8-DAG: rldicl
135 ; CHECK-PWR8-DAG: cmpd
136 ; CHECK-PWR8-DAG: subfc
137 ; CHECK-PWR8-DAG: adde
138 ; CHECK-PWR8-DAG: xori
143 ; select_cc lhs, rhs, -1, (zext (setcc rhs, lhs, setgt)), setgt
144 define i64 @setb6(i64 %a, i64 %b) {
145 %t1 = icmp sgt i64 %b, %a
146 %t2 = icmp sgt i64 %a, %b
147 %t3 = zext i1 %t2 to i64
148 %t4 = select i1 %t1, i64 -1, i64 %t3
150 ; CHECK-LABEL: setb6:
154 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
155 ; CHECK-NEXT: setb r3, cr0
161 ; CHECK-PWR8-LABEL: setb6
162 ; CHECK-PWR8-DAG: sradi
163 ; CHECK-PWR8-DAG: rldicl
165 ; CHECK-PWR8-DAG: cmpd
166 ; CHECK-PWR8-DAG: subfc
167 ; CHECK-PWR8-DAG: adde
168 ; CHECK-PWR8-DAG: xori
173 ; select_cc lhs, rhs, -1, (zext (setcc rhs, lhs, setlt)), setlt
174 define i64 @setb7(i64 %a, i64 %b) {
175 %t1 = icmp slt i64 %a, %b
176 %t2 = icmp slt i64 %b, %a
177 %t3 = zext i1 %t2 to i64
178 %t4 = select i1 %t1, i64 -1, i64 %t3
180 ; CHECK-LABEL: setb7:
184 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
185 ; CHECK-NEXT: setb r3, cr0
191 ; CHECK-PWR8-LABEL: setb7
192 ; CHECK-PWR8-DAG: sradi
193 ; CHECK-PWR8-DAG: rldicl
195 ; CHECK-PWR8-DAG: cmpd
196 ; CHECK-PWR8-DAG: subfc
197 ; CHECK-PWR8-DAG: adde
198 ; CHECK-PWR8-DAG: xori
203 ; select_cc lhs, rhs, -1, (zext (setcc lhs, rhs, setlt)), setgt
204 define i64 @setb8(i64 %a, i64 %b) {
205 %t1 = icmp sgt i64 %b, %a
206 %t2 = icmp slt i64 %b, %a
207 %t3 = zext i1 %t2 to i64
208 %t4 = select i1 %t1, i64 -1, i64 %t3
210 ; CHECK-LABEL: setb8:
214 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
215 ; CHECK-NEXT: setb r3, cr0
221 ; CHECK-PWR8-LABEL: setb8
222 ; CHECK-PWR8-DAG: sradi
223 ; CHECK-PWR8-DAG: rldicl
225 ; CHECK-PWR8-DAG: cmpd
226 ; CHECK-PWR8-DAG: subfc
227 ; CHECK-PWR8-DAG: adde
228 ; CHECK-PWR8-DAG: xori
233 ; select_cc lhs, rhs, 1, (sext (setcc lhs, rhs, setne)), setgt
234 define i64 @setb9(i64 %a, i64 %b) {
235 %t1 = icmp sgt i64 %a, %b
236 %t2 = icmp ne i64 %a, %b
237 %t3 = sext i1 %t2 to i64
238 %t4 = select i1 %t1, i64 1, i64 %t3
240 ; CHECK-LABEL: setb9:
243 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
244 ; CHECK-NEXT: setb r3, cr0
249 ; CHECK-PWR8-LABEL: setb9
250 ; CHECK-PWR8-DAG: xor
252 ; CHECK-PWR8-DAG: cmpd
253 ; CHECK-PWR8-DAG: subfic
254 ; CHECK-PWR8-DAG: subfe
259 ; select_cc lhs, rhs, 1, (sext (setcc rhs, lhs, setne)), setlt
260 define i64 @setb10(i64 %a, i64 %b) {
261 %t1 = icmp slt i64 %b, %a
262 %t2 = icmp ne i64 %a, %b
263 %t3 = sext i1 %t2 to i64
264 %t4 = select i1 %t1, i64 1, i64 %t3
266 ; CHECK-LABEL: setb10:
269 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
270 ; CHECK-NEXT: setb r3, cr0
275 ; CHECK-PWR8-LABEL: setb10
276 ; CHECK-PWR8-DAG: xor
278 ; CHECK-PWR8-DAG: cmpd
279 ; CHECK-PWR8-DAG: subfic
280 ; CHECK-PWR8-DAG: subfe
285 ; select_cc lhs, rhs, 1, (sext (setcc rhs, lhs, setne)), setgt
286 define i64 @setb11(i64 %a, i64 %b) {
287 %t1 = icmp sgt i64 %a, %b
288 %t2 = icmp ne i64 %b, %a
289 %t3 = sext i1 %t2 to i64
290 %t4 = select i1 %t1, i64 1, i64 %t3
292 ; CHECK-LABEL: setb11:
295 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
296 ; CHECK-NEXT: setb r3, cr0
301 ; CHECK-PWR8-LABEL: setb11
302 ; CHECK-PWR8-DAG: xor
304 ; CHECK-PWR8-DAG: cmpd
305 ; CHECK-PWR8-DAG: subfic
306 ; CHECK-PWR8-DAG: subfe
311 ; select_cc lhs, rhs, 1, (sext (setcc lhs, rhs, setne)), setlt
312 define i64 @setb12(i64 %a, i64 %b) {
313 %t1 = icmp slt i64 %b, %a
314 %t2 = icmp ne i64 %b, %a
315 %t3 = sext i1 %t2 to i64
316 %t4 = select i1 %t1, i64 1, i64 %t3
318 ; CHECK-LABEL: setb12:
321 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
322 ; CHECK-NEXT: setb r3, cr0
327 ; CHECK-PWR8-LABEL: setb12
328 ; CHECK-PWR8-DAG: xor
330 ; CHECK-PWR8-DAG: cmpd
331 ; CHECK-PWR8-DAG: subfic
332 ; CHECK-PWR8-DAG: subfe
337 ; select_cc lhs, rhs, 1, (sext (setcc lhs, rhs, setlt)), setgt
338 define i64 @setb13(i64 %a, i64 %b) {
339 %t1 = icmp sgt i64 %a, %b
340 %t2 = icmp slt i64 %a, %b
341 %t3 = sext i1 %t2 to i64
342 %t4 = select i1 %t1, i64 1, i64 %t3
344 ; CHECK-LABEL: setb13:
348 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
349 ; CHECK-NEXT: setb r3, cr0
356 ; CHECK-PWR8-LABEL: setb13
357 ; CHECK-PWR8-DAG: sradi
358 ; CHECK-PWR8-DAG: rldicl
360 ; CHECK-PWR8-DAG: cmpd
361 ; CHECK-PWR8-DAG: subfc
362 ; CHECK-PWR8-DAG: adde
363 ; CHECK-PWR8-DAG: xori
364 ; CHECK-PWR8-DAG: neg
369 ; select_cc lhs, rhs, 1, (sext (setcc rhs, lhs, setlt)), setlt
370 define i64 @setb14(i64 %a, i64 %b) {
371 %t1 = icmp slt i64 %b, %a
372 %t2 = icmp slt i64 %a, %b
373 %t3 = sext i1 %t2 to i64
374 %t4 = select i1 %t1, i64 1, i64 %t3
376 ; CHECK-LABEL: setb14:
380 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
381 ; CHECK-NEXT: setb r3, cr0
388 ; CHECK-PWR8-LABEL: setb14
389 ; CHECK-PWR8-DAG: sradi
390 ; CHECK-PWR8-DAG: rldicl
392 ; CHECK-PWR8-DAG: cmpd
393 ; CHECK-PWR8-DAG: subfc
394 ; CHECK-PWR8-DAG: adde
395 ; CHECK-PWR8-DAG: xori
396 ; CHECK-PWR8-DAG: neg
401 ; select_cc lhs, rhs, 1, (sext (setcc rhs, lhs, setgt)), setgt
402 define i64 @setb15(i64 %a, i64 %b) {
403 %t1 = icmp sgt i64 %a, %b
404 %t2 = icmp sgt i64 %b, %a
405 %t3 = sext i1 %t2 to i64
406 %t4 = select i1 %t1, i64 1, i64 %t3
408 ; CHECK-LABEL: setb15:
412 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
413 ; CHECK-NEXT: setb r3, cr0
420 ; CHECK-PWR8-LABEL: setb15
421 ; CHECK-PWR8-DAG: sradi
422 ; CHECK-PWR8-DAG: rldicl
424 ; CHECK-PWR8-DAG: cmpd
425 ; CHECK-PWR8-DAG: subfc
426 ; CHECK-PWR8-DAG: adde
427 ; CHECK-PWR8-DAG: xori
428 ; CHECK-PWR8-DAG: neg
433 ; select_cc lhs, rhs, 1, (sext (setcc lhs, rhs, setgt)), setlt
434 define i64 @setb16(i64 %a, i64 %b) {
435 %t1 = icmp slt i64 %b, %a
436 %t2 = icmp sgt i64 %b, %a
437 %t3 = sext i1 %t2 to i64
438 %t4 = select i1 %t1, i64 1, i64 %t3
440 ; CHECK-LABEL: setb16:
444 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
445 ; CHECK-NEXT: setb r3, cr0
452 ; CHECK-PWR8-LABEL: setb16
453 ; CHECK-PWR8-DAG: sradi
454 ; CHECK-PWR8-DAG: rldicl
456 ; CHECK-PWR8-DAG: cmpd
457 ; CHECK-PWR8-DAG: subfc
458 ; CHECK-PWR8-DAG: adde
459 ; CHECK-PWR8-DAG: xori
460 ; CHECK-PWR8-DAG: neg
465 ; select_cc lhs, rhs, 0, (select_cc lhs, rhs, 1, -1, setgt), seteq
466 define i64 @setb17(i64 %a, i64 %b) {
467 %t1 = icmp eq i64 %a, %b
468 %t2 = icmp sgt i64 %a, %b
469 %t3 = select i1 %t2, i64 1, i64 -1
470 %t4 = select i1 %t1, i64 0, i64 %t3
472 ; CHECK-LABEL: setb17:
476 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
477 ; CHECK-NEXT: setb r3, cr0
480 ; CHECK-PWR8-LABEL: setb17
488 ; select_cc lhs, rhs, 0, (select_cc rhs, lhs, 1, -1, setgt), seteq
489 define i64 @setb18(i64 %a, i64 %b) {
490 %t1 = icmp eq i64 %b, %a
491 %t2 = icmp sgt i64 %a, %b
492 %t3 = select i1 %t2, i64 1, i64 -1
493 %t4 = select i1 %t1, i64 0, i64 %t3
495 ; CHECK-LABEL: setb18:
499 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
500 ; CHECK-NEXT: setb r3, cr0
503 ; CHECK-PWR8-LABEL: setb18
511 ; select_cc lhs, rhs, 0, (select_cc rhs, lhs, 1, -1, setlt), seteq
512 define i64 @setb19(i64 %a, i64 %b) {
513 %t1 = icmp eq i64 %a, %b
514 %t2 = icmp slt i64 %b, %a
515 %t3 = select i1 %t2, i64 1, i64 -1
516 %t4 = select i1 %t1, i64 0, i64 %t3
518 ; CHECK-LABEL: setb19:
522 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
523 ; CHECK-NEXT: setb r3, cr0
526 ; CHECK-PWR8-LABEL: setb19
534 ; select_cc lhs, rhs, 0, (select_cc lhs, rhs, 1, -1, setlt), seteq
535 define i64 @setb20(i64 %a, i64 %b) {
536 %t1 = icmp eq i64 %b, %a
537 %t2 = icmp slt i64 %b, %a
538 %t3 = select i1 %t2, i64 1, i64 -1
539 %t4 = select i1 %t1, i64 0, i64 %t3
541 ; CHECK-LABEL: setb20:
545 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
546 ; CHECK-NEXT: setb r3, cr0
549 ; CHECK-PWR8-LABEL: setb20
557 ; select_cc lhs, rhs, 0, (select_cc lhs, rhs, -1, 1, setlt), seteq
558 define i64 @setb21(i64 %a, i64 %b) {
559 %t1 = icmp eq i64 %a, %b
560 %t2 = icmp slt i64 %a, %b
561 %t3 = select i1 %t2, i64 -1, i64 1
562 %t4 = select i1 %t1, i64 0, i64 %t3
564 ; CHECK-LABEL: setb21:
568 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
569 ; CHECK-NEXT: setb r3, cr0
572 ; CHECK-PWR8-LABEL: setb21
580 ; select_cc lhs, rhs, 0, (select_cc rhs, lhs, -1, 1, setlt), seteq
581 define i64 @setb22(i64 %a, i64 %b) {
582 %t1 = icmp eq i64 %b, %a
583 %t2 = icmp slt i64 %a, %b
584 %t3 = select i1 %t2, i64 -1, i64 1
585 %t4 = select i1 %t1, i64 0, i64 %t3
587 ; CHECK-LABEL: setb22:
591 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
592 ; CHECK-NEXT: setb r3, cr0
595 ; CHECK-PWR8-LABEL: setb22
603 ; select_cc lhs, rhs, 0, (select_cc rhs, lhs, -1, 1, setgt), seteq
604 define i64 @setb23(i64 %a, i64 %b) {
605 %t1 = icmp eq i64 %a, %b
606 %t2 = icmp sgt i64 %b, %a
607 %t3 = select i1 %t2, i64 -1, i64 1
608 %t4 = select i1 %t1, i64 0, i64 %t3
610 ; CHECK-LABEL: setb23:
614 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
615 ; CHECK-NEXT: setb r3, cr0
618 ; CHECK-PWR8-LABEL: setb23
626 ; select_cc lhs, rhs, 0, (select_cc lhs, rhs, -1, 1, setgt), seteq
627 define i64 @setb24(i64 %a, i64 %b) {
628 %t1 = icmp eq i64 %b, %a
629 %t2 = icmp sgt i64 %b, %a
630 %t3 = select i1 %t2, i64 -1, i64 1
631 %t4 = select i1 %t1, i64 0, i64 %t3
633 ; CHECK-LABEL: setb24:
637 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
638 ; CHECK-NEXT: setb r3, cr0
641 ; CHECK-PWR8-LABEL: setb24
648 ; end all patterns testing for i64
650 ; Test with swapping the input parameters
652 ; select_cc lhs, rhs, -1, (zext (setcc lhs, rhs, setne)), setlt
653 define i64 @setb25(i64 %a, i64 %b) {
654 %t1 = icmp slt i64 %b, %a
655 %t2 = icmp ne i64 %b, %a
656 %t3 = zext i1 %t2 to i64
657 %t4 = select i1 %t1, i64 -1, i64 %t3
659 ; CHECK-LABEL: setb25:
663 ; CHECK: cmpd {{c?r?(0, )?}}r4, r3
664 ; CHECK-NEXT: setb r3, cr0
669 ; CHECK-PWR8-LABEL: setb25
670 ; CHECK-PWR8-DAG: cmpd
671 ; CHECK-PWR8-DAG: addic
672 ; CHECK-PWR8-DAG: subfe
677 ; select_cc lhs, rhs, -1, (zext (setcc rhs, lhs, setne)), setgt
678 define i64 @setb26(i64 %a, i64 %b) {
679 %t1 = icmp sgt i64 %a, %b
680 %t2 = icmp ne i64 %b, %a
681 %t3 = zext i1 %t2 to i64
682 %t4 = select i1 %t1, i64 -1, i64 %t3
684 ; CHECK-LABEL: setb26:
687 ; CHECK: cmpd {{c?r?(0, )?}}r4, r3
688 ; CHECK-NEXT: setb r3, cr0
693 ; CHECK-PWR8-LABEL: setb26
694 ; CHECK-PWR8-DAG: cmpd
695 ; CHECK-PWR8-DAG: addic
696 ; CHECK-PWR8-DAG: subfe
701 ; Test with different scalar integer type for selected value
702 ; i32/i16/i8 rather than i64 above
704 ; select_cc lhs, rhs, -1, (zext (setcc rhs, lhs, setne)), setlt
705 define i64 @setb27(i64 %a, i64 %b) {
706 %t1 = icmp slt i64 %a, %b
707 %t2 = icmp ne i64 %b, %a
708 %t3 = zext i1 %t2 to i32
709 %t4 = select i1 %t1, i32 -1, i32 %t3
710 %t5 = sext i32 %t4 to i64
712 ; CHECK-LABEL: setb27:
715 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
716 ; CHECK-NEXT: setb r3, cr0
722 ; CHECK-PWR8-LABEL: setb27
723 ; CHECK-PWR8-DAG: cmpd
724 ; CHECK-PWR8-DAG: addic
725 ; CHECK-PWR8-DAG: subfe
731 ; select_cc lhs, rhs, -1, (zext (setcc lhs, rhs, setne)), setgt
732 define i64 @setb28(i64 %a, i64 %b) {
733 %t1 = icmp sgt i64 %b, %a
734 %t2 = icmp ne i64 %b, %a
735 %t3 = zext i1 %t2 to i16
736 %t4 = select i1 %t1, i16 -1, i16 %t3
737 %t5 = sext i16 %t4 to i64
739 ; CHECK-LABEL: setb28:
742 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
743 ; CHECK-NEXT: setb r3, cr0
749 ; CHECK-PWR8-LABEL: setb28
750 ; CHECK-PWR8-DAG: cmpd
751 ; CHECK-PWR8-DAG: addic
752 ; CHECK-PWR8-DAG: subfe
758 ; select_cc lhs, rhs, -1, (zext (setcc lhs, rhs, setgt)), setlt
759 define i64 @setb29(i64 %a, i64 %b) {
760 %t1 = icmp slt i64 %a, %b
761 %t2 = icmp sgt i64 %a, %b
762 %t3 = zext i1 %t2 to i8
763 %t4 = select i1 %t1, i8 -1, i8 %t3
764 %t5 = zext i8 %t4 to i64
766 ; CHECK-LABEL: setb29:
770 ; CHECK: cmpd {{c?r?(0, )?}}r3, r4
771 ; CHECK-NEXT: setb r3, cr0
777 ; CHECK-PWR8-LABEL: setb29
778 ; CHECK-PWR8-DAG: cmpd
779 ; CHECK-PWR8-DAG: subfc
780 ; CHECK-PWR8-DAG: adde
785 ; Testings to cover different comparison opcodes
786 ; Test with integer type i32/i16/i8 for input parameter
788 ; select_cc lhs, rhs, -1, (zext (setcc lhs, rhs, setne)), setlt
789 define i64 @setbsw1(i32 %a, i32 %b) {
790 %t1 = icmp slt i32 %a, %b
791 %t2 = icmp ne i32 %a, %b
792 %t3 = zext i1 %t2 to i64
793 %t4 = select i1 %t1, i64 -1, i64 %t3
795 ; CHECK-LABEL: setbsw1:
798 ; CHECK: cmpw {{c?r?(0, )?}}r3, r4
799 ; CHECK-NEXT: setb r3, cr0
805 ; CHECK-PWR8-LABEL: setbsw1
806 ; CHECK-PWR8-DAG: cntlzw
807 ; CHECK-PWR8-DAG: cmpw
808 ; CHECK-PWR8-DAG: srwi
809 ; CHECK-PWR8-DAG: xori
814 ; select_cc lhs, rhs, -1, (zext (setcc rhs, lhs, setne)), setgt
815 define i64 @setbsw2(i32 %a, i32 %b) {
816 %t1 = icmp sgt i32 %b, %a
817 %t2 = icmp ne i32 %a, %b
818 %t3 = zext i1 %t2 to i64
819 %t4 = select i1 %t1, i64 -1, i64 %t3
821 ; CHECK-LABEL: setbsw2:
824 ; CHECK: cmpw {{c?r?(0, )?}}r3, r4
825 ; CHECK-NEXT: setb r3, cr0
831 ; CHECK-PWR8-LABEL: setbsw2
832 ; CHECK-PWR8-DAG: cntlzw
833 ; CHECK-PWR8-DAG: cmpw
834 ; CHECK-PWR8-DAG: srwi
835 ; CHECK-PWR8-DAG: xori
840 ; select_cc lhs, rhs, 0, (select_cc rhs, lhs, -1, 1, setgt), seteq
841 define i64 @setbsw3(i32 %a, i32 %b) {
842 %t1 = icmp eq i32 %a, %b
843 %t2 = icmp sgt i32 %b, %a
844 %t3 = select i1 %t2, i64 -1, i64 1
845 %t4 = select i1 %t1, i64 0, i64 %t3
847 ; CHECK-LABEL: setbsw3:
849 ; CHECK: cmpw {{c?r?(0, )?}}r3, r4
850 ; CHECK-NEXT: setb r3, cr0
855 ; CHECK-PWR8-LABEL: setbsw3
863 ; select_cc lhs, rhs, -1, (zext (setcc rhs, lhs, setne)), setlt
864 define i64 @setbsh1(i16 signext %a, i16 signext %b) {
865 %t1 = icmp slt i16 %a, %b
866 %t2 = icmp ne i16 %b, %a
867 %t3 = zext i1 %t2 to i64
868 %t4 = select i1 %t1, i64 -1, i64 %t3
870 ; CHECK-LABEL: setbsh1:
873 ; CHECK: cmpw {{c?r?(0, )?}}r3, r4
874 ; CHECK-NEXT: setb r3, cr0
880 ; CHECK-PWR8-LABEL: setbsh1
881 ; CHECK-PWR8-DAG: cntlzw
882 ; CHECK-PWR8-DAG: cmpw
883 ; CHECK-PWR8-DAG: srwi
884 ; CHECK-PWR8-DAG: xori
889 ; select_cc lhs, rhs, -1, (zext (setcc lhs, rhs, setne)), setgt
890 define i64 @setbsh2(i16 signext %a, i16 signext %b) {
891 %t1 = icmp sgt i16 %b, %a
892 %t2 = icmp ne i16 %b, %a
893 %t3 = zext i1 %t2 to i64
894 %t4 = select i1 %t1, i64 -1, i64 %t3
896 ; CHECK-LABEL: setbsh2:
899 ; CHECK: cmpw {{c?r?(0, )?}}r3, r4
900 ; CHECK-NEXT: setb r3, cr0
906 ; CHECK-PWR8-LABEL: setbsh2
907 ; CHECK-PWR8-DAG: cmpw
908 ; CHECK-PWR8-DAG: cntlzw
909 ; CHECK-PWR8-DAG: srwi
910 ; CHECK-PWR8-DAG: xori
915 ; select_cc lhs, rhs, -1, (zext (setcc lhs, rhs, setgt)), setlt
916 define i64 @setbsc1(i8 %a, i8 %b) {
917 %t1 = icmp slt i8 %a, %b
918 %t2 = icmp sgt i8 %a, %b
919 %t3 = zext i1 %t2 to i64
920 %t4 = select i1 %t1, i64 -1, i64 %t3
922 ; CHECK-LABEL: setbsc1:
923 ; CHECK-DAG: extsb [[RA:r[0-9]+]], r3
924 ; CHECK-DAG: extsb [[RB:r[0-9]+]], r4
927 ; CHECK: cmpw {{c?r?(0, )?}}[[RA]], [[RB]]
928 ; CHECK-NEXT: setb r3, cr0
932 ; CHECK-PWR8-LABEL: setbsc1
933 ; CHECK-PWR8-DAG: extsb
934 ; CHECK-PWR8-DAG: extsb
935 ; CHECK-PWR8-DAG: extsw
936 ; CHECK-PWR8-DAG: extsw
937 ; CHECK-PWR8-DAG: cmpw
938 ; CHECK-PWR8-DAG: rldicl
943 ; select_cc lhs, rhs, -1, (zext (setcc rhs, lhs, setgt)), setgt
944 define i64 @setbsc2(i8 %a, i8 %b) {
945 %t1 = icmp sgt i8 %b, %a
946 %t2 = icmp sgt i8 %a, %b
947 %t3 = zext i1 %t2 to i64
948 %t4 = select i1 %t1, i64 -1, i64 %t3
950 ; CHECK-LABEL: setbsc2:
951 ; CHECK-DAG: extsb [[RA:r[0-9]+]], r3
952 ; CHECK-DAG: extsb [[RB:r[0-9]+]], r4
955 ; CHECK: cmpw {{c?r?(0, )?}}[[RA]], [[RB]]
956 ; CHECK-NEXT: setb r3, cr0
960 ; CHECK-PWR8-LABEL: setbsc2
961 ; CHECK-PWR8-DAG: extsb
962 ; CHECK-PWR8-DAG: extsb
963 ; CHECK-PWR8-DAG: extsw
964 ; CHECK-PWR8-DAG: extsw
965 ; CHECK-PWR8-DAG: cmpw
966 ; CHECK-PWR8-DAG: rldicl
971 ; select_cc lhs, rhs, -1, (zext (setcc rhs, lhs, setlt)), setlt
972 define i64 @setbsc3(i4 %a, i4 %b) {
973 %t1 = icmp slt i4 %a, %b
974 %t2 = icmp slt i4 %b, %a
975 %t3 = zext i1 %t2 to i64
976 %t4 = select i1 %t1, i64 -1, i64 %t3
978 ; CHECK-LABEL: setbsc3:
979 ; CHECK-DAG: slwi [[RA:r[0-9]+]], r3, 28
980 ; CHECK-DAG: slwi [[RB:r[0-9]+]], r4, 28
982 ; CHECK-DAG: srawi [[RA1:r[0-9]+]], [[RA]], 28
983 ; CHECK-DAG: srawi [[RB1:r[0-9]+]], [[RB]], 28
985 ; CHECK: cmpw {{c?r?(0, )?}}[[RA1]], [[RB1]]
986 ; CHECK-NEXT: setb r3, cr0
990 ; CHECK-PWR8-LABEL: setbsc3
991 ; CHECK-PWR8-DAG: slwi
992 ; CHECK-PWR8-DAG: slwi
993 ; CHECK-PWR8-DAG: srawi
994 ; CHECK-PWR8-DAG: srawi
995 ; CHECK-PWR8-DAG: extsw
996 ; CHECK-PWR8-DAG: extsw
997 ; CHECK-PWR8-DAG: cmpw
998 ; CHECK-PWR8-DAG: rldicl
1003 ; Test with unsigned integer type i64/i32/i16/i8 for input parameter
1005 ; select_cc lhs, rhs, -1, (zext (setcc lhs, rhs, setult)), setugt
1006 define i64 @setbud1(i64 %a, i64 %b) {
1007 %t1 = icmp ugt i64 %b, %a
1008 %t2 = icmp ult i64 %b, %a
1009 %t3 = zext i1 %t2 to i64
1010 %t4 = select i1 %t1, i64 -1, i64 %t3
1012 ; CHECK-LABEL: setbud1:
1014 ; CHECK: cmpld {{c?r?(0, )?}}r3, r4
1015 ; CHECK-NEXT: setb r3, cr0
1021 ; CHECK-PWR8-LABEL: setbud1
1022 ; CHECK-PWR8-DAG: subfc
1023 ; CHECK-PWR8-DAG: subfe
1024 ; CHECK-PWR8-DAG: cmpld
1025 ; CHECK-PWR8-DAG: neg
1030 ; select_cc lhs, rhs, 1, (sext (setcc lhs, rhs, setne)), setugt
1031 define i64 @setbud2(i64 %a, i64 %b) {
1032 %t1 = icmp ugt i64 %a, %b
1033 %t2 = icmp ne i64 %a, %b
1034 %t3 = sext i1 %t2 to i64
1035 %t4 = select i1 %t1, i64 1, i64 %t3
1037 ; CHECK-LABEL: setbud2:
1040 ; CHECK: cmpld {{c?r?(0, )?}}r3, r4
1041 ; CHECK-NEXT: setb r3, cr0
1046 ; CHECK-PWR8-LABEL: setbud2
1047 ; CHECK-PWR8-DAG: cmpld
1048 ; CHECK-PWR8-DAG: subfic
1049 ; CHECK-PWR8-DAG: subfe
1054 ; select_cc lhs, rhs, 0, (select_cc lhs, rhs, -1, 1, setugt), seteq
1055 define i64 @setbud3(i64 %a, i64 %b) {
1056 %t1 = icmp eq i64 %b, %a
1057 %t2 = icmp ugt i64 %b, %a
1058 %t3 = select i1 %t2, i64 -1, i64 1
1059 %t4 = select i1 %t1, i64 0, i64 %t3
1061 ; CHECK-LABEL: setbud3:
1063 ; CHECK: cmpld {{c?r?(0, )?}}r3, r4
1064 ; CHECK-NEXT: setb r3, cr0
1068 ; CHECK-PWR8-LABEL: setbud3
1069 ; CHECK-PWR8-DAG: cmpld
1070 ; CHECK-PWR8-DAG: li
1071 ; CHECK-PWR8-DAG: li
1077 ; select_cc lhs, rhs, 1, (sext (setcc rhs, lhs, setne)), setult
1078 define i64 @setbuw1(i32 %a, i32 %b) {
1079 %t1 = icmp ult i32 %b, %a
1080 %t2 = icmp ne i32 %a, %b
1081 %t3 = sext i1 %t2 to i64
1082 %t4 = select i1 %t1, i64 1, i64 %t3
1084 ; CHECK-LABEL: setbuw1:
1087 ; CHECK: cmplw {{c?r?(0, )?}}r3, r4
1088 ; CHECK-NEXT: setb r3, cr0
1095 ; CHECK-PWR8-LABEL: setbuw1
1096 ; CHECK-PWR8-DAG: cntlzw
1097 ; CHECK-PWR8-DAG: cmplw
1098 ; CHECK-PWR8-DAG: srwi
1099 ; CHECK-PWR8-DAG: xori
1100 ; CHECK-PWR8-DAG: neg
1105 ; select_cc lhs, rhs, 1, (sext (setcc rhs, lhs, setne)), setugt
1106 define i64 @setbuw2(i32 %a, i32 %b) {
1107 %t1 = icmp ugt i32 %a, %b
1108 %t2 = icmp ne i32 %b, %a
1109 %t3 = sext i1 %t2 to i64
1110 %t4 = select i1 %t1, i64 1, i64 %t3
1112 ; CHECK-LABEL: setbuw2:
1115 ; CHECK: cmplw {{c?r?(0, )?}}r3, r4
1116 ; CHECK-NEXT: setb r3, cr0
1123 ; CHECK-PWR8-LABEL: setbuw2
1124 ; CHECK-PWR8-DAG: cntlzw
1125 ; CHECK-PWR8-DAG: cmplw
1126 ; CHECK-PWR8-DAG: srwi
1127 ; CHECK-PWR8-DAG: xori
1128 ; CHECK-PWR8-DAG: neg
1133 ; select_cc lhs, rhs, 1, (sext (setcc lhs, rhs, setne)), setult
1134 define i64 @setbuh(i16 %a, i16 %b) {
1135 %t1 = icmp ult i16 %b, %a
1136 %t2 = icmp ne i16 %b, %a
1137 %t3 = sext i1 %t2 to i64
1138 %t4 = select i1 %t1, i64 1, i64 %t3
1140 ; CHECK-LABEL: setbuh:
1141 ; CHECK-DAG: rlwinm [[RA:r[0-9]+]], r3, 0, 16, 31
1142 ; CHECK-DAG: rlwinm [[RB:r[0-9]+]], r4, 0, 16, 31
1145 ; CHECK: cmplw {{c?r?(0, )?}}[[RA]], [[RB]]
1146 ; CHECK-NEXT: setb r3, cr0
1153 ; CHECK-PWR8-LABEL: setbuh
1154 ; CHECK-PWR8: rlwinm
1155 ; CHECK-PWR8: rlwinm
1156 ; CHECK-PWR8-DAG: cmplw
1157 ; CHECK-PWR8-DAG: cntlzw
1165 ; select_cc lhs, rhs, 1, (sext (setcc lhs, rhs, setult)), setugt
1166 define i64 @setbuc(i8 %a, i8 %b) {
1167 %t1 = icmp ugt i8 %a, %b
1168 %t2 = icmp ult i8 %a, %b
1169 %t3 = sext i1 %t2 to i64
1170 %t4 = select i1 %t1, i64 1, i64 %t3
1172 ; CHECK-LABEL: setbuc:
1173 ; CHECK-DAG: rlwinm [[RA:r[0-9]+]], r3, 0, 24, 31
1174 ; CHECK-DAG: rlwinm [[RB:r[0-9]+]], r4, 0, 24, 31
1177 ; CHECK: cmplw {{c?r?(0, )?}}[[RA]], [[RB]]
1178 ; CHECK-NEXT: setb r3, cr0
1183 ; CHECK-PWR8-LABEL: setbuc
1184 ; CHECK-PWR8: rlwinm
1185 ; CHECK-PWR8: rlwinm
1186 ; CHECK-PWR8-DAG: clrldi
1187 ; CHECK-PWR8-DAG: clrldi
1188 ; CHECK-PWR8-DAG: cmplw
1194 ; Test with float/double/float128 for input parameter
1196 ; select_cc lhs, rhs, -1, (zext (setcc rhs, lhs, setlt)), setlt
1197 define i64 @setbf1(float %a, float %b) {
1198 %t1 = fcmp fast olt float %a, %b
1199 %t2 = fcmp fast olt float %b, %a
1200 %t3 = zext i1 %t2 to i64
1201 %t4 = select i1 %t1, i64 -1, i64 %t3
1203 ; CHECK-LABEL: setbf1:
1205 ; CHECK: fcmpu cr0, f1, f2
1206 ; CHECK-NEXT: setb r3, cr0
1210 ; CHECK-PWR8-LABEL: setbf1
1216 ; select_cc lhs, rhs, -1, (zext (setcc lhs, rhs, setlt)), setgt
1217 define i64 @setbf2(float %a, float %b) {
1218 %t1 = fcmp fast ogt float %b, %a
1219 %t2 = fcmp fast olt float %b, %a
1220 %t3 = zext i1 %t2 to i64
1221 %t4 = select i1 %t1, i64 -1, i64 %t3
1223 ; CHECK-LABEL: setbf2:
1225 ; CHECK: fcmpu cr0, f1, f2
1226 ; CHECK-NEXT: setb r3, cr0
1230 ; CHECK-PWR8-LABEL: setbf2
1236 ; select_cc lhs, rhs, 0, (select_cc lhs, rhs, -1, 1, setgt), seteq
1237 define i64 @setbdf1(double %a, double %b) {
1238 %t1 = fcmp fast oeq double %b, %a
1239 %t2 = fcmp fast ogt double %b, %a
1240 %t3 = select i1 %t2, i64 -1, i64 1
1241 %t4 = select i1 %t1, i64 0, i64 %t3
1243 ; CHECK-LABEL: setbdf1:
1244 ; CHECK: xscmpudp cr0, f1, f2
1245 ; CHECK-NEXT: setb r3, cr0
1249 ; CHECK-PWR8-LABEL: setbdf1
1255 ; select_cc lhs, rhs, 1, (sext (setcc lhs, rhs, setgt)), setlt
1256 define i64 @setbdf2(double %a, double %b) {
1257 %t1 = fcmp fast olt double %b, %a
1258 %t2 = fcmp fast ogt double %b, %a
1259 %t3 = sext i1 %t2 to i64
1260 %t4 = select i1 %t1, i64 1, i64 %t3
1262 ; CHECK-LABEL: setbdf2:
1265 ; CHECK: xscmpudp cr0, f1, f2
1266 ; CHECK-NEXT: setb r3, cr0
1270 ; CHECK-PWR8-LABEL: setbdf2
1276 define i64 @setbf128(fp128 %a, fp128 %b) {
1277 %t1 = fcmp fast ogt fp128 %a, %b
1278 %t2 = fcmp fast olt fp128 %a, %b
1279 %t3 = sext i1 %t2 to i64
1280 %t4 = select i1 %t1, i64 1, i64 %t3
1282 ; CHECK-LABEL: setbf128:
1284 ; CHECK: xscmpuqp cr0, v2, v3
1285 ; CHECK-NEXT: setb r3, cr0
1289 ; CHECK-PWR8-LABEL: setbf128
1294 ; Some cases we can't leverage setb
1296 define i64 @setbn1(i64 %a, i64 %b) {
1297 %t1 = icmp slt i64 %a, %b
1298 %t2 = icmp eq i64 %a, %b
1299 %t3 = zext i1 %t2 to i64
1300 %t4 = select i1 %t1, i64 -1, i64 %t3
1302 ; CHECK-LABEL: setbn1:
1303 ; CHECK-NOT: {{\<setb\>}}
1308 define i64 @setbn2(double %a, double %b) {
1309 %t1 = fcmp olt double %a, %b
1310 %t2 = fcmp one double %a, %b
1311 %t3 = zext i1 %t2 to i64
1312 %t4 = select i1 %t1, i64 -1, i64 %t3
1314 ; CHECK-LABEL: setbn2:
1315 ; CHECK-NOT: {{\<setb\>}}
1320 define i64 @setbn3(float %a, float %b) {
1321 %t1 = fcmp ult float %a, %b
1322 %t2 = fcmp une float %a, %b
1323 %t3 = zext i1 %t2 to i64
1324 %t4 = select i1 %t1, i64 -1, i64 %t3
1326 ; CHECK-LABEL: setbn3:
1327 ; CHECK-NOT: {{\<setb\>}}