Skip to content

Commit d16bacc

Browse files
dtcxzywzahiraam
authored andcommitted
[InstCombine] Add pre-commit tests for PR65845
See also https://reviews.llvm.org/D158983
1 parent 3fc460f commit d16bacc

File tree

1 file changed

+159
-51
lines changed

1 file changed

+159
-51
lines changed

llvm/test/Transforms/InstCombine/select-and-or.ll

Lines changed: 159 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -477,32 +477,34 @@ define i1 @and_or2(i1 %a, i1 %b, i1 %c) {
477477
ret i1 %r
478478
}
479479

480-
define i1 @and_or1_bundef(i1 %a, i1 noundef %b, i1 %c) {
481-
; CHECK-LABEL: @and_or1_bundef(
482-
; CHECK-NEXT: [[TMP1:%.*]] = or i1 [[C:%.*]], [[B:%.*]]
483-
; CHECK-NEXT: [[R:%.*]] = and i1 [[TMP1]], [[A:%.*]]
480+
define i1 @and_or1_commuted(i1 %a, i1 %b, i1 %c) {
481+
; CHECK-LABEL: @and_or1_commuted(
482+
; CHECK-NEXT: [[TMP1:%.*]] = freeze i1 [[B:%.*]]
483+
; CHECK-NEXT: [[TMP2:%.*]] = or i1 [[TMP1]], [[C:%.*]]
484+
; CHECK-NEXT: [[R:%.*]] = and i1 [[TMP2]], [[A:%.*]]
484485
; CHECK-NEXT: ret i1 [[R]]
485486
;
486487
%nota = xor i1 %a, true
487-
%cond = or i1 %nota, %c
488+
%cond = or i1 %c, %nota
488489
%r = select i1 %cond, i1 %a, i1 %b
489490
ret i1 %r
490491
}
491492

492-
define i1 @and_or2_aundef(i1 noundef %a, i1 %b, i1 %c) {
493-
; CHECK-LABEL: @and_or2_aundef(
494-
; CHECK-NEXT: [[TMP1:%.*]] = or i1 [[C:%.*]], [[A:%.*]]
495-
; CHECK-NEXT: [[R:%.*]] = and i1 [[TMP1]], [[B:%.*]]
493+
define i1 @and_or2_commuted(i1 %a, i1 %b, i1 %c) {
494+
; CHECK-LABEL: @and_or2_commuted(
495+
; CHECK-NEXT: [[TMP1:%.*]] = freeze i1 [[A:%.*]]
496+
; CHECK-NEXT: [[TMP2:%.*]] = or i1 [[TMP1]], [[C:%.*]]
497+
; CHECK-NEXT: [[R:%.*]] = and i1 [[TMP2]], [[B:%.*]]
496498
; CHECK-NEXT: ret i1 [[R]]
497499
;
498500
%notc = xor i1 %c, true
499-
%cond = and i1 %notc, %b
501+
%cond = and i1 %b, %notc
500502
%r = select i1 %cond, i1 %a, i1 %b
501503
ret i1 %r
502504
}
503505

504-
define i1 @no_and_or1_bundef(i1 %a, i1 noundef %b, i1 %c) {
505-
; CHECK-LABEL: @no_and_or1_bundef(
506+
define i1 @and_or1_multiuse(i1 %a, i1 %b, i1 %c) {
507+
; CHECK-LABEL: @and_or1_multiuse(
506508
; CHECK-NEXT: [[NOTA:%.*]] = xor i1 [[A:%.*]], true
507509
; CHECK-NEXT: [[COND:%.*]] = or i1 [[NOTA]], [[C:%.*]]
508510
; CHECK-NEXT: call void @use(i1 [[COND]])
@@ -516,8 +518,8 @@ define i1 @no_and_or1_bundef(i1 %a, i1 noundef %b, i1 %c) {
516518
ret i1 %r
517519
}
518520

519-
define i1 @no_and_or2_aundef(i1 noundef %a, i1 %b, i1 %c) {
520-
; CHECK-LABEL: @no_and_or2_aundef(
521+
define i1 @and_or2_multiuse(i1 %a, i1 %b, i1 %c) {
522+
; CHECK-LABEL: @and_or2_multiuse(
521523
; CHECK-NEXT: [[NOTC:%.*]] = xor i1 [[C:%.*]], true
522524
; CHECK-NEXT: [[COND:%.*]] = and i1 [[NOTC]], [[B:%.*]]
523525
; CHECK-NEXT: call void @use(i1 [[COND]])
@@ -531,38 +533,68 @@ define i1 @no_and_or2_aundef(i1 noundef %a, i1 %b, i1 %c) {
531533
ret i1 %r
532534
}
533535

534-
define i1 @and_or1_op1not(i1 %a, i1 %b) {
535-
; CHECK-LABEL: @and_or1_op1not(
536-
; CHECK-NEXT: [[C:%.*]] = call i1 @gen_i1()
537-
; CHECK-NEXT: [[TMP1:%.*]] = freeze i1 [[B:%.*]]
538-
; CHECK-NEXT: [[TMP2:%.*]] = or i1 [[C]], [[TMP1]]
539-
; CHECK-NEXT: [[R:%.*]] = and i1 [[TMP2]], [[A:%.*]]
540-
; CHECK-NEXT: ret i1 [[R]]
536+
define <2 x i1> @and_or1_vec(<2 x i1> %a, <2 x i1> %b) {
537+
; CHECK-LABEL: @and_or1_vec(
538+
; CHECK-NEXT: [[C:%.*]] = call <2 x i1> @gen_v2i1()
539+
; CHECK-NEXT: [[TMP1:%.*]] = freeze <2 x i1> [[B:%.*]]
540+
; CHECK-NEXT: [[TMP2:%.*]] = or <2 x i1> [[C]], [[TMP1]]
541+
; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[TMP2]], [[A:%.*]]
542+
; CHECK-NEXT: ret <2 x i1> [[R]]
541543
;
542-
%c = call i1 @gen_i1()
543-
%nota = xor i1 %a, true
544-
%cond = or i1 %c, %nota
545-
%r = select i1 %cond, i1 %a, i1 %b
546-
ret i1 %r
544+
%c = call <2 x i1> @gen_v2i1()
545+
%nota = xor <2 x i1> %a, <i1 true, i1 true>
546+
%cond = or <2 x i1> %nota, %c
547+
%r = select <2 x i1> %cond, <2 x i1> %a, <2 x i1> %b
548+
ret <2 x i1> %r
547549
}
548550

549-
define i1 @and_or2_op1not(i1 %a, i1 %c) {
550-
; CHECK-LABEL: @and_or2_op1not(
551-
; CHECK-NEXT: [[B:%.*]] = call i1 @gen_i1()
552-
; CHECK-NEXT: [[TMP1:%.*]] = freeze i1 [[A:%.*]]
553-
; CHECK-NEXT: [[TMP2:%.*]] = or i1 [[TMP1]], [[C:%.*]]
554-
; CHECK-NEXT: [[R:%.*]] = and i1 [[B]], [[TMP2]]
555-
; CHECK-NEXT: ret i1 [[R]]
551+
define <2 x i1> @and_or2_vec(<2 x i1> %a, <2 x i1> %b) {
552+
; CHECK-LABEL: @and_or2_vec(
553+
; CHECK-NEXT: [[C:%.*]] = call <2 x i1> @gen_v2i1()
554+
; CHECK-NEXT: [[TMP1:%.*]] = freeze <2 x i1> [[A:%.*]]
555+
; CHECK-NEXT: [[TMP2:%.*]] = or <2 x i1> [[C]], [[TMP1]]
556+
; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[TMP2]], [[B:%.*]]
557+
; CHECK-NEXT: ret <2 x i1> [[R]]
556558
;
557-
%b = call i1 @gen_i1()
558-
%notc = xor i1 %c, true
559-
%cond = and i1 %b, %notc
560-
%r = select i1 %cond, i1 %a, i1 %b
561-
ret i1 %r
559+
%c = call <2 x i1> @gen_v2i1()
560+
%notc = xor <2 x i1> %c, <i1 true, i1 true>
561+
%cond = and <2 x i1> %notc, %b
562+
%r = select <2 x i1> %cond, <2 x i1> %a, <2 x i1> %b
563+
ret <2 x i1> %r
562564
}
563565

564-
define i1 @neg_and_or1(i1 %a, i1 %b, i1 %c, i1 %d) {
565-
; CHECK-LABEL: @neg_and_or1(
566+
define <2 x i1> @and_or1_vec_commuted(<2 x i1> %a, <2 x i1> %b) {
567+
; CHECK-LABEL: @and_or1_vec_commuted(
568+
; CHECK-NEXT: [[C:%.*]] = call <2 x i1> @gen_v2i1()
569+
; CHECK-NEXT: [[TMP1:%.*]] = freeze <2 x i1> [[B:%.*]]
570+
; CHECK-NEXT: [[TMP2:%.*]] = or <2 x i1> [[C]], [[TMP1]]
571+
; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[TMP2]], [[A:%.*]]
572+
; CHECK-NEXT: ret <2 x i1> [[R]]
573+
;
574+
%c = call <2 x i1> @gen_v2i1()
575+
%nota = xor <2 x i1> %a, <i1 true, i1 true>
576+
%cond = or <2 x i1> %c, %nota
577+
%r = select <2 x i1> %cond, <2 x i1> %a, <2 x i1> %b
578+
ret <2 x i1> %r
579+
}
580+
581+
define <2 x i1> @and_or2_vec_commuted(<2 x i1> %a, <2 x i1> %b) {
582+
; CHECK-LABEL: @and_or2_vec_commuted(
583+
; CHECK-NEXT: [[C:%.*]] = call <2 x i1> @gen_v2i1()
584+
; CHECK-NEXT: [[TMP1:%.*]] = freeze <2 x i1> [[A:%.*]]
585+
; CHECK-NEXT: [[TMP2:%.*]] = or <2 x i1> [[C]], [[TMP1]]
586+
; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[TMP2]], [[B:%.*]]
587+
; CHECK-NEXT: ret <2 x i1> [[R]]
588+
;
589+
%c = call <2 x i1> @gen_v2i1()
590+
%notc = xor <2 x i1> %c, <i1 true, i1 true>
591+
%cond = and <2 x i1> %b, %notc
592+
%r = select <2 x i1> %cond, <2 x i1> %a, <2 x i1> %b
593+
ret <2 x i1> %r
594+
}
595+
596+
define i1 @and_or1_wrong_operand(i1 %a, i1 %b, i1 %c, i1 %d) {
597+
; CHECK-LABEL: @and_or1_wrong_operand(
566598
; CHECK-NEXT: [[NOTA:%.*]] = xor i1 [[A:%.*]], true
567599
; CHECK-NEXT: [[COND:%.*]] = or i1 [[NOTA]], [[C:%.*]]
568600
; CHECK-NEXT: [[R:%.*]] = select i1 [[COND]], i1 [[D:%.*]], i1 [[B:%.*]]
@@ -574,8 +606,8 @@ define i1 @neg_and_or1(i1 %a, i1 %b, i1 %c, i1 %d) {
574606
ret i1 %r
575607
}
576608

577-
define i1 @neg_and_or2(i1 %a, i1 %b, i1 %c, i1 %d) {
578-
; CHECK-LABEL: @neg_and_or2(
609+
define i1 @and_or2_wrong_operand(i1 %a, i1 %b, i1 %c, i1 %d) {
610+
; CHECK-LABEL: @and_or2_wrong_operand(
579611
; CHECK-NEXT: [[NOTC:%.*]] = xor i1 [[C:%.*]], true
580612
; CHECK-NEXT: [[COND:%.*]] = and i1 [[NOTC]], [[B:%.*]]
581613
; CHECK-NEXT: [[R:%.*]] = select i1 [[COND]], i1 [[A:%.*]], i1 [[D:%.*]]
@@ -587,21 +619,97 @@ define i1 @neg_and_or2(i1 %a, i1 %b, i1 %c, i1 %d) {
587619
ret i1 %r
588620
}
589621

590-
define <2 x i1> @and_or1_op1not_vec(<2 x i1> %a, <2 x i1> %b) {
591-
; CHECK-LABEL: @and_or1_op1not_vec(
592-
; CHECK-NEXT: [[C:%.*]] = call <2 x i1> @gen_v2i1()
593-
; CHECK-NEXT: [[TMP1:%.*]] = freeze <2 x i1> [[B:%.*]]
594-
; CHECK-NEXT: [[TMP2:%.*]] = or <2 x i1> [[C]], [[TMP1]]
595-
; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[TMP2]], [[A:%.*]]
622+
define i1 @and_or3(i1 %a, i1 %b, i32 %x, i32 %y) {
623+
; CHECK-LABEL: @and_or3(
624+
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
625+
; CHECK-NEXT: [[COND:%.*]] = and i1 [[C]], [[B:%.*]]
626+
; CHECK-NEXT: [[R:%.*]] = select i1 [[COND]], i1 [[A:%.*]], i1 [[B]]
627+
; CHECK-NEXT: ret i1 [[R]]
628+
;
629+
%c = icmp eq i32 %x, %y
630+
%cond = and i1 %b, %c
631+
%r = select i1 %cond, i1 %a, i1 %b
632+
ret i1 %r
633+
}
634+
635+
define i1 @and_or3_commuted(i1 %a, i1 %b, i32 %x, i32 %y) {
636+
; CHECK-LABEL: @and_or3_commuted(
637+
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
638+
; CHECK-NEXT: [[COND:%.*]] = and i1 [[C]], [[B:%.*]]
639+
; CHECK-NEXT: [[R:%.*]] = select i1 [[COND]], i1 [[A:%.*]], i1 [[B]]
640+
; CHECK-NEXT: ret i1 [[R]]
641+
;
642+
%c = icmp eq i32 %x, %y
643+
%cond = and i1 %c, %b
644+
%r = select i1 %cond, i1 %a, i1 %b
645+
ret i1 %r
646+
}
647+
648+
define i1 @and_or3_not_free_to_invert(i1 %a, i1 %b, i1 %c) {
649+
; CHECK-LABEL: @and_or3_not_free_to_invert(
650+
; CHECK-NEXT: [[COND:%.*]] = and i1 [[B:%.*]], [[C:%.*]]
651+
; CHECK-NEXT: [[R:%.*]] = select i1 [[COND]], i1 [[A:%.*]], i1 [[B]]
652+
; CHECK-NEXT: ret i1 [[R]]
653+
;
654+
%cond = and i1 %b, %c
655+
%r = select i1 %cond, i1 %a, i1 %b
656+
ret i1 %r
657+
}
658+
659+
define i1 @and_or3_multiuse(i1 %a, i1 %b, i32 %x, i32 %y) {
660+
; CHECK-LABEL: @and_or3_multiuse(
661+
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
662+
; CHECK-NEXT: [[COND:%.*]] = and i1 [[C]], [[B:%.*]]
663+
; CHECK-NEXT: call void @use(i1 [[COND]])
664+
; CHECK-NEXT: [[R:%.*]] = select i1 [[COND]], i1 [[A:%.*]], i1 [[B]]
665+
; CHECK-NEXT: ret i1 [[R]]
666+
;
667+
%c = icmp eq i32 %x, %y
668+
%cond = and i1 %b, %c
669+
call void @use(i1 %cond)
670+
%r = select i1 %cond, i1 %a, i1 %b
671+
ret i1 %r
672+
}
673+
674+
define <2 x i1> @and_or3_vec(<2 x i1> %a, <2 x i1> %b, <2 x i32> %x, <2 x i32> %y) {
675+
; CHECK-LABEL: @and_or3_vec(
676+
; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x i32> [[X:%.*]], [[Y:%.*]]
677+
; CHECK-NEXT: [[COND:%.*]] = and <2 x i1> [[C]], [[B:%.*]]
678+
; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[COND]], <2 x i1> [[A:%.*]], <2 x i1> [[B]]
596679
; CHECK-NEXT: ret <2 x i1> [[R]]
597680
;
598-
%c = call <2 x i1> @gen_v2i1()
599-
%nota = xor <2 x i1> %a, <i1 true, i1 true>
600-
%cond = or <2 x i1> %c, %nota
681+
%c = icmp eq <2 x i32> %x, %y
682+
%cond = and <2 x i1> %b, %c
683+
%r = select <2 x i1> %cond, <2 x i1> %a, <2 x i1> %b
684+
ret <2 x i1> %r
685+
}
686+
687+
define <2 x i1> @and_or3_vec_commuted(<2 x i1> %a, <2 x i1> %b, <2 x i32> %x, <2 x i32> %y) {
688+
; CHECK-LABEL: @and_or3_vec_commuted(
689+
; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x i32> [[X:%.*]], [[Y:%.*]]
690+
; CHECK-NEXT: [[COND:%.*]] = and <2 x i1> [[C]], [[B:%.*]]
691+
; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[COND]], <2 x i1> [[A:%.*]], <2 x i1> [[B]]
692+
; CHECK-NEXT: ret <2 x i1> [[R]]
693+
;
694+
%c = icmp eq <2 x i32> %x, %y
695+
%cond = and <2 x i1> %c, %b
601696
%r = select <2 x i1> %cond, <2 x i1> %a, <2 x i1> %b
602697
ret <2 x i1> %r
603698
}
604699

700+
define i1 @and_or3_wrong_operand(i1 %a, i1 %b, i32 %x, i32 %y, i1 %d) {
701+
; CHECK-LABEL: @and_or3_wrong_operand(
702+
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
703+
; CHECK-NEXT: [[COND:%.*]] = and i1 [[C]], [[B:%.*]]
704+
; CHECK-NEXT: [[R:%.*]] = select i1 [[COND]], i1 [[A:%.*]], i1 [[D:%.*]]
705+
; CHECK-NEXT: ret i1 [[R]]
706+
;
707+
%c = icmp eq i32 %x, %y
708+
%cond = and i1 %b, %c
709+
%r = select i1 %cond, i1 %a, i1 %d
710+
ret i1 %r
711+
}
712+
605713
define i1 @or_and1(i1 %a, i1 %b, i1 %c) {
606714
; CHECK-LABEL: @or_and1(
607715
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], i1 [[A:%.*]], i1 false

0 commit comments

Comments
 (0)