Skip to content

Commit 60429fb

Browse files
committed
[InstCombine] Add more tests for select equivalence fold (NFC)
1 parent fb0c705 commit 60429fb

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

llvm/test/Transforms/InstCombine/select.ll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,6 +2797,19 @@ define <2 x i8> @select_replacement_add_eq_vec_poison(<2 x i8> %x, <2 x i8> %y)
27972797
ret <2 x i8> %sel
27982798
}
27992799

2800+
define <2 x i8> @select_replacement_add_eq_vec_undef(<2 x i8> %x, <2 x i8> %y) {
2801+
; CHECK-LABEL: @select_replacement_add_eq_vec_undef(
2802+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[X:%.*]], <i8 1, i8 undef>
2803+
; CHECK-NEXT: [[ADD:%.*]] = add <2 x i8> [[X]], <i8 1, i8 1>
2804+
; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[ADD]], <2 x i8> [[Y:%.*]]
2805+
; CHECK-NEXT: ret <2 x i8> [[SEL]]
2806+
;
2807+
%cmp = icmp eq <2 x i8> %x, <i8 1, i8 undef>
2808+
%add = add <2 x i8> %x, <i8 1, i8 1>
2809+
%sel = select <2 x i1> %cmp, <2 x i8> %add, <2 x i8> %y
2810+
ret <2 x i8> %sel
2811+
}
2812+
28002813
define i8 @select_replacement_add_ne(i8 %x, i8 %y) {
28012814
; CHECK-LABEL: @select_replacement_add_ne(
28022815
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], 1
@@ -2835,6 +2848,21 @@ define i8 @select_replacement_sub_noundef(i8 %x, i8 noundef %y, i8 %z) {
28352848
ret i8 %sel
28362849
}
28372850

2851+
define i8 @select_replacement_sub_noundef_but_may_be_poison(i8 %x, i8 noundef %yy, i8 %z) {
2852+
; CHECK-LABEL: @select_replacement_sub_noundef_but_may_be_poison(
2853+
; CHECK-NEXT: [[Y:%.*]] = shl nuw i8 [[YY:%.*]], 1
2854+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[Y]], [[X:%.*]]
2855+
; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[X]], [[Y]]
2856+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[SUB]], i8 [[Z:%.*]]
2857+
; CHECK-NEXT: ret i8 [[SEL]]
2858+
;
2859+
%y = shl nuw i8 %yy, 1
2860+
%cmp = icmp eq i8 %x, %y
2861+
%sub = sub i8 %x, %y
2862+
%sel = select i1 %cmp, i8 %sub, i8 %z
2863+
ret i8 %sel
2864+
}
2865+
28382866
; TODO: The transform is also safe without noundef.
28392867
define i8 @select_replacement_sub(i8 %x, i8 %y, i8 %z) {
28402868
; CHECK-LABEL: @select_replacement_sub(

0 commit comments

Comments
 (0)