1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=ipsccp -S | FileCheck %s
6 define void @f1(i32 %a, i32 %b) {
9 ; CHECK-NEXT: [[A_255:%.*]] = and i32 [[A:%.*]], 255
10 ; CHECK-NEXT: [[A_2:%.*]] = add i32 [[A_255]], 20
11 ; CHECK-NEXT: [[BC:%.*]] = icmp ugt i32 [[B:%.*]], [[A_2]]
12 ; CHECK-NEXT: br i1 [[BC]], label [[TRUE:%.*]], label [[FALSE:%.*]]
14 ; CHECK-NEXT: call void @use(i1 false)
15 ; CHECK-NEXT: call void @use(i1 false)
16 ; CHECK-NEXT: call void @use(i1 false)
17 ; CHECK-NEXT: call void @use(i1 true)
18 ; CHECK-NEXT: call void @use(i1 true)
19 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[B]], 21
20 ; CHECK-NEXT: call void @use(i1 [[C_1]])
21 ; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[B]], 21
22 ; CHECK-NEXT: call void @use(i1 [[C_2]])
23 ; CHECK-NEXT: [[C_3:%.*]] = icmp ugt i32 [[B]], 255
24 ; CHECK-NEXT: call void @use(i1 [[C_3]])
25 ; CHECK-NEXT: ret void
27 ; CHECK-NEXT: call void @use(i1 false)
28 ; CHECK-NEXT: call void @use(i1 false)
29 ; CHECK-NEXT: call void @use(i1 true)
30 ; CHECK-NEXT: call void @use(i1 true)
31 ; CHECK-NEXT: [[C_4:%.*]] = icmp eq i32 [[B]], 21
32 ; CHECK-NEXT: call void @use(i1 [[C_4]])
33 ; CHECK-NEXT: [[C_5:%.*]] = icmp eq i32 [[B]], 275
34 ; CHECK-NEXT: call void @use(i1 [[C_5]])
35 ; CHECK-NEXT: ret void
38 %a.255 = and i32 %a, 255
39 %a.2 = add i32 %a.255, 20
40 %bc = icmp ugt i32 %b, %a.2
41 br i1 %bc, label %true, label %false
44 ; Conditions below are false.
45 %f.1 = icmp eq i32 %b, 0
46 call void @use(i1 %f.1)
47 %f.2 = icmp eq i32 %b, 20
48 call void @use(i1 %f.2)
49 %f.3 = icmp ult i32 %b, 20
50 call void @use(i1 %f.3)
52 ; Conditions below are true.
53 %t.1 = icmp ugt i32 %b, 5
54 call void @use(i1 %t.1)
55 %t.2 = icmp ne i32 %b, 20
56 call void @use(i1 %t.2)
58 ; Conditions below cannot be simplified.
59 %c.1 = icmp eq i32 %b, 21
60 call void @use(i1 %c.1)
61 %c.2 = icmp ugt i32 %b, 21
62 call void @use(i1 %c.2)
63 %c.3 = icmp ugt i32 %b, 255
64 call void @use(i1 %c.3)
67 false: ;%b in [0, 276)
68 ; Conditions below are false;
69 %f.4 = icmp eq i32 %b, 276
70 call void @use(i1 %f.4)
71 %f.5 = icmp ugt i32 %b, 275
72 call void @use(i1 %f.5)
74 ; Conditions below are true;
75 %t.3 = icmp ne i32 %b, 276
76 call void @use(i1 %t.3)
77 %t.4 = icmp ule i32 %b, 275
78 call void @use(i1 %t.4)
80 ; Conditions below cannot be simplified.
81 %c.4 = icmp eq i32 %b, 21
82 call void @use(i1 %c.4)
83 %c.5 = icmp eq i32 %b, 275
84 call void @use(i1 %c.5)
88 ; TODO: Use information %a != 0 in false branch.
89 define void @f2_ptr(i8* %a, i8* %b) {
90 ; CHECK-LABEL: @f2_ptr(
92 ; CHECK-NEXT: [[BC:%.*]] = icmp eq i8* [[A:%.*]], null
93 ; CHECK-NEXT: br i1 [[BC]], label [[TRUE:%.*]], label [[FALSE:%.*]]
95 ; CHECK-NEXT: call void @use(i1 false)
96 ; CHECK-NEXT: call void @use(i1 true)
97 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i8* null, [[B:%.*]]
98 ; CHECK-NEXT: call void @use(i1 [[C_1]])
99 ; CHECK-NEXT: ret void
101 ; CHECK-NEXT: [[F_2:%.*]] = icmp eq i8* [[A]], null
102 ; CHECK-NEXT: call void @use(i1 [[F_2]])
103 ; CHECK-NEXT: [[T_2:%.*]] = icmp ne i8* [[A]], null
104 ; CHECK-NEXT: call void @use(i1 [[T_2]])
105 ; CHECK-NEXT: [[C_2:%.*]] = icmp eq i8* [[A]], [[B]]
106 ; CHECK-NEXT: call void @use(i1 [[C_2]])
107 ; CHECK-NEXT: ret void
110 %bc = icmp eq i8* %a, null
111 br i1 %bc, label %true, label %false
114 %f.1 = icmp ne i8* %a, null
115 call void @use(i1 %f.1)
117 %t.1 = icmp eq i8* %a, null
118 call void @use(i1 %t.1)
120 %c.1 = icmp eq i8* %a, %b
121 call void @use(i1 %c.1)
125 %f.2 = icmp eq i8* %a, null
126 call void @use(i1 %f.2)
128 %t.2 = icmp ne i8* %a, null
129 call void @use(i1 %t.2)
131 %c.2 = icmp eq i8* %a, %b
132 call void @use(i1 %c.2)
136 define i8* @f3(i8* %a, i8* %b, i1 %c) {
139 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i8* [[A:%.*]], null
140 ; CHECK-NEXT: br i1 [[C_1]], label [[TRUE:%.*]], label [[FALSE:%.*]]
142 ; CHECK-NEXT: br i1 [[C:%.*]], label [[TRUE_2:%.*]], label [[FALSE_2:%.*]]
144 ; CHECK-NEXT: br label [[EXIT_2:%.*]]
146 ; CHECK-NEXT: br label [[EXIT_2]]
148 ; CHECK-NEXT: [[P:%.*]] = phi i8* [ null, [[TRUE_2]] ], [ [[B:%.*]], [[FALSE_2]] ]
149 ; CHECK-NEXT: ret i8* [[P]]
151 ; CHECK-NEXT: ret i8* null
154 %c.1 = icmp eq i8* %a, null
155 br i1 %c.1, label %true, label %false
158 br i1 %c, label %true.2, label %false.2
167 %p = phi i8* [ %a, %true.2 ], [ %b, %false.2 ]
174 define i32 @f5(i64 %sz) {
177 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 4088, [[SZ:%.*]]
178 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
180 ; CHECK-NEXT: [[DIV:%.*]] = udiv i64 4088, [[SZ]]
181 ; CHECK-NEXT: br label [[COND_END]]
183 ; CHECK-NEXT: [[COND:%.*]] = phi i64 [ [[DIV]], [[COND_TRUE]] ], [ 1, [[ENTRY:%.*]] ]
184 ; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[COND]] to i32
185 ; CHECK-NEXT: ret i32 [[CONV]]
188 %cmp = icmp ugt i64 4088, %sz
189 br i1 %cmp, label %cond.true, label %cond.end
191 cond.true: ; preds = %entry
192 %div = udiv i64 4088, %sz
195 cond.end: ; preds = %entry, %cond.true
196 %cond = phi i64 [ %div, %cond.true ], [ 1, %entry ]
197 %conv = trunc i64 %cond to i32
201 define void @f6(i32 %b) {
204 ; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i32 [[B:%.*]], 20
205 ; CHECK-NEXT: br i1 [[C_1]], label [[TRUE:%.*]], label [[FALSE:%.*]]
207 ; CHECK-NEXT: call void @use(i1 true)
208 ; CHECK-NEXT: ret void
210 ; CHECK-NEXT: ret void
214 %c.1 = icmp ugt i32 %b, %a
215 br i1 %c.1, label %true, label %false
218 %c.2 = icmp eq i32 %a, 20
219 call void @use(i1 %c.2)
226 ; Test with 2 unrelated nested conditions.
227 define void @f7_nested_conds(i32* %a, i32 %b) {
228 ; CHECK-LABEL: @f7_nested_conds(
230 ; CHECK-NEXT: [[A_V:%.*]] = load i32, i32* [[A:%.*]], align 4
231 ; CHECK-NEXT: [[C_1:%.*]] = icmp ne i32 [[A_V]], 0
232 ; CHECK-NEXT: br i1 [[C_1]], label [[TRUE:%.*]], label [[FALSE:%.*]]
234 ; CHECK-NEXT: br label [[TRUE_2:%.*]]
236 ; CHECK-NEXT: call void @use(i1 true)
237 ; CHECK-NEXT: ret void
239 ; CHECK-NEXT: store i32 [[B:%.*]], i32* [[A]], align 4
240 ; CHECK-NEXT: ret void
243 %a.v = load i32, i32* %a
244 %c.1 = icmp ne i32 %a.v, 0
245 br i1 %c.1, label %true, label %false
248 %c.2 = icmp ult i32 %a.v, 3
249 br i1 %c.2, label %true.2, label %true
252 %c.3 = icmp eq i32 %a.v, 0
253 call void @use(i1 %c.3)
257 store i32 %b, i32* %a
261 ; Test with 2 related nested conditions (%b > [20, 276) && %b < 255).
262 define void @f8_nested_conds(i32 %a, i32 %b) {
263 ; CHECK-LABEL: @f8_nested_conds(
265 ; CHECK-NEXT: [[A_255:%.*]] = and i32 [[A:%.*]], 255
266 ; CHECK-NEXT: [[A_2:%.*]] = add i32 [[A_255]], 20
267 ; CHECK-NEXT: [[BC_1:%.*]] = icmp ugt i32 [[B:%.*]], [[A_2]]
268 ; CHECK-NEXT: br i1 [[BC_1]], label [[TRUE:%.*]], label [[FALSE:%.*]]
270 ; CHECK-NEXT: [[BC_2:%.*]] = icmp ult i32 [[B]], 255
271 ; CHECK-NEXT: br i1 [[BC_2]], label [[TRUE_2:%.*]], label [[FALSE_2:%.*]]
273 ; CHECK-NEXT: call void @use(i1 false)
274 ; CHECK-NEXT: call void @use(i1 false)
275 ; CHECK-NEXT: call void @use(i1 false)
276 ; CHECK-NEXT: call void @use(i1 false)
277 ; CHECK-NEXT: call void @use(i1 false)
278 ; CHECK-NEXT: call void @use(i1 true)
279 ; CHECK-NEXT: call void @use(i1 true)
280 ; CHECK-NEXT: call void @use(i1 true)
281 ; CHECK-NEXT: call void @use(i1 true)
282 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[B]], 21
283 ; CHECK-NEXT: call void @use(i1 [[C_1]])
284 ; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[B]], 21
285 ; CHECK-NEXT: call void @use(i1 [[C_2]])
286 ; CHECK-NEXT: [[C_3:%.*]] = icmp ugt i32 [[B]], 34
287 ; CHECK-NEXT: call void @use(i1 [[C_3]])
288 ; CHECK-NEXT: ret void
290 ; CHECK-NEXT: call void @use(i1 false)
291 ; CHECK-NEXT: call void @use(i1 false)
292 ; CHECK-NEXT: call void @use(i1 true)
293 ; CHECK-NEXT: call void @use(i1 true)
294 ; CHECK-NEXT: [[C_4:%.*]] = icmp eq i32 [[B]], 255
295 ; CHECK-NEXT: call void @use(i1 [[C_4]])
296 ; CHECK-NEXT: [[C_5:%.*]] = icmp ne i32 [[B]], 275
297 ; CHECK-NEXT: call void @use(i1 [[C_5]])
298 ; CHECK-NEXT: ret void
300 ; CHECK-NEXT: ret void
303 %a.255 = and i32 %a, 255
304 %a.2 = add i32 %a.255, 20
305 %bc.1 = icmp ugt i32 %b, %a.2
306 br i1 %bc.1, label %true, label %false
308 true: ; %b in [21, 0)
309 %bc.2 = icmp ult i32 %b, 255
310 br i1 %bc.2, label %true.2, label %false.2
312 true.2: ; %b in [21, 255)
313 ; Conditions below are false.
314 %f.1 = icmp eq i32 %b, 0
315 call void @use(i1 %f.1)
316 %f.2 = icmp eq i32 %b, 20
317 call void @use(i1 %f.2)
318 %f.3 = icmp ult i32 %b, 20
319 call void @use(i1 %f.3)
320 %f.4 = icmp eq i32 %b, 255
321 call void @use(i1 %f.4)
322 %f.5 = icmp ugt i32 %b, 255
323 call void @use(i1 %f.5)
326 ; Conditions below are true.
327 %t.1 = icmp ugt i32 %b, 5
328 call void @use(i1 %t.1)
329 %t.2 = icmp ne i32 %b, 20
330 call void @use(i1 %t.2)
331 %t.3 = icmp ult i32 %b, 255
332 call void @use(i1 %t.3)
333 %t.4 = icmp ne i32 %b, 300
334 call void @use(i1 %t.4)
336 ; Conditions below cannot be simplified.
337 %c.1 = icmp eq i32 %b, 21
338 call void @use(i1 %c.1)
339 %c.2 = icmp ugt i32 %b, 21
340 call void @use(i1 %c.2)
341 %c.3 = icmp ugt i32 %b, 34
342 call void @use(i1 %c.3)
345 false.2: ;%b in [255, 0)
346 ; Conditions below are false;
347 %f.6 = icmp eq i32 %b, 254
348 call void @use(i1 %f.6)
349 %f.7 = icmp ult i32 %b, 255
350 call void @use(i1 %f.7)
352 ; Conditions below are true;
353 %t.5 = icmp ne i32 %b, 254
354 call void @use(i1 %t.5)
355 %t.6 = icmp uge i32 %b, 255
356 call void @use(i1 %t.6)
358 ; Conditions below cannot be simplified.
359 %c.4 = icmp eq i32 %b, 255
360 call void @use(i1 %c.4)
361 %c.5 = icmp ne i32 %b, 275
362 call void @use(i1 %c.5)
369 ; Test with with nested conditions where the second conditions is more limiting than the first one.
370 define void @f9_nested_conds(i32 %a, i32 %b) {
371 ; CHECK-LABEL: @f9_nested_conds(
373 ; CHECK-NEXT: [[BC_1:%.*]] = icmp ugt i32 [[B:%.*]], 10
374 ; CHECK-NEXT: br i1 [[BC_1]], label [[TRUE:%.*]], label [[FALSE:%.*]]
376 ; CHECK-NEXT: call void @use(i1 false)
377 ; CHECK-NEXT: call void @use(i1 false)
378 ; CHECK-NEXT: call void @use(i1 true)
379 ; CHECK-NEXT: call void @use(i1 true)
380 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[B]], 11
381 ; CHECK-NEXT: call void @use(i1 [[C_1]])
382 ; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[B]], 11
383 ; CHECK-NEXT: call void @use(i1 [[C_2]])
384 ; CHECK-NEXT: [[BC_2:%.*]] = icmp ugt i32 [[B]], 20
385 ; CHECK-NEXT: br i1 [[BC_2]], label [[TRUE_2:%.*]], label [[FALSE_2:%.*]]
387 ; CHECK-NEXT: call void @use(i1 false)
388 ; CHECK-NEXT: call void @use(i1 false)
389 ; CHECK-NEXT: call void @use(i1 true)
390 ; CHECK-NEXT: call void @use(i1 true)
391 ; CHECK-NEXT: [[C_3:%.*]] = icmp eq i32 [[B]], 21
392 ; CHECK-NEXT: call void @use(i1 [[C_3]])
393 ; CHECK-NEXT: [[C_4:%.*]] = icmp ugt i32 [[B]], 21
394 ; CHECK-NEXT: call void @use(i1 [[C_4]])
395 ; CHECK-NEXT: [[C_5:%.*]] = icmp ugt i32 [[B]], 34
396 ; CHECK-NEXT: call void @use(i1 [[C_5]])
397 ; CHECK-NEXT: ret void
399 ; CHECK-NEXT: call void @use(i1 false)
400 ; CHECK-NEXT: call void @use(i1 false)
401 ; CHECK-NEXT: call void @use(i1 true)
402 ; CHECK-NEXT: call void @use(i1 true)
403 ; CHECK-NEXT: call void @use(i1 true)
404 ; CHECK-NEXT: call void @use(i1 true)
405 ; CHECK-NEXT: [[C_6:%.*]] = icmp eq i32 [[B]], 11
406 ; CHECK-NEXT: call void @use(i1 [[C_6]])
407 ; CHECK-NEXT: [[C_7:%.*]] = icmp ne i32 [[B]], 15
408 ; CHECK-NEXT: call void @use(i1 [[C_7]])
409 ; CHECK-NEXT: ret void
411 ; CHECK-NEXT: ret void
414 %bc.1 = icmp ugt i32 %b, 10
415 br i1 %bc.1, label %true, label %false
417 true: ; %b in [11, 0)
418 ; Conditions below are false.
419 %f.1 = icmp eq i32 %b, 0
420 call void @use(i1 %f.1)
421 %f.2 = icmp eq i32 %b, 10
422 call void @use(i1 %f.2)
424 ; Conditions below are true.
425 %t.1 = icmp ugt i32 %b, 5
426 call void @use(i1 %t.1)
427 %t.2 = icmp ne i32 %b, 10
428 call void @use(i1 %t.2)
430 ; Conditions below cannot be simplified.
431 %c.1 = icmp eq i32 %b, 11
432 call void @use(i1 %c.1)
433 %c.2 = icmp ugt i32 %b, 11
434 call void @use(i1 %c.2)
436 %bc.2 = icmp ugt i32 %b, 20
437 br i1 %bc.2, label %true.2, label %false.2
439 true.2: ; %b in [21, 0)
440 ; Conditions below are false.
441 %f.3 = icmp eq i32 %b, 11
442 call void @use(i1 %f.3)
443 %f.4 = icmp eq i32 %b, 20
444 call void @use(i1 %f.4)
446 ; Conditions below are true.
447 %t.3 = icmp ugt i32 %b, 11
448 call void @use(i1 %t.3)
449 %t.4 = icmp ne i32 %b, 20
450 call void @use(i1 %t.4)
452 ; Conditions below cannot be simplified.
453 %c.3 = icmp eq i32 %b, 21
454 call void @use(i1 %c.3)
455 %c.4 = icmp ugt i32 %b, 21
456 call void @use(i1 %c.4)
457 %c.5 = icmp ugt i32 %b, 34
458 call void @use(i1 %c.5)
461 false.2: ;%b in [11, 21)
462 ; Conditions below are false;
463 %f.5 = icmp eq i32 %b, 21
464 call void @use(i1 %f.5)
465 %f.6 = icmp ugt i32 %b, 21
466 call void @use(i1 %f.6)
467 %f.7 = icmp ne i32 %b, 5
468 call void @use(i1 %f.7)
470 ; Conditions below are true;
471 %t.5 = icmp ne i32 %b, 21
472 call void @use(i1 %t.5)
473 %t.6 = icmp ult i32 %b, 21
474 call void @use(i1 %t.6)
475 %t.7 = icmp ne i32 %b, 5
476 call void @use(i1 %t.7)
478 ; Conditions below cannot be simplified.
479 %c.6 = icmp eq i32 %b, 11
480 call void @use(i1 %c.6)
481 %c.7 = icmp ne i32 %b, 15
482 call void @use(i1 %c.7)
490 ; Test with with nested conditions where the second conditions is more limiting than the first one.
491 define void @f10_cond_does_not_restrict_range(i32 %a, i32 %b) {
492 ; CHECK-LABEL: @f10_cond_does_not_restrict_range(
494 ; CHECK-NEXT: [[B_255:%.*]] = and i32 [[B:%.*]], 255
495 ; CHECK-NEXT: br label [[TRUE:%.*]]
497 ; CHECK-NEXT: call void @use(i1 false)
498 ; CHECK-NEXT: call void @use(i1 false)
499 ; CHECK-NEXT: call void @use(i1 true)
500 ; CHECK-NEXT: call void @use(i1 true)
501 ; CHECK-NEXT: call void @use(i1 true)
502 ; CHECK-NEXT: call void @use(i1 true)
503 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[B_255]], 11
504 ; CHECK-NEXT: call void @use(i1 [[C_1]])
505 ; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[B_255]], 30
506 ; CHECK-NEXT: call void @use(i1 [[C_2]])
507 ; CHECK-NEXT: ret void
510 %b.255 = and i32 %b, 255
511 %bc.1 = icmp ult i32 %b.255, 300
512 br i1 %bc.1, label %true, label %false
514 true: ; %b in [0, 256)
515 ; Conditions below are false.
516 %f.1 = icmp eq i32 %b.255, 256
517 call void @use(i1 %f.1)
518 %f.2 = icmp eq i32 %b.255, 300
519 call void @use(i1 %f.2)
521 ; Conditions below are true.
522 %t.1 = icmp ult i32 %b.255, 256
523 call void @use(i1 %t.1)
524 %t.2 = icmp ult i32 %b.255, 300
525 call void @use(i1 %t.2)
526 %t.3 = icmp ne i32 %b.255, 256
527 call void @use(i1 %t.3)
528 %t.4 = icmp ne i32 %b.255, 300
529 call void @use(i1 %t.4)
531 ; Conditions below cannot be simplified.
532 %c.1 = icmp eq i32 %b.255, 11
533 call void @use(i1 %c.1)
534 %c.2 = icmp ugt i32 %b.255, 30
535 call void @use(i1 %c.2)
542 define void @f11_contradiction(i32 %a, i32 %b) {
543 ; CHECK-LABEL: @f11_contradiction(
545 ; CHECK-NEXT: [[BC_1:%.*]] = icmp eq i32 [[B:%.*]], 10
546 ; CHECK-NEXT: br i1 [[BC_1]], label [[TRUE:%.*]], label [[FALSE:%.*]]
548 ; CHECK-NEXT: br label [[FALSE]]
550 ; CHECK-NEXT: ret void
553 %bc.1 = icmp eq i32 %b, 10
554 br i1 %bc.1, label %true, label %false
556 true: ; %b in [10, 11)
557 %bc.2 = icmp eq i32 %b, 20
558 br i1 %bc.2, label %true.2, label %false
561 %f.1 = icmp eq i32 %b, 256
562 call void @use(i1 %f.1)
563 %f.2 = icmp ne i32 %b, 300
564 call void @use(i1 %f.2)
571 define void @f12_float(float %b) {
572 ; CHECK-LABEL: @f12_float(
574 ; CHECK-NEXT: [[BC_1:%.*]] = fcmp olt float 1.000000e+00, [[B:%.*]]
575 ; CHECK-NEXT: br i1 [[BC_1]], label [[TRUE:%.*]], label [[FALSE:%.*]]
577 ; CHECK-NEXT: call void @use(i1 false)
578 ; CHECK-NEXT: call void @use(i1 true)
579 ; CHECK-NEXT: ret void
581 ; CHECK-NEXT: ret void
584 %a = fadd float 0.0, 1.0
585 %bc.1 = fcmp olt float %a, %b
586 br i1 %bc.1, label %true, label %false
588 true: ; %b in [10, 11)
589 %f.1 = fcmp one float %a, 1.0
590 call void @use(i1 %f.1)
592 %t.1 = fcmp oeq float %a, 1.0
593 call void @use(i1 %t.1)
604 define void @f13_constexpr1() {
605 ; CHECK-LABEL: @f13_constexpr1(
607 ; CHECK-NEXT: [[BC_1:%.*]] = icmp eq i32 add (i32 ptrtoint (i32* @A to i32), i32 10), 55
608 ; CHECK-NEXT: br i1 [[BC_1]], label [[TRUE:%.*]], label [[FALSE:%.*]]
610 ; CHECK-NEXT: call void @use(i1 false)
611 ; CHECK-NEXT: call void @use(i1 true)
612 ; CHECK-NEXT: ret void
614 ; CHECK-NEXT: ret void
617 %a = add i32 ptrtoint (i32* @A to i32), 10
618 %bc.1 = icmp eq i32 %a, 55
619 br i1 %bc.1, label %true, label %false
621 true: ; %b in [10, 11)
622 %f.1 = icmp eq i32 %a, 10
623 call void @use(i1 %f.1)
624 %f.2 = icmp eq i32 %a, 55
625 call void @use(i1 %f.2)
633 ; TODO: can we fold the compares in the true block?
634 define void @f14_constexpr2() {
635 ; CHECK-LABEL: @f14_constexpr2(
637 ; CHECK-NEXT: br i1 icmp eq (i32 ptrtoint (i32* @A to i32), i32 ptrtoint (i32* @B to i32)), label [[TRUE:%.*]], label [[FALSE:%.*]]
639 ; CHECK-NEXT: call void @use(i1 icmp ne (i32 ptrtoint (i32* @B to i32), i32 ptrtoint (i32* @A to i32)))
640 ; CHECK-NEXT: call void @use(i1 icmp eq (i32 ptrtoint (i32* @B to i32), i32 ptrtoint (i32* @A to i32)))
641 ; CHECK-NEXT: ret void
643 ; CHECK-NEXT: ret void
646 %a = add i32 ptrtoint (i32* @A to i32), 0
647 %b = add i32 ptrtoint (i32* @B to i32), 0
648 %bc.1 = icmp eq i32 %a, %b
649 br i1 %bc.1, label %true, label %false
651 true: ; %b in [10, 11)
652 %f.1 = icmp ne i32 %a, %b
653 call void @use(i1 %f.1)
654 %f.2 = icmp eq i32 %a, %b
655 call void @use(i1 %f.2)
663 define void @loop_1() {
664 ; CHECK-LABEL: @loop_1(
666 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
668 ; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC27:%.*]], [[FOR_COND_CLEANUP13:%.*]] ]
669 ; CHECK-NEXT: [[CMP9:%.*]] = icmp sle i32 [[I_0]], 3
670 ; CHECK-NEXT: br i1 [[CMP9]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]]
671 ; CHECK: for.cond.cleanup:
672 ; CHECK-NEXT: ret void
674 ; CHECK-NEXT: br label [[FOR_COND11:%.*]]
676 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP13]]
677 ; CHECK: for.cond.cleanup13:
678 ; CHECK-NEXT: [[INC27]] = add nsw i32 [[I_0]], 1
679 ; CHECK-NEXT: br label [[FOR_COND]]
684 for.cond: ; preds = %for.cond.cleanup13, %if.then
685 %i.0 = phi i32 [ 0, %entry ], [ %inc27, %for.cond.cleanup13 ]
686 %cmp9 = icmp sle i32 %i.0, 3
687 br i1 %cmp9, label %for.body, label %for.cond.cleanup
689 for.cond.cleanup: ; preds = %for.cond
692 for.body: ; preds = %for.cond
695 for.cond11: ; preds = %arrayctor.cont21, %for.body
696 br label %for.cond.cleanup13
698 for.cond.cleanup13: ; preds = %for.cond11
699 %inc27 = add nsw i32 %i.0, 1
704 define void @loop() {
705 ; CHECK-LABEL: @loop(
707 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
709 ; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC27:%.*]], [[FOR_COND_CLEANUP13:%.*]] ]
710 ; CHECK-NEXT: [[CMP9:%.*]] = icmp sle i32 [[I_0]], 3
711 ; CHECK-NEXT: br i1 [[CMP9]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]]
712 ; CHECK: for.cond.cleanup:
713 ; CHECK-NEXT: ret void
715 ; CHECK-NEXT: br label [[FOR_COND11:%.*]]
717 ; CHECK-NEXT: [[J_0:%.*]] = phi i32 [ 0, [[FOR_BODY]] ], [ [[INC:%.*]], [[FOR_BODY14:%.*]] ]
718 ; CHECK-NEXT: [[CMP12:%.*]] = icmp slt i32 [[J_0]], 2
719 ; CHECK-NEXT: br i1 [[CMP12]], label [[FOR_BODY14]], label [[FOR_COND_CLEANUP13]]
720 ; CHECK: for.cond.cleanup13:
721 ; CHECK-NEXT: [[INC27]] = add nsw i32 [[I_0]], 1
722 ; CHECK-NEXT: br label [[FOR_COND]]
724 ; CHECK-NEXT: [[INC]] = add nsw i32 [[J_0]], 1
725 ; CHECK-NEXT: br label [[FOR_COND11]]
730 for.cond: ; preds = %for.cond.cleanup13, %if.then
731 %i.0 = phi i32 [ 0, %entry ], [ %inc27, %for.cond.cleanup13 ]
732 %cmp9 = icmp sle i32 %i.0, 3
733 br i1 %cmp9, label %for.body, label %for.cond.cleanup
735 for.cond.cleanup: ; preds = %for.cond
738 for.body: ; preds = %for.cond
741 for.cond11: ; preds = %arrayctor.cont21, %for.body
742 %j.0 = phi i32 [ 0, %for.body ], [ %inc, %for.body14 ]
743 %cmp12 = icmp slt i32 %j.0, 2
744 br i1 %cmp12, label %for.body14, label %for.cond.cleanup13
746 for.cond.cleanup13: ; preds = %for.cond11
747 %inc27 = add nsw i32 %i.0, 1
751 %inc = add nsw i32 %j.0, 1
755 define i32 @udiv_1(i64 %sz) {
756 ; CHECK-LABEL: @udiv_1(
758 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 4088, [[SZ:%.*]]
759 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
761 ; CHECK-NEXT: [[DIV:%.*]] = udiv i64 4088, [[SZ]]
762 ; CHECK-NEXT: br label [[COND_END]]
764 ; CHECK-NEXT: [[COND:%.*]] = phi i64 [ [[DIV]], [[COND_TRUE]] ], [ 1, [[ENTRY:%.*]] ]
765 ; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[COND]] to i32
766 ; CHECK-NEXT: ret i32 [[CONV]]
769 %cmp = icmp ugt i64 4088, %sz
770 br i1 %cmp, label %cond.true, label %cond.end
772 cond.true: ; preds = %entry
773 %div = udiv i64 4088, %sz
776 cond.end: ; preds = %entry, %cond.true
777 %cond = phi i64 [ %div, %cond.true ], [ 1, %entry ]
778 %conv = trunc i64 %cond to i32
782 ; Same as @udiv_1, but with the condition switched.
783 define i32 @udiv_2(i64 %sz) {
784 ; CHECK-LABEL: @udiv_2(
786 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[SZ:%.*]], 4088
787 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
789 ; CHECK-NEXT: br label [[COND_END]]
791 ; CHECK-NEXT: [[COND:%.*]] = phi i64 [ 0, [[COND_TRUE]] ], [ 1, [[ENTRY:%.*]] ]
792 ; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[COND]] to i32
793 ; CHECK-NEXT: ret i32 [[CONV]]
796 %cmp = icmp ugt i64 %sz, 4088
797 br i1 %cmp, label %cond.true, label %cond.end
799 cond.true: ; preds = %entry
800 %div = udiv i64 4088, %sz
803 cond.end: ; preds = %entry, %cond.true
804 %cond = phi i64 [ %div, %cond.true ], [ 1, %entry ]
805 %conv = trunc i64 %cond to i32
809 define void @f16_conditions_and(i32 %a, i32 %b) {
810 ; CHECK-LABEL: @f16_conditions_and(
812 ; CHECK-NEXT: [[LT:%.*]] = icmp ult i32 [[A:%.*]], 100
813 ; CHECK-NEXT: [[GT:%.*]] = icmp ugt i32 [[A]], 20
814 ; CHECK-NEXT: [[BC:%.*]] = and i1 [[LT]], [[GT]]
815 ; CHECK-NEXT: br i1 [[BC]], label [[TRUE:%.*]], label [[FALSE:%.*]]
817 ; CHECK-NEXT: call void @use(i1 false)
818 ; CHECK-NEXT: call void @use(i1 false)
819 ; CHECK-NEXT: call void @use(i1 false)
820 ; CHECK-NEXT: call void @use(i1 true)
821 ; CHECK-NEXT: call void @use(i1 true)
822 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[A]], 21
823 ; CHECK-NEXT: call void @use(i1 [[C_1]])
824 ; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[A]], 21
825 ; CHECK-NEXT: call void @use(i1 [[C_2]])
826 ; CHECK-NEXT: [[C_3:%.*]] = icmp ugt i32 [[A]], 50
827 ; CHECK-NEXT: call void @use(i1 [[C_3]])
828 ; CHECK-NEXT: ret void
830 ; CHECK-NEXT: [[F_4:%.*]] = icmp eq i32 [[A]], 50
831 ; CHECK-NEXT: call void @use(i1 [[F_4]])
832 ; CHECK-NEXT: [[T_3:%.*]] = icmp ne i32 [[A]], 50
833 ; CHECK-NEXT: call void @use(i1 [[T_3]])
834 ; CHECK-NEXT: [[C_4:%.*]] = icmp eq i32 [[A]], 10
835 ; CHECK-NEXT: call void @use(i1 [[C_4]])
836 ; CHECK-NEXT: [[C_5:%.*]] = icmp eq i32 [[B:%.*]], 100
837 ; CHECK-NEXT: call void @use(i1 [[C_5]])
838 ; CHECK-NEXT: ret void
841 %lt = icmp ult i32 %a, 100
842 %gt = icmp ugt i32 %a, 20
843 %bc = and i1 %lt, %gt
844 br i1 %bc, label %true, label %false
846 true: ; %a in [21, 100)
847 ; Conditions below are false.
848 %f.1 = icmp eq i32 %a, 0
849 call void @use(i1 %f.1)
850 %f.2 = icmp eq i32 %a, 20
851 call void @use(i1 %f.2)
852 %f.3 = icmp ugt i32 %a, 100
853 call void @use(i1 %f.3)
855 ; Conditions below are true.
856 %t.1 = icmp ult i32 %a, 100
857 call void @use(i1 %t.1)
858 %t.2 = icmp ne i32 %a, 20
859 call void @use(i1 %t.2)
861 ; Conditions below cannot be simplified.
862 %c.1 = icmp eq i32 %a, 21
863 call void @use(i1 %c.1)
864 %c.2 = icmp ugt i32 %a, 21
865 call void @use(i1 %c.2)
866 %c.3 = icmp ugt i32 %a, 50
867 call void @use(i1 %c.3)
871 ; TODO: Currently there is no conditional range info in the false branch for branch conditions with an AND.
872 ; %a should be in in [100, 21)
873 ; Conditions below are false;
874 %f.4 = icmp eq i32 %a, 50
875 call void @use(i1 %f.4)
877 ; Conditions below are true;
878 %t.3 = icmp ne i32 %a, 50
879 call void @use(i1 %t.3)
881 ; Conditions below cannot be simplified.
882 %c.4 = icmp eq i32 %a, 10
883 call void @use(i1 %c.4)
884 %c.5 = icmp eq i32 %b, 100
885 call void @use(i1 %c.5)
889 define void @f16_conditions_and_logical(i32 %a, i32 %b) {
890 ; CHECK-LABEL: @f16_conditions_and_logical(
892 ; CHECK-NEXT: [[LT:%.*]] = icmp ult i32 [[A:%.*]], 100
893 ; CHECK-NEXT: [[GT:%.*]] = icmp ugt i32 [[A]], 20
894 ; CHECK-NEXT: [[BC:%.*]] = select i1 [[LT]], i1 [[GT]], i1 false
895 ; CHECK-NEXT: br i1 [[BC]], label [[TRUE:%.*]], label [[FALSE:%.*]]
897 ; CHECK-NEXT: call void @use(i1 false)
898 ; CHECK-NEXT: call void @use(i1 false)
899 ; CHECK-NEXT: call void @use(i1 false)
900 ; CHECK-NEXT: call void @use(i1 true)
901 ; CHECK-NEXT: call void @use(i1 true)
902 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[A]], 21
903 ; CHECK-NEXT: call void @use(i1 [[C_1]])
904 ; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[A]], 21
905 ; CHECK-NEXT: call void @use(i1 [[C_2]])
906 ; CHECK-NEXT: [[C_3:%.*]] = icmp ugt i32 [[A]], 50
907 ; CHECK-NEXT: call void @use(i1 [[C_3]])
908 ; CHECK-NEXT: ret void
910 ; CHECK-NEXT: [[F_4:%.*]] = icmp eq i32 [[A]], 50
911 ; CHECK-NEXT: call void @use(i1 [[F_4]])
912 ; CHECK-NEXT: [[T_3:%.*]] = icmp ne i32 [[A]], 50
913 ; CHECK-NEXT: call void @use(i1 [[T_3]])
914 ; CHECK-NEXT: [[C_4:%.*]] = icmp eq i32 [[A]], 10
915 ; CHECK-NEXT: call void @use(i1 [[C_4]])
916 ; CHECK-NEXT: [[C_5:%.*]] = icmp eq i32 [[B:%.*]], 100
917 ; CHECK-NEXT: call void @use(i1 [[C_5]])
918 ; CHECK-NEXT: ret void
921 %lt = icmp ult i32 %a, 100
922 %gt = icmp ugt i32 %a, 20
923 %bc = select i1 %lt, i1 %gt, i1 false
924 br i1 %bc, label %true, label %false
926 true: ; %a in [21, 100)
927 ; Conditions below are false.
928 %f.1 = icmp eq i32 %a, 0
929 call void @use(i1 %f.1)
930 %f.2 = icmp eq i32 %a, 20
931 call void @use(i1 %f.2)
932 %f.3 = icmp ugt i32 %a, 100
933 call void @use(i1 %f.3)
935 ; Conditions below are true.
936 %t.1 = icmp ult i32 %a, 100
937 call void @use(i1 %t.1)
938 %t.2 = icmp ne i32 %a, 20
939 call void @use(i1 %t.2)
941 ; Conditions below cannot be simplified.
942 %c.1 = icmp eq i32 %a, 21
943 call void @use(i1 %c.1)
944 %c.2 = icmp ugt i32 %a, 21
945 call void @use(i1 %c.2)
946 %c.3 = icmp ugt i32 %a, 50
947 call void @use(i1 %c.3)
951 ; TODO: Currently there is no conditional range info in the false branch for branch conditions with an AND.
952 ; %a should be in in [100, 21)
953 ; Conditions below are false;
954 %f.4 = icmp eq i32 %a, 50
955 call void @use(i1 %f.4)
957 ; Conditions below are true;
958 %t.3 = icmp ne i32 %a, 50
959 call void @use(i1 %t.3)
961 ; Conditions below cannot be simplified.
962 %c.4 = icmp eq i32 %a, 10
963 call void @use(i1 %c.4)
964 %c.5 = icmp eq i32 %b, 100
965 call void @use(i1 %c.5)
969 define void @f17_conditions_or(i32 %a, i32 %b) {
970 ; CHECK-LABEL: @f17_conditions_or(
972 ; CHECK-NEXT: [[GT:%.*]] = icmp uge i32 [[A:%.*]], 100
973 ; CHECK-NEXT: [[LT:%.*]] = icmp ule i32 [[A]], 20
974 ; CHECK-NEXT: [[BC:%.*]] = or i1 [[LT]], [[GT]]
975 ; CHECK-NEXT: br i1 [[BC]], label [[TRUE:%.*]], label [[FALSE:%.*]]
977 ; CHECK-NEXT: call void @use(i1 false)
978 ; CHECK-NEXT: call void @use(i1 false)
979 ; CHECK-NEXT: call void @use(i1 false)
980 ; CHECK-NEXT: call void @use(i1 true)
981 ; CHECK-NEXT: call void @use(i1 true)
982 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[A]], 21
983 ; CHECK-NEXT: call void @use(i1 [[C_1]])
984 ; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[A]], 21
985 ; CHECK-NEXT: call void @use(i1 [[C_2]])
986 ; CHECK-NEXT: [[C_3:%.*]] = icmp ugt i32 [[A]], 50
987 ; CHECK-NEXT: call void @use(i1 [[C_3]])
988 ; CHECK-NEXT: ret void
990 ; CHECK-NEXT: [[F_4:%.*]] = icmp eq i32 [[A]], 50
991 ; CHECK-NEXT: call void @use(i1 [[F_4]])
992 ; CHECK-NEXT: [[T_3:%.*]] = icmp ne i32 [[A]], 50
993 ; CHECK-NEXT: call void @use(i1 [[T_3]])
994 ; CHECK-NEXT: [[C_4:%.*]] = icmp eq i32 [[A]], 10
995 ; CHECK-NEXT: call void @use(i1 [[C_4]])
996 ; CHECK-NEXT: [[C_5:%.*]] = icmp eq i32 [[B:%.*]], 100
997 ; CHECK-NEXT: call void @use(i1 [[C_5]])
998 ; CHECK-NEXT: ret void
1001 %gt = icmp uge i32 %a, 100
1002 %lt = icmp ule i32 %a, 20
1003 %bc = or i1 %lt, %gt
1004 br i1 %bc, label %true, label %false
1006 false: ; %a in [21, 100)
1007 ; Conditions below are false.
1008 %f.1 = icmp eq i32 %a, 0
1009 call void @use(i1 %f.1)
1010 %f.2 = icmp eq i32 %a, 20
1011 call void @use(i1 %f.2)
1012 %f.3 = icmp ugt i32 %a, 100
1013 call void @use(i1 %f.3)
1015 ; Conditions below are true.
1016 %t.1 = icmp ult i32 %a, 100
1017 call void @use(i1 %t.1)
1018 %t.2 = icmp ne i32 %a, 20
1019 call void @use(i1 %t.2)
1021 ; Conditions below cannot be simplified.
1022 %c.1 = icmp eq i32 %a, 21
1023 call void @use(i1 %c.1)
1024 %c.2 = icmp ugt i32 %a, 21
1025 call void @use(i1 %c.2)
1026 %c.3 = icmp ugt i32 %a, 50
1027 call void @use(i1 %c.3)
1031 ; TODO: Currently there is no conditional range info in the false branch for branch conditions with an AND.
1032 ; %a should be in in [100, 21)
1033 ; Conditions below are false;
1034 %f.4 = icmp eq i32 %a, 50
1035 call void @use(i1 %f.4)
1037 ; Conditions below are true;
1038 %t.3 = icmp ne i32 %a, 50
1039 call void @use(i1 %t.3)
1041 ; Conditions below cannot be simplified.
1042 %c.4 = icmp eq i32 %a, 10
1043 call void @use(i1 %c.4)
1044 %c.5 = icmp eq i32 %b, 100
1045 call void @use(i1 %c.5)
1049 define void @f17_conditions_or_logical(i32 %a, i32 %b) {
1050 ; CHECK-LABEL: @f17_conditions_or_logical(
1051 ; CHECK-NEXT: entry:
1052 ; CHECK-NEXT: [[GT:%.*]] = icmp uge i32 [[A:%.*]], 100
1053 ; CHECK-NEXT: [[LT:%.*]] = icmp ule i32 [[A]], 20
1054 ; CHECK-NEXT: [[BC:%.*]] = select i1 [[LT]], i1 true, i1 [[GT]]
1055 ; CHECK-NEXT: br i1 [[BC]], label [[TRUE:%.*]], label [[FALSE:%.*]]
1057 ; CHECK-NEXT: call void @use(i1 false)
1058 ; CHECK-NEXT: call void @use(i1 false)
1059 ; CHECK-NEXT: call void @use(i1 false)
1060 ; CHECK-NEXT: call void @use(i1 true)
1061 ; CHECK-NEXT: call void @use(i1 true)
1062 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[A]], 21
1063 ; CHECK-NEXT: call void @use(i1 [[C_1]])
1064 ; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[A]], 21
1065 ; CHECK-NEXT: call void @use(i1 [[C_2]])
1066 ; CHECK-NEXT: [[C_3:%.*]] = icmp ugt i32 [[A]], 50
1067 ; CHECK-NEXT: call void @use(i1 [[C_3]])
1068 ; CHECK-NEXT: ret void
1070 ; CHECK-NEXT: [[F_4:%.*]] = icmp eq i32 [[A]], 50
1071 ; CHECK-NEXT: call void @use(i1 [[F_4]])
1072 ; CHECK-NEXT: [[T_3:%.*]] = icmp ne i32 [[A]], 50
1073 ; CHECK-NEXT: call void @use(i1 [[T_3]])
1074 ; CHECK-NEXT: [[C_4:%.*]] = icmp eq i32 [[A]], 10
1075 ; CHECK-NEXT: call void @use(i1 [[C_4]])
1076 ; CHECK-NEXT: [[C_5:%.*]] = icmp eq i32 [[B:%.*]], 100
1077 ; CHECK-NEXT: call void @use(i1 [[C_5]])
1078 ; CHECK-NEXT: ret void
1081 %gt = icmp uge i32 %a, 100
1082 %lt = icmp ule i32 %a, 20
1083 %bc = select i1 %lt, i1 true, i1 %gt
1084 br i1 %bc, label %true, label %false
1086 false: ; %a in [21, 100)
1087 ; Conditions below are false.
1088 %f.1 = icmp eq i32 %a, 0
1089 call void @use(i1 %f.1)
1090 %f.2 = icmp eq i32 %a, 20
1091 call void @use(i1 %f.2)
1092 %f.3 = icmp ugt i32 %a, 100
1093 call void @use(i1 %f.3)
1095 ; Conditions below are true.
1096 %t.1 = icmp ult i32 %a, 100
1097 call void @use(i1 %t.1)
1098 %t.2 = icmp ne i32 %a, 20
1099 call void @use(i1 %t.2)
1101 ; Conditions below cannot be simplified.
1102 %c.1 = icmp eq i32 %a, 21
1103 call void @use(i1 %c.1)
1104 %c.2 = icmp ugt i32 %a, 21
1105 call void @use(i1 %c.2)
1106 %c.3 = icmp ugt i32 %a, 50
1107 call void @use(i1 %c.3)
1111 ; TODO: Currently there is no conditional range info in the false branch for branch conditions with an AND.
1112 ; %a should be in in [100, 21)
1113 ; Conditions below are false;
1114 %f.4 = icmp eq i32 %a, 50
1115 call void @use(i1 %f.4)
1117 ; Conditions below are true;
1118 %t.3 = icmp ne i32 %a, 50
1119 call void @use(i1 %t.3)
1121 ; Conditions below cannot be simplified.
1122 %c.4 = icmp eq i32 %a, 10
1123 call void @use(i1 %c.4)
1124 %c.5 = icmp eq i32 %b, 100
1125 call void @use(i1 %c.5)
1129 define void @f18_conditions_chained_and(i32 %a, i32 %b) {
1130 ; CHECK-LABEL: @f18_conditions_chained_and(
1131 ; CHECK-NEXT: entry:
1132 ; CHECK-NEXT: [[LT:%.*]] = icmp ult i32 [[A:%.*]], 100
1133 ; CHECK-NEXT: [[GT:%.*]] = icmp ugt i32 [[A]], 20
1134 ; CHECK-NEXT: [[BC:%.*]] = and i1 [[LT]], [[GT]]
1135 ; CHECK-NEXT: [[B_LT:%.*]] = icmp ult i32 [[B:%.*]], 50
1136 ; CHECK-NEXT: [[BC_2:%.*]] = and i1 [[BC]], [[B_LT]]
1137 ; CHECK-NEXT: br i1 [[BC_2]], label [[TRUE:%.*]], label [[FALSE:%.*]]
1139 ; CHECK-NEXT: call void @use(i1 false)
1140 ; CHECK-NEXT: call void @use(i1 false)
1141 ; CHECK-NEXT: call void @use(i1 false)
1142 ; CHECK-NEXT: call void @use(i1 false)
1143 ; CHECK-NEXT: call void @use(i1 true)
1144 ; CHECK-NEXT: call void @use(i1 true)
1145 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[A]], 21
1146 ; CHECK-NEXT: call void @use(i1 [[C_1]])
1147 ; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[A]], 21
1148 ; CHECK-NEXT: call void @use(i1 [[C_2]])
1149 ; CHECK-NEXT: [[C_3:%.*]] = icmp ugt i32 [[A]], 50
1150 ; CHECK-NEXT: call void @use(i1 [[C_3]])
1151 ; CHECK-NEXT: [[C_4:%.*]] = icmp eq i32 [[B]], 0
1152 ; CHECK-NEXT: call void @use(i1 [[C_4]])
1153 ; CHECK-NEXT: [[C_5:%.*]] = icmp eq i32 [[B]], 20
1154 ; CHECK-NEXT: call void @use(i1 [[C_5]])
1155 ; CHECK-NEXT: ret void
1157 ; CHECK-NEXT: [[F_5:%.*]] = icmp eq i32 [[A]], 50
1158 ; CHECK-NEXT: call void @use(i1 [[F_5]])
1159 ; CHECK-NEXT: [[T_3:%.*]] = icmp ne i32 [[A]], 50
1160 ; CHECK-NEXT: call void @use(i1 [[T_3]])
1161 ; CHECK-NEXT: [[C_6:%.*]] = icmp eq i32 [[A]], 10
1162 ; CHECK-NEXT: call void @use(i1 [[C_6]])
1163 ; CHECK-NEXT: [[C_7:%.*]] = icmp eq i32 [[B]], 100
1164 ; CHECK-NEXT: call void @use(i1 [[C_7]])
1165 ; CHECK-NEXT: ret void
1168 %lt = icmp ult i32 %a, 100
1169 %gt = icmp ugt i32 %a, 20
1170 %bc = and i1 %lt, %gt
1171 %b.lt = icmp ult i32 %b, 50
1172 %bc.2 = and i1 %bc, %b.lt
1173 br i1 %bc.2, label %true, label %false
1175 true: ; %a in [21, 100)
1176 ; Conditions below are false.
1177 %f.1 = icmp eq i32 %a, 0
1178 call void @use(i1 %f.1)
1179 %f.2 = icmp eq i32 %a, 20
1180 call void @use(i1 %f.2)
1181 %f.3 = icmp ugt i32 %a, 100
1182 call void @use(i1 %f.3)
1183 %f.4 = icmp ugt i32 %b, 100
1184 call void @use(i1 %f.4)
1187 ; Conditions below are true.
1188 %t.1 = icmp ult i32 %a, 100
1189 call void @use(i1 %t.1)
1190 %t.2 = icmp ne i32 %a, 20
1191 call void @use(i1 %t.2)
1193 ; Conditions below cannot be simplified.
1194 %c.1 = icmp eq i32 %a, 21
1195 call void @use(i1 %c.1)
1196 %c.2 = icmp ugt i32 %a, 21
1197 call void @use(i1 %c.2)
1198 %c.3 = icmp ugt i32 %a, 50
1199 call void @use(i1 %c.3)
1200 %c.4 = icmp eq i32 %b, 0
1201 call void @use(i1 %c.4)
1202 %c.5 = icmp eq i32 %b, 20
1203 call void @use(i1 %c.5)
1207 ; Conditions below are false;
1208 %f.5 = icmp eq i32 %a, 50
1209 call void @use(i1 %f.5)
1211 ; Conditions below are true;
1212 %t.3 = icmp ne i32 %a, 50
1213 call void @use(i1 %t.3)
1215 ; Conditions below cannot be simplified.
1216 %c.6 = icmp eq i32 %a, 10
1217 call void @use(i1 %c.6)
1218 %c.7 = icmp eq i32 %b, 100
1219 call void @use(i1 %c.7)
1223 define void @f19_conditions_chained_and_nested_and(i32 %a, i32 %b) {
1224 ; CHECK-LABEL: @f19_conditions_chained_and_nested_and(
1225 ; CHECK-NEXT: entry:
1226 ; CHECK-NEXT: [[LT_A:%.*]] = icmp ult i32 [[A:%.*]], 100
1227 ; CHECK-NEXT: [[LT_B:%.*]] = icmp ult i32 [[B:%.*]], 1000
1228 ; CHECK-NEXT: [[BC:%.*]] = and i1 [[LT_A]], [[LT_B]]
1229 ; CHECK-NEXT: br i1 [[BC]], label [[TRUE:%.*]], label [[FALSE:%.*]]
1231 ; CHECK-NEXT: [[GT_A:%.*]] = icmp ugt i32 [[A]], 30
1232 ; CHECK-NEXT: [[GT_B:%.*]] = icmp ugt i32 [[B]], 300
1233 ; CHECK-NEXT: [[BC_2:%.*]] = and i1 [[GT_A]], [[GT_B]]
1234 ; CHECK-NEXT: br i1 [[BC_2]], label [[TRUE_2:%.*]], label [[FALSE]]
1236 ; CHECK-NEXT: call void @use(i1 false)
1237 ; CHECK-NEXT: call void @use(i1 false)
1238 ; CHECK-NEXT: call void @use(i1 false)
1239 ; CHECK-NEXT: call void @use(i1 false)
1240 ; CHECK-NEXT: call void @use(i1 false)
1241 ; CHECK-NEXT: call void @use(i1 false)
1242 ; CHECK-NEXT: call void @use(i1 true)
1243 ; CHECK-NEXT: call void @use(i1 true)
1244 ; CHECK-NEXT: call void @use(i1 true)
1245 ; CHECK-NEXT: call void @use(i1 true)
1246 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[A]], 31
1247 ; CHECK-NEXT: call void @use(i1 [[C_1]])
1248 ; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[A]], 31
1249 ; CHECK-NEXT: call void @use(i1 [[C_2]])
1250 ; CHECK-NEXT: [[C_3:%.*]] = icmp ugt i32 [[A]], 50
1251 ; CHECK-NEXT: call void @use(i1 [[C_3]])
1252 ; CHECK-NEXT: [[C_4:%.*]] = icmp eq i32 [[B]], 301
1253 ; CHECK-NEXT: call void @use(i1 [[C_4]])
1254 ; CHECK-NEXT: [[C_5:%.*]] = icmp ugt i32 [[B]], 301
1255 ; CHECK-NEXT: call void @use(i1 [[C_5]])
1256 ; CHECK-NEXT: [[C_6:%.*]] = icmp ugt i32 [[B]], 500
1257 ; CHECK-NEXT: call void @use(i1 [[C_6]])
1258 ; CHECK-NEXT: ret void
1260 ; CHECK-NEXT: ret void
1263 %lt.a = icmp ult i32 %a, 100
1264 %lt.b = icmp ult i32 %b, 1000
1265 %bc = and i1 %lt.a, %lt.b
1266 br i1 %bc, label %true, label %false
1269 %gt.a = icmp ugt i32 %a, 30
1270 %gt.b = icmp ugt i32 %b, 300
1271 %bc.2 = and i1 %gt.a, %gt.b
1272 br i1 %bc.2, label %true.2, label %false
1275 ; Conditions below are false.
1276 %f.1 = icmp eq i32 %a, 0
1277 call void @use(i1 %f.1)
1278 %f.2 = icmp eq i32 %a, 20
1279 call void @use(i1 %f.2)
1280 %f.3 = icmp ugt i32 %a, 100
1281 call void @use(i1 %f.3)
1282 %f.4 = icmp eq i32 %b, 0
1283 call void @use(i1 %f.4)
1284 %f.5 = icmp eq i32 %b, 300
1285 call void @use(i1 %f.5)
1286 %f.6 = icmp ugt i32 %b, 1000
1287 call void @use(i1 %f.6)
1290 ; Conditions below are true.
1291 %t.1 = icmp ult i32 %a, 100
1292 call void @use(i1 %t.1)
1293 %t.2 = icmp ne i32 %a, 20
1294 call void @use(i1 %t.2)
1295 %t.3 = icmp ult i32 %b, 1000
1296 call void @use(i1 %t.3)
1297 %t.4 = icmp ne i32 %b, 300
1298 call void @use(i1 %t.4)
1301 ; Conditions below cannot be simplified.
1302 %c.1 = icmp eq i32 %a, 31
1303 call void @use(i1 %c.1)
1304 %c.2 = icmp ugt i32 %a, 31
1305 call void @use(i1 %c.2)
1306 %c.3 = icmp ugt i32 %a, 50
1307 call void @use(i1 %c.3)
1308 %c.4 = icmp eq i32 %b, 301
1309 call void @use(i1 %c.4)
1310 %c.5 = icmp ugt i32 %b, 301
1311 call void @use(i1 %c.5)
1312 %c.6 = icmp ugt i32 %b, 500
1313 call void @use(i1 %c.6)
1321 declare i64 @get_i64()
1325 define void @f20_ne_0_nuked_by_and(i32 %arg) local_unnamed_addr #0 {
1326 ; CHECK-LABEL: @f20_ne_0_nuked_by_and(
1328 ; CHECK-NEXT: br label [[BB122:%.*]]
1330 ; CHECK-NEXT: [[TMP123:%.*]] = phi i32 [ 256, [[BB11:%.*]] ], [ [[TMP136:%.*]], [[BB135:%.*]] ]
1331 ; CHECK-NEXT: [[TMP127:%.*]] = call i64 @get_i64()
1332 ; CHECK-NEXT: [[TMP128:%.*]] = trunc i64 [[TMP127]] to i32
1333 ; CHECK-NEXT: [[TMP131:%.*]] = icmp ne i32 [[TMP128]], 0
1334 ; CHECK-NEXT: [[TMP132:%.*]] = icmp sgt i32 [[TMP123]], [[TMP128]]
1335 ; CHECK-NEXT: [[TMP133:%.*]] = and i1 [[TMP131]], [[TMP132]]
1336 ; CHECK-NEXT: br i1 [[TMP133]], label [[BB134:%.*]], label [[BB135]]
1338 ; CHECK-NEXT: br label [[BB135]]
1340 ; CHECK-NEXT: [[TMP136]] = phi i32 [ [[TMP123]], [[BB122]] ], [ [[TMP128]], [[BB134]] ]
1341 ; CHECK-NEXT: [[BC:%.*]] = call i1 @cond()
1342 ; CHECK-NEXT: br i1 [[BC]], label [[BB139:%.*]], label [[BB122]]
1344 ; CHECK-NEXT: call void @use(i1 false)
1345 ; CHECK-NEXT: ret void
1347 bb11: ; preds = %bb1
1350 bb122: ; preds = %bb135, %bb120
1351 %tmp123 = phi i32 [ 256, %bb11 ], [ %tmp136, %bb135 ]
1352 %tmp127 = call i64 @get_i64()
1353 %tmp128 = trunc i64 %tmp127 to i32
1354 %tmp131 = icmp ne i32 %tmp128, 0
1355 %tmp132 = icmp sgt i32 %tmp123, %tmp128
1356 %tmp133 = and i1 %tmp131, %tmp132
1357 br i1 %tmp133, label %bb134, label %bb135
1359 bb134: ; preds = %bb122
1362 bb135: ; preds = %bb134, %bb122
1363 %tmp136 = phi i32 [ %tmp123, %bb122 ], [ %tmp128, %bb134 ]
1364 %bc = call i1 @cond()
1365 br i1 %bc, label %bb139, label %bb122
1367 bb139: ; preds = %bb135
1368 %tmp140 = icmp eq i32 %tmp136, 0
1369 call void @use(i1 %tmp140)
1372 bb142: ; preds = %bb139