Skip to content

Commit e9ca727

Browse files
committed
[InstCombine] Add more tests. NFC.
1 parent 0ad2e48 commit e9ca727

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

llvm/test/Transforms/InstCombine/icmp-select.ll

+56
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,41 @@ entry:
709709
ret i1 %res
710710
}
711711

712+
define i1 @discr_eq_add_commuted(i8 noundef %a, i8 %b, i8 %c, i1 %cond1, i1 %cond2) {
713+
; CHECK-LABEL: @discr_eq_add_commuted(
714+
; CHECK-NEXT: entry:
715+
; CHECK-NEXT: [[TMP0:%.*]] = select i1 [[COND1:%.*]], i8 [[B:%.*]], i8 0
716+
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[COND2:%.*]], i8 [[C:%.*]], i8 [[B]]
717+
; CHECK-NEXT: [[RES:%.*]] = icmp eq i8 [[TMP0]], [[TMP1]]
718+
; CHECK-NEXT: ret i1 [[RES]]
719+
;
720+
entry:
721+
%add1 = add i8 %a, %b
722+
%sel1 = select i1 %cond1, i8 %add1, i8 %a
723+
%add2 = add i8 %c, %a
724+
%sel2 = select i1 %cond2, i8 %add2, i8 %add1
725+
%res = icmp eq i8 %sel1, %sel2
726+
ret i1 %res
727+
}
728+
729+
define i1 @discr_eq_sub(i8 noundef %a, i8 %b, i8 %c, i1 %cond1, i1 %cond2) {
730+
; CHECK-LABEL: @discr_eq_sub(
731+
; CHECK-NEXT: entry:
732+
; CHECK-NEXT: [[TMP0:%.*]] = select i1 [[COND1:%.*]], i8 [[B:%.*]], i8 0
733+
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[COND2:%.*]], i8 [[C:%.*]], i8 0
734+
; CHECK-NEXT: [[RES:%.*]] = icmp eq i8 [[TMP0]], [[TMP1]]
735+
; CHECK-NEXT: ret i1 [[RES]]
736+
;
737+
entry:
738+
%neg = sub i8 0, %a
739+
%sub1 = sub i8 %b, %a
740+
%sel1 = select i1 %cond1, i8 %sub1, i8 %neg
741+
%sub2 = sub i8 %c, %a
742+
%sel2 = select i1 %cond2, i8 %sub2, i8 %neg
743+
%res = icmp eq i8 %sel1, %sel2
744+
ret i1 %res
745+
}
746+
712747
; Negative tests
713748

714749
define i1 @discr_eq_multi_use(i8 %a, i8 %b) {
@@ -775,3 +810,24 @@ entry:
775810
%res = icmp eq <2 x i8> %sel1, %add2
776811
ret <2 x i1> %res
777812
}
813+
814+
define i1 @discr_eq_sub_commuted(i8 noundef %a, i8 %b, i8 %c, i1 %cond1, i1 %cond2) {
815+
; CHECK-LABEL: @discr_eq_sub_commuted(
816+
; CHECK-NEXT: entry:
817+
; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]]
818+
; CHECK-NEXT: [[SUB1:%.*]] = sub i8 [[A]], [[B:%.*]]
819+
; CHECK-NEXT: [[SEL1:%.*]] = select i1 [[COND1:%.*]], i8 [[SUB1]], i8 [[NEG]]
820+
; CHECK-NEXT: [[SUB2:%.*]] = sub i8 [[A]], [[C:%.*]]
821+
; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[COND2:%.*]], i8 [[SUB2]], i8 [[NEG]]
822+
; CHECK-NEXT: [[RES:%.*]] = icmp eq i8 [[SEL1]], [[SEL2]]
823+
; CHECK-NEXT: ret i1 [[RES]]
824+
;
825+
entry:
826+
%neg = sub i8 0, %a
827+
%sub1 = sub i8 %a, %b
828+
%sel1 = select i1 %cond1, i8 %sub1, i8 %neg
829+
%sub2 = sub i8 %a, %c
830+
%sel2 = select i1 %cond2, i8 %sub2, i8 %neg
831+
%res = icmp eq i8 %sel1, %sel2
832+
ret i1 %res
833+
}

0 commit comments

Comments
 (0)