Skip to content

Commit 1162651

Browse files
committed
[InstCombine] Add tests for expanding foldSelectValueEquivalence; NFC
1 parent 7d60232 commit 1162651

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3+
4+
declare void @use.i1(i1)
5+
declare void @use.i8(i8)
6+
define i8 @replace_with_y_noundef(i8 %x, i8 noundef %y, i8 %z) {
7+
; CHECK-LABEL: @replace_with_y_noundef(
8+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]
9+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], [[Y]]
10+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[AND]], i8 [[Z:%.*]]
11+
; CHECK-NEXT: ret i8 [[SEL]]
12+
;
13+
%cmp = icmp eq i8 %x, %y
14+
%and = and i8 %x, %y
15+
%sel = select i1 %cmp, i8 %and, i8 %z
16+
ret i8 %sel
17+
}
18+
19+
define i8 @replace_with_x_noundef(i8 noundef %x, i8 %y, i8 %z) {
20+
; CHECK-LABEL: @replace_with_x_noundef(
21+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], [[Y:%.*]]
22+
; CHECK-NEXT: call void @use.i1(i1 [[CMP]])
23+
; CHECK-NEXT: [[AND:%.*]] = or i8 [[X]], [[Y]]
24+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[Z:%.*]], i8 [[AND]]
25+
; CHECK-NEXT: ret i8 [[SEL]]
26+
;
27+
%cmp = icmp ne i8 %x, %y
28+
call void @use.i1(i1 %cmp)
29+
%and = or i8 %x, %y
30+
%sel = select i1 %cmp, i8 %z, i8 %and
31+
ret i8 %sel
32+
}
33+
34+
define i8 @replace_with_x_maybe_undef_fail(i8 %x, i8 %y, i8 %z) {
35+
; CHECK-LABEL: @replace_with_x_maybe_undef_fail(
36+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], [[Y:%.*]]
37+
; CHECK-NEXT: call void @use.i1(i1 [[CMP]])
38+
; CHECK-NEXT: [[AND:%.*]] = or i8 [[X]], [[Y]]
39+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[Z:%.*]], i8 [[AND]]
40+
; CHECK-NEXT: ret i8 [[SEL]]
41+
;
42+
%cmp = icmp ne i8 %x, %y
43+
call void @use.i1(i1 %cmp)
44+
%and = or i8 %x, %y
45+
%sel = select i1 %cmp, i8 %z, i8 %and
46+
ret i8 %sel
47+
}
48+
49+
define i8 @replace_with_y_for_new_oneuse(i8 noundef %xx, i8 noundef %y, i8 %z) {
50+
; CHECK-LABEL: @replace_with_y_for_new_oneuse(
51+
; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13
52+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y:%.*]]
53+
; CHECK-NEXT: [[ADD:%.*]] = add nuw i8 [[X]], [[Y]]
54+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[ADD]], i8 [[Z:%.*]]
55+
; CHECK-NEXT: ret i8 [[SEL]]
56+
;
57+
%x = mul i8 %xx, 13
58+
%cmp = icmp eq i8 %x, %y
59+
%add = add nuw i8 %x, %y
60+
%sel = select i1 %cmp, i8 %add, i8 %z
61+
ret i8 %sel
62+
}
63+
64+
define i8 @replace_with_x_for_new_oneuse(i8 noundef %xx, i8 noundef %yy, i8 %z, i8 %w) {
65+
; CHECK-LABEL: @replace_with_x_for_new_oneuse(
66+
; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13
67+
; CHECK-NEXT: [[Y:%.*]] = add i8 [[YY:%.*]], [[W:%.*]]
68+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y]]
69+
; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]]
70+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
71+
; CHECK-NEXT: ret i8 [[SEL]]
72+
;
73+
%x = mul i8 %xx, 13
74+
%y = add i8 %yy, %w
75+
%cmp = icmp eq i8 %x, %y
76+
%mul = mul i8 %x, %y
77+
%sel = select i1 %cmp, i8 %mul, i8 %z
78+
ret i8 %sel
79+
}
80+
81+
define i8 @replace_with_x_for_simple_binop(i8 noundef %xx, i8 %yy, i8 %z, i8 %w) {
82+
; CHECK-LABEL: @replace_with_x_for_simple_binop(
83+
; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13
84+
; CHECK-NEXT: [[Y:%.*]] = add i8 [[YY:%.*]], [[W:%.*]]
85+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y]]
86+
; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]]
87+
; CHECK-NEXT: call void @use.i8(i8 [[Y]])
88+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
89+
; CHECK-NEXT: ret i8 [[SEL]]
90+
;
91+
%x = mul i8 %xx, 13
92+
%y = add i8 %yy, %w
93+
%cmp = icmp eq i8 %x, %y
94+
%mul = mul i8 %x, %y
95+
call void @use.i8(i8 %y)
96+
%sel = select i1 %cmp, i8 %mul, i8 %z
97+
ret i8 %sel
98+
}
99+
100+
define i8 @replace_with_none_for_new_oneuse_fail_maybe_undef(i8 %xx, i8 %y, i8 %z) {
101+
; CHECK-LABEL: @replace_with_none_for_new_oneuse_fail_maybe_undef(
102+
; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13
103+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y:%.*]]
104+
; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]]
105+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
106+
; CHECK-NEXT: ret i8 [[SEL]]
107+
;
108+
%x = mul i8 %xx, 13
109+
%cmp = icmp eq i8 %x, %y
110+
%mul = mul i8 %x, %y
111+
%sel = select i1 %cmp, i8 %mul, i8 %z
112+
ret i8 %sel
113+
}
114+
115+
define i8 @replace_with_y_for_simple_binop(i8 %x, i8 noundef %y, i8 %z) {
116+
; CHECK-LABEL: @replace_with_y_for_simple_binop(
117+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]
118+
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[X]], [[Y]]
119+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
120+
; CHECK-NEXT: ret i8 [[SEL]]
121+
;
122+
%cmp = icmp eq i8 %x, %y
123+
%mul = mul nsw i8 %x, %y
124+
%sel = select i1 %cmp, i8 %mul, i8 %z
125+
ret i8 %sel
126+
}
127+
128+
define i8 @replace_with_y_for_simple_binop_fail(i8 %x, i8 noundef %y, i8 %z, i8 %q) {
129+
; CHECK-LABEL: @replace_with_y_for_simple_binop_fail(
130+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]
131+
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[X]], [[Q:%.*]]
132+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
133+
; CHECK-NEXT: ret i8 [[SEL]]
134+
;
135+
%cmp = icmp eq i8 %x, %y
136+
%mul = mul nsw i8 %x, %q
137+
%sel = select i1 %cmp, i8 %mul, i8 %z
138+
ret i8 %sel
139+
}

0 commit comments

Comments
 (0)