1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instsimplify -S | FileCheck %s
4 define i32 @select_and_icmp(i32 %x, i32 %y, i32 %z) {
5 ; CHECK-LABEL: @select_and_icmp(
6 ; CHECK-NEXT: ret i32 [[X:%.*]]
8 %A = icmp eq i32 %x, %z
9 %B = icmp eq i32 %y, %z
11 %D = select i1 %C, i32 %z, i32 %x
15 define <2 x i8> @select_and_icmp_vec(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
16 ; CHECK-LABEL: @select_and_icmp_vec(
17 ; CHECK-NEXT: ret <2 x i8> [[X:%.*]]
19 %A = icmp eq <2 x i8> %x, %z
20 %B = icmp eq <2 x i8> %y, %z
21 %C = and <2 x i1> %A, %B
22 %D = select <2 x i1> %C, <2 x i8> %z, <2 x i8> %x
26 define i32 @select_and_icmp2(i32 %x, i32 %y, i32 %z) {
27 ; CHECK-LABEL: @select_and_icmp2(
28 ; CHECK-NEXT: ret i32 [[Y:%.*]]
30 %A = icmp eq i32 %x, %z
31 %B = icmp eq i32 %y, %z
33 %D = select i1 %C, i32 %z, i32 %y
37 define i32 @select_and_icmp_alt(i32 %x, i32 %y, i32 %z) {
38 ; CHECK-LABEL: @select_and_icmp_alt(
39 ; CHECK-NEXT: ret i32 [[Z:%.*]]
41 %A = icmp eq i32 %x, %z
42 %B = icmp eq i32 %y, %z
44 %D = select i1 %C, i32 %x, i32 %z
48 define i32 @select_and_icmp_alt2(i32 %x, i32 %y, i32 %z) {
49 ; CHECK-LABEL: @select_and_icmp_alt2(
50 ; CHECK-NEXT: ret i32 [[Z:%.*]]
52 %A = icmp eq i32 %x, %z
53 %B = icmp eq i32 %y, %z
55 %D = select i1 %C, i32 %y, i32 %z
59 define i32 @select_and_icmp_inv_alt(i32 %x, i32 %y, i32 %z) {
60 ; CHECK-LABEL: @select_and_icmp_inv_alt(
61 ; CHECK-NEXT: ret i32 [[Z:%.*]]
63 %A = icmp eq i32 %z, %x
64 %B = icmp eq i32 %z, %y
66 %D = select i1 %C, i32 %x, i32 %z
70 define i32 @select_and_inv_icmp_alt(i32 %x, i32 %y, i32 %z) {
71 ; CHECK-LABEL: @select_and_inv_icmp_alt(
72 ; CHECK-NEXT: ret i32 [[Z:%.*]]
74 %A = icmp eq i32 %x, %z
75 %B = icmp eq i32 %y, %z
77 %D = select i1 %C, i32 %x, i32 %z
81 define i32 @select_and_inv_icmp(i32 %x, i32 %y, i32 %z) {
82 ; CHECK-LABEL: @select_and_inv_icmp(
83 ; CHECK-NEXT: ret i32 [[X:%.*]]
85 %A = icmp eq i32 %x, %z
86 %B = icmp eq i32 %y, %z
88 %D = select i1 %C, i32 %z, i32 %x
92 define <2 x i8> @select_and_icmp_alt_vec(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
93 ; CHECK-LABEL: @select_and_icmp_alt_vec(
94 ; CHECK-NEXT: ret <2 x i8> [[Z:%.*]]
96 %A = icmp eq <2 x i8> %x, %z
97 %B = icmp eq <2 x i8> %y, %z
98 %C = and <2 x i1> %A, %B
99 %D = select <2 x i1> %C, <2 x i8> %x, <2 x i8> %z
104 define i32 @select_and_icmp_inv(i32 %x, i32 %y, i32 %z) {
105 ; CHECK-LABEL: @select_and_icmp_inv(
106 ; CHECK-NEXT: ret i32 [[X:%.*]]
108 %A = icmp eq i32 %z, %x
109 %B = icmp eq i32 %z, %y
111 %D = select i1 %C, i32 %z, i32 %x
116 define i32 @select_and_icmp_pred_bad_1(i32 %x, i32 %y, i32 %z) {
117 ; CHECK-LABEL: @select_and_icmp_pred_bad_1(
118 ; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]]
119 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]]
120 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]]
121 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X]]
122 ; CHECK-NEXT: ret i32 [[D]]
124 %A = icmp eq i32 %x, %z
125 %B = icmp ne i32 %y, %z
127 %D = select i1 %C, i32 %z, i32 %x
131 define i32 @select_and_icmp_pred_bad_2(i32 %x, i32 %y, i32 %z) {
132 ; CHECK-LABEL: @select_and_icmp_pred_bad_2(
133 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]]
134 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]]
135 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]]
136 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X]]
137 ; CHECK-NEXT: ret i32 [[D]]
139 %A = icmp ne i32 %x, %z
140 %B = icmp eq i32 %y, %z
142 %D = select i1 %C, i32 %z, i32 %x
146 define i32 @select_and_icmp_pred_bad_3(i32 %x, i32 %y, i32 %z) {
147 ; CHECK-LABEL: @select_and_icmp_pred_bad_3(
148 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]]
149 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]]
150 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]]
151 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X]]
152 ; CHECK-NEXT: ret i32 [[D]]
154 %A = icmp ne i32 %x, %z
155 %B = icmp ne i32 %y, %z
157 %D = select i1 %C, i32 %z, i32 %x
161 define i32 @select_and_icmp_pred_bad_4(i32 %x, i32 %y, i32 %z) {
162 ; CHECK-LABEL: @select_and_icmp_pred_bad_4(
163 ; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]]
164 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]]
165 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
166 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X]]
167 ; CHECK-NEXT: ret i32 [[D]]
169 %A = icmp eq i32 %x, %z
170 %B = icmp eq i32 %y, %z
172 %D = select i1 %C, i32 %z, i32 %x
176 define i32 @select_and_icmp_bad_true_val(i32 %x, i32 %y, i32 %z, i32 %k) {
177 ; CHECK-LABEL: @select_and_icmp_bad_true_val(
178 ; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]]
179 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]]
180 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]]
181 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[K:%.*]], i32 [[X]]
182 ; CHECK-NEXT: ret i32 [[D]]
184 %A = icmp eq i32 %x, %z
185 %B = icmp eq i32 %y, %z
187 %D = select i1 %C, i32 %k, i32 %x
191 define i32 @select_and_icmp_bad_false_val(i32 %x, i32 %y, i32 %z, i32 %k) {
192 ; CHECK-LABEL: @select_and_icmp_bad_false_val(
193 ; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]]
194 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]]
195 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]]
196 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[K:%.*]]
197 ; CHECK-NEXT: ret i32 [[D]]
199 %A = icmp eq i32 %x, %z
200 %B = icmp eq i32 %y, %z
202 %D = select i1 %C, i32 %z, i32 %k
206 define i32 @select_and_icmp_bad_op(i32 %x, i32 %y, i32 %z, i32 %k) {
207 ; CHECK-LABEL: @select_and_icmp_bad_op(
208 ; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[K:%.*]], [[Z:%.*]]
209 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]]
210 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]]
211 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X:%.*]]
212 ; CHECK-NEXT: ret i32 [[D]]
214 %A = icmp eq i32 %k, %z
215 %B = icmp eq i32 %y, %z
217 %D = select i1 %C, i32 %z, i32 %x
221 define i32 @select_and_icmp_bad_op_2(i32 %x, i32 %y, i32 %z, i32 %k) {
222 ; CHECK-LABEL: @select_and_icmp_bad_op_2(
223 ; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[K:%.*]]
224 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z:%.*]]
225 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]]
226 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X]]
227 ; CHECK-NEXT: ret i32 [[D]]
229 %A = icmp eq i32 %x, %k
230 %B = icmp eq i32 %y, %z
232 %D = select i1 %C, i32 %z, i32 %x
236 define i32 @select_and_icmp_alt_bad_1(i32 %x, i32 %y, i32 %z) {
237 ; CHECK-LABEL: @select_and_icmp_alt_bad_1(
238 ; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]]
239 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]]
240 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]]
241 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[Z]]
242 ; CHECK-NEXT: ret i32 [[D]]
244 %A = icmp eq i32 %x, %z
245 %B = icmp ne i32 %y, %z
247 %D = select i1 %C, i32 %x, i32 %z
251 define i32 @select_and_icmp_alt_bad_2(i32 %x, i32 %y, i32 %z) {
252 ; CHECK-LABEL: @select_and_icmp_alt_bad_2(
253 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]]
254 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]]
255 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]]
256 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[Z]]
257 ; CHECK-NEXT: ret i32 [[D]]
259 %A = icmp ne i32 %x, %z
260 %B = icmp eq i32 %y, %z
262 %D = select i1 %C, i32 %x, i32 %z
266 define i32 @select_and_icmp_alt_bad_3(i32 %x, i32 %y, i32 %z) {
267 ; CHECK-LABEL: @select_and_icmp_alt_bad_3(
268 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]]
269 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]]
270 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]]
271 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[Z]]
272 ; CHECK-NEXT: ret i32 [[D]]
274 %A = icmp ne i32 %x, %z
275 %B = icmp ne i32 %y, %z
277 %D = select i1 %C, i32 %x, i32 %z
281 define i32 @select_and_icmp_alt_bad_4(i32 %x, i32 %y, i32 %z) {
282 ; CHECK-LABEL: @select_and_icmp_alt_bad_4(
283 ; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]]
284 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]]
285 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
286 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[Z]]
287 ; CHECK-NEXT: ret i32 [[D]]
289 %A = icmp eq i32 %x, %z
290 %B = icmp eq i32 %y, %z
292 %D = select i1 %C, i32 %x, i32 %z
296 define i32 @select_and_icmp_alt_bad_5(i32 %x, i32 %y, i32 %z, i32 %k) {
297 ; CHECK-LABEL: @select_and_icmp_alt_bad_5(
298 ; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[K:%.*]]
299 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z:%.*]]
300 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
301 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[Z]]
302 ; CHECK-NEXT: ret i32 [[D]]
304 %A = icmp eq i32 %x, %k
305 %B = icmp eq i32 %y, %z
307 %D = select i1 %C, i32 %x, i32 %z
311 define i32 @select_and_icmp_alt_bad_true_val(i32 %x, i32 %y, i32 %z, i32 %k) {
312 ; CHECK-LABEL: @select_and_icmp_alt_bad_true_val(
313 ; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]]
314 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]]
315 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]]
316 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[K:%.*]], i32 [[Z]]
317 ; CHECK-NEXT: ret i32 [[D]]
319 %A = icmp eq i32 %x, %z
320 %B = icmp eq i32 %y, %z
322 %D = select i1 %C, i32 %k, i32 %z
326 define i32 @select_and_icmp_alt_bad_false_val(i32 %x, i32 %y, i32 %z, i32 %k) {
327 ; CHECK-LABEL: @select_and_icmp_alt_bad_false_val(
328 ; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]]
329 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]]
330 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]]
331 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[K:%.*]]
332 ; CHECK-NEXT: ret i32 [[D]]
334 %A = icmp eq i32 %x, %z
335 %B = icmp eq i32 %y, %z
337 %D = select i1 %C, i32 %x, i32 %k