Skip to content

Commit 768ddc0

Browse files
committed
[InstCombine] Add tests for expanding foldSelectValueEquivalence; NFC
1 parent 81cdd35 commit 768ddc0

File tree

1 file changed

+186
-0
lines changed

1 file changed

+186
-0
lines changed
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
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_y_for_new_oneuse2(i8 %xx, i8 noundef %y, i8 %z, i8 %q) {
65+
; CHECK-LABEL: @replace_with_y_for_new_oneuse2(
66+
; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13
67+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y:%.*]]
68+
; CHECK-NEXT: [[ADD:%.*]] = add nuw i8 [[X]], [[Q:%.*]]
69+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[ADD]], i8 [[Z:%.*]]
70+
; CHECK-NEXT: ret i8 [[SEL]]
71+
;
72+
%x = mul i8 %xx, 13
73+
%cmp = icmp eq i8 %x, %y
74+
%add = add nuw i8 %x, %q
75+
%sel = select i1 %cmp, i8 %add, i8 %z
76+
ret i8 %sel
77+
}
78+
79+
define i8 @replace_with_x_for_new_oneuse(i8 noundef %xx, i8 noundef %yy, i8 %z, i8 %w) {
80+
; CHECK-LABEL: @replace_with_x_for_new_oneuse(
81+
; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13
82+
; CHECK-NEXT: [[Y:%.*]] = add i8 [[YY:%.*]], [[W:%.*]]
83+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y]]
84+
; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]]
85+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
86+
; CHECK-NEXT: ret i8 [[SEL]]
87+
;
88+
%x = mul i8 %xx, 13
89+
%y = add i8 %yy, %w
90+
%cmp = icmp eq i8 %x, %y
91+
%mul = mul i8 %x, %y
92+
%sel = select i1 %cmp, i8 %mul, i8 %z
93+
ret i8 %sel
94+
}
95+
96+
define i8 @replace_with_x_for_new_oneuse2(i8 noundef %xx, i8 %yy, i8 %z, i8 %w, i8 %q) {
97+
; CHECK-LABEL: @replace_with_x_for_new_oneuse2(
98+
; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13
99+
; CHECK-NEXT: [[Y:%.*]] = add i8 [[YY:%.*]], [[W:%.*]]
100+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y]]
101+
; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[Y]], [[Q:%.*]]
102+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
103+
; CHECK-NEXT: ret i8 [[SEL]]
104+
;
105+
%x = mul i8 %xx, 13
106+
%y = add i8 %yy, %w
107+
%cmp = icmp eq i8 %x, %y
108+
%mul = mul i8 %q, %y
109+
%sel = select i1 %cmp, i8 %mul, i8 %z
110+
ret i8 %sel
111+
}
112+
113+
define i8 @replace_with_x_for_simple_binop(i8 noundef %xx, i8 %yy, i8 %z, i8 %w) {
114+
; CHECK-LABEL: @replace_with_x_for_simple_binop(
115+
; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13
116+
; CHECK-NEXT: [[Y:%.*]] = add i8 [[YY:%.*]], [[W:%.*]]
117+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y]]
118+
; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]]
119+
; CHECK-NEXT: call void @use.i8(i8 [[Y]])
120+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
121+
; CHECK-NEXT: ret i8 [[SEL]]
122+
;
123+
%x = mul i8 %xx, 13
124+
%y = add i8 %yy, %w
125+
%cmp = icmp eq i8 %x, %y
126+
%mul = mul i8 %x, %y
127+
call void @use.i8(i8 %y)
128+
%sel = select i1 %cmp, i8 %mul, i8 %z
129+
ret i8 %sel
130+
}
131+
132+
define i8 @replace_with_none_for_new_oneuse_fail_maybe_undef(i8 %xx, i8 %y, i8 %z) {
133+
; CHECK-LABEL: @replace_with_none_for_new_oneuse_fail_maybe_undef(
134+
; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13
135+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y:%.*]]
136+
; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]]
137+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
138+
; CHECK-NEXT: ret i8 [[SEL]]
139+
;
140+
%x = mul i8 %xx, 13
141+
%cmp = icmp eq i8 %x, %y
142+
%mul = mul i8 %x, %y
143+
%sel = select i1 %cmp, i8 %mul, i8 %z
144+
ret i8 %sel
145+
}
146+
147+
define i8 @replace_with_y_for_simple_binop(i8 %x, i8 noundef %y, i8 %z) {
148+
; CHECK-LABEL: @replace_with_y_for_simple_binop(
149+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]
150+
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[X]], [[Y]]
151+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
152+
; CHECK-NEXT: ret i8 [[SEL]]
153+
;
154+
%cmp = icmp eq i8 %x, %y
155+
%mul = mul nsw i8 %x, %y
156+
%sel = select i1 %cmp, i8 %mul, i8 %z
157+
ret i8 %sel
158+
}
159+
160+
define i8 @replace_with_y_for_simple_binop_fail_multiuse(i8 %x, i8 noundef %y, i8 %z) {
161+
; CHECK-LABEL: @replace_with_y_for_simple_binop_fail_multiuse(
162+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]
163+
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[X]], [[Y]]
164+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
165+
; CHECK-NEXT: call void @use.i8(i8 [[MUL]])
166+
; CHECK-NEXT: ret i8 [[SEL]]
167+
;
168+
%cmp = icmp eq i8 %x, %y
169+
%mul = mul nsw i8 %x, %y
170+
%sel = select i1 %cmp, i8 %mul, i8 %z
171+
call void @use.i8(i8 %mul)
172+
ret i8 %sel
173+
}
174+
175+
define i8 @replace_with_y_for_simple_binop_fail(i8 %x, i8 noundef %y, i8 %z, i8 %q) {
176+
; CHECK-LABEL: @replace_with_y_for_simple_binop_fail(
177+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]
178+
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[X]], [[Q:%.*]]
179+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]
180+
; CHECK-NEXT: ret i8 [[SEL]]
181+
;
182+
%cmp = icmp eq i8 %x, %y
183+
%mul = mul nsw i8 %x, %q
184+
%sel = select i1 %cmp, i8 %mul, i8 %z
185+
ret i8 %sel
186+
}

0 commit comments

Comments
 (0)