1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -correlated-propagation -S | FileCheck %s
5 define i32 @test1(i1 %C) {
7 ; CHECK-NEXT: br i1 [[C:%.*]], label [[EXIT:%.*]], label [[BODY:%.*]]
9 ; CHECK-NEXT: ret i32 11
11 ; CHECK-NEXT: ret i32 10
13 br i1 %C, label %exit, label %body
16 %A = select i1 %C, i32 10, i32 11
26 ; CHECK-LABEL: @test2(
28 ; CHECK-NEXT: [[COND:%.*]] = tail call i1 @ext()
29 ; CHECK-NEXT: br i1 [[COND]], label [[BB1:%.*]], label [[BB2:%.*]]
31 ; CHECK-NEXT: [[COND2:%.*]] = tail call i1 @ext()
32 ; CHECK-NEXT: br i1 [[COND2]], label [[BB3:%.*]], label [[BB2]]
34 ; CHECK-NEXT: ret i1 false
36 ; CHECK-NEXT: [[RES:%.*]] = tail call i1 @ext()
37 ; CHECK-NEXT: ret i1 [[RES]]
40 %cond = tail call i1 @ext()
41 br i1 %cond, label %bb1, label %bb2
44 %cond2 = tail call i1 @ext()
45 br i1 %cond2, label %bb3, label %bb2
48 %cond_merge = phi i1 [ %cond, %entry ], [ false, %bb1 ]
52 %res = tail call i1 @ext()
57 @gv = internal constant i8 7
58 define i8 @test3(i8* %a) nounwind {
59 ; CHECK-LABEL: @test3(
61 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i8* [[A:%.*]], @gv
62 ; CHECK-NEXT: br i1 [[COND]], label [[BB2:%.*]], label [[BB:%.*]]
64 ; CHECK-NEXT: ret i8 0
66 ; CHECK-NEXT: [[SHOULD_BE_CONST:%.*]] = load i8, i8* @gv
67 ; CHECK-NEXT: ret i8 [[SHOULD_BE_CONST]]
70 %cond = icmp eq i8* %a, @gv
71 br i1 %cond, label %bb2, label %bb
77 %should_be_const = load i8, i8* %a
78 ret i8 %should_be_const
82 define i32 @test4(i32) {
83 ; CHECK-LABEL: @test4(
84 ; CHECK-NEXT: EntryBlock:
85 ; CHECK-NEXT: [[DOTDEMORGAN:%.*]] = icmp sgt i32 [[TMP0:%.*]], 2
86 ; CHECK-NEXT: br i1 [[DOTDEMORGAN]], label [[GREATERTHANTWO:%.*]], label [[LESSTHANOREQUALTOTWO:%.*]]
87 ; CHECK: GreaterThanTwo:
88 ; CHECK-NEXT: br i1 false, label [[IMPOSSIBLE:%.*]], label [[NOTTWOANDGREATERTHANTWO:%.*]]
89 ; CHECK: NotTwoAndGreaterThanTwo:
90 ; CHECK-NEXT: ret i32 2
92 ; CHECK-NEXT: ret i32 1
93 ; CHECK: LessThanOrEqualToTwo:
94 ; CHECK-NEXT: ret i32 0
97 %.demorgan = icmp sgt i32 %0, 2
98 br i1 %.demorgan, label %GreaterThanTwo, label %LessThanOrEqualToTwo
102 br i1 %1, label %Impossible, label %NotTwoAndGreaterThanTwo
104 NotTwoAndGreaterThanTwo:
110 LessThanOrEqualToTwo:
114 declare i32* @f(i32*)
115 define void @test5(i32* %x, i32* %y) {
116 ; CHECK-LABEL: @test5(
118 ; CHECK-NEXT: [[PRE:%.*]] = icmp eq i32* [[X:%.*]], null
119 ; CHECK-NEXT: br i1 [[PRE]], label [[RETURN:%.*]], label [[LOOP:%.*]]
121 ; CHECK-NEXT: [[PHI:%.*]] = phi i32* [ [[F:%.*]], [[LOOP]] ], [ [[X]], [[ENTRY:%.*]] ]
122 ; CHECK-NEXT: [[F]] = tail call i32* @f(i32* [[PHI]])
123 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32* [[F]], [[Y:%.*]]
124 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP1]], i32* [[F]], i32* null
125 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32* [[SEL]], null
126 ; CHECK-NEXT: br i1 [[CMP2]], label [[RETURN]], label [[LOOP]]
128 ; CHECK-NEXT: ret void
131 %pre = icmp eq i32* %x, null
132 br i1 %pre, label %return, label %loop
135 %phi = phi i32* [ %sel, %loop ], [ %x, %entry ]
136 %f = tail call i32* @f(i32* %phi)
137 %cmp1 = icmp ne i32* %f, %y
138 %sel = select i1 %cmp1, i32* %f, i32* null
139 %cmp2 = icmp eq i32* %sel, null
140 br i1 %cmp2, label %return, label %loop
146 define i32 @switch1(i32 %s) {
147 ; CHECK-LABEL: @switch1(
149 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[S:%.*]], 0
150 ; CHECK-NEXT: br i1 [[CMP]], label [[NEGATIVE:%.*]], label [[OUT:%.*]]
152 ; CHECK-NEXT: switch i32 [[S]], label [[OUT]] [
153 ; CHECK-NEXT: i32 -2, label [[NEXT:%.*]]
154 ; CHECK-NEXT: i32 -1, label [[NEXT]]
157 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ -1, [[NEGATIVE]] ]
158 ; CHECK-NEXT: ret i32 [[P]]
160 ; CHECK-NEXT: ret i32 0
163 %cmp = icmp slt i32 %s, 0
164 br i1 %cmp, label %negative, label %out
167 switch i32 %s, label %out [
177 %p = phi i32 [ 1, %entry ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ]
181 %q = phi i32 [ 0, %negative ], [ 0, %negative ]
185 define i32 @switch2(i32 %s) {
186 ; CHECK-LABEL: @switch2(
188 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[S:%.*]], 0
189 ; CHECK-NEXT: br i1 [[CMP]], label [[POSITIVE:%.*]], label [[OUT:%.*]]
191 ; CHECK-NEXT: br label [[OUT]]
193 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ -1, [[ENTRY:%.*]] ], [ 1, [[POSITIVE]] ]
194 ; CHECK-NEXT: ret i32 [[P]]
196 ; CHECK-NEXT: ret i32 0
199 %cmp = icmp sgt i32 %s, 0
200 br i1 %cmp, label %positive, label %out
203 switch i32 %s, label %out [
210 %p = phi i32 [ -1, %entry ], [ 1, %positive ], [ 1, %positive ]
214 %q = phi i32 [ 0, %positive ], [ 0, %positive ]
218 define i32 @switch3(i32 %s) {
219 ; CHECK-LABEL: @switch3(
221 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[S:%.*]], 0
222 ; CHECK-NEXT: br i1 [[CMP]], label [[POSITIVE:%.*]], label [[OUT:%.*]]
224 ; CHECK-NEXT: br label [[OUT]]
226 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ -1, [[ENTRY:%.*]] ], [ 1, [[POSITIVE]] ]
227 ; CHECK-NEXT: ret i32 [[P]]
229 ; CHECK-NEXT: ret i32 0
232 %cmp = icmp sgt i32 %s, 0
233 br i1 %cmp, label %positive, label %out
236 switch i32 %s, label %out [
243 %p = phi i32 [ -1, %entry ], [ 1, %positive ], [ 1, %positive ]
247 %q = phi i32 [ 0, %positive ], [ 0, %positive ]
251 define void @switch4(i32 %s) {
252 ; CHECK-LABEL: @switch4(
254 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[S:%.*]], 0
255 ; CHECK-NEXT: br i1 [[CMP]], label [[ZERO:%.*]], label [[OUT:%.*]]
257 ; CHECK-NEXT: br label [[NEXT:%.*]]
259 ; CHECK-NEXT: ret void
261 ; CHECK-NEXT: ret void
264 %cmp = icmp eq i32 %s, 0
265 br i1 %cmp, label %zero, label %out
268 switch i32 %s, label %out [
281 define i1 @arg_attribute(i8* nonnull %a) {
282 ; CHECK-LABEL: @arg_attribute(
283 ; CHECK-NEXT: br label [[EXIT:%.*]]
285 ; CHECK-NEXT: ret i1 false
287 %cmp = icmp eq i8* %a, null
294 declare nonnull i8* @return_nonnull()
295 define i1 @call_attribute() {
296 ; CHECK-LABEL: @call_attribute(
297 ; CHECK-NEXT: [[A:%.*]] = call i8* @return_nonnull()
298 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[A]], null
299 ; CHECK-NEXT: br label [[EXIT:%.*]]
301 ; CHECK-NEXT: ret i1 false
303 %a = call i8* @return_nonnull()
304 %cmp = icmp eq i8* %a, null
311 define i1 @umin(i32 %a, i32 %b) {
312 ; CHECK-LABEL: @umin(
314 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[A:%.*]], 5
315 ; CHECK-NEXT: br i1 [[CMP]], label [[A_GUARD:%.*]], label [[OUT:%.*]]
317 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i32 [[B:%.*]], 20
318 ; CHECK-NEXT: br i1 [[CMP2]], label [[B_GUARD:%.*]], label [[OUT]]
320 ; CHECK-NEXT: [[SEL_CMP:%.*]] = icmp ult i32 [[A]], [[B]]
321 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[SEL_CMP]], i32 [[A]], i32 [[B]]
322 ; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[MIN]], 7
323 ; CHECK-NEXT: br label [[NEXT:%.*]]
325 ; CHECK-NEXT: ret i1 false
327 ; CHECK-NEXT: ret i1 false
330 %cmp = icmp ult i32 %a, 5
331 br i1 %cmp, label %a_guard, label %out
334 %cmp2 = icmp ult i32 %b, 20
335 br i1 %cmp2, label %b_guard, label %out
338 %sel_cmp = icmp ult i32 %a, %b
339 %min = select i1 %sel_cmp, i32 %a, i32 %b
340 %res = icmp eq i32 %min, 7
348 define i1 @smin(i32 %a, i32 %b) {
349 ; CHECK-LABEL: @smin(
351 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[A:%.*]], 5
352 ; CHECK-NEXT: br i1 [[CMP]], label [[A_GUARD:%.*]], label [[OUT:%.*]]
354 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i32 [[B:%.*]], 20
355 ; CHECK-NEXT: br i1 [[CMP2]], label [[B_GUARD:%.*]], label [[OUT]]
357 ; CHECK-NEXT: [[SEL_CMP:%.*]] = icmp sle i32 [[A]], [[B]]
358 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[SEL_CMP]], i32 [[A]], i32 [[B]]
359 ; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[MIN]], 7
360 ; CHECK-NEXT: br label [[NEXT:%.*]]
362 ; CHECK-NEXT: ret i1 false
364 ; CHECK-NEXT: ret i1 false
367 %cmp = icmp ult i32 %a, 5
368 br i1 %cmp, label %a_guard, label %out
371 %cmp2 = icmp ult i32 %b, 20
372 br i1 %cmp2, label %b_guard, label %out
375 %sel_cmp = icmp sle i32 %a, %b
376 %min = select i1 %sel_cmp, i32 %a, i32 %b
377 %res = icmp eq i32 %min, 7
385 define i1 @smax(i32 %a, i32 %b) {
386 ; CHECK-LABEL: @smax(
388 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A:%.*]], 5
389 ; CHECK-NEXT: br i1 [[CMP]], label [[A_GUARD:%.*]], label [[OUT:%.*]]
391 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[B:%.*]], 20
392 ; CHECK-NEXT: br i1 [[CMP2]], label [[B_GUARD:%.*]], label [[OUT]]
394 ; CHECK-NEXT: [[SEL_CMP:%.*]] = icmp sge i32 [[A]], [[B]]
395 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[SEL_CMP]], i32 [[A]], i32 [[B]]
396 ; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[MAX]], 7
397 ; CHECK-NEXT: br label [[NEXT:%.*]]
399 ; CHECK-NEXT: ret i1 false
401 ; CHECK-NEXT: ret i1 false
404 %cmp = icmp sgt i32 %a, 5
405 br i1 %cmp, label %a_guard, label %out
408 %cmp2 = icmp sgt i32 %b, 20
409 br i1 %cmp2, label %b_guard, label %out
412 %sel_cmp = icmp sge i32 %a, %b
413 %max = select i1 %sel_cmp, i32 %a, i32 %b
414 %res = icmp eq i32 %max, 7
422 define i1 @umax(i32 %a, i32 %b) {
423 ; CHECK-LABEL: @umax(
425 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A:%.*]], 5
426 ; CHECK-NEXT: br i1 [[CMP]], label [[A_GUARD:%.*]], label [[OUT:%.*]]
428 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[B:%.*]], 20
429 ; CHECK-NEXT: br i1 [[CMP2]], label [[B_GUARD:%.*]], label [[OUT]]
431 ; CHECK-NEXT: [[SEL_CMP:%.*]] = icmp uge i32 [[A]], [[B]]
432 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[SEL_CMP]], i32 [[A]], i32 [[B]]
433 ; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[MAX]], 7
434 ; CHECK-NEXT: br label [[NEXT:%.*]]
436 ; CHECK-NEXT: ret i1 false
438 ; CHECK-NEXT: ret i1 false
441 %cmp = icmp sgt i32 %a, 5
442 br i1 %cmp, label %a_guard, label %out
445 %cmp2 = icmp sgt i32 %b, 20
446 br i1 %cmp2, label %b_guard, label %out
449 %sel_cmp = icmp uge i32 %a, %b
450 %max = select i1 %sel_cmp, i32 %a, i32 %b
451 %res = icmp eq i32 %max, 7
459 define i1 @clamp_low1(i32 %a) {
460 ; CHECK-LABEL: @clamp_low1(
462 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[A:%.*]], 5
463 ; CHECK-NEXT: br i1 [[CMP]], label [[A_GUARD:%.*]], label [[OUT:%.*]]
465 ; CHECK-NEXT: [[SEL_CMP:%.*]] = icmp eq i32 [[A]], 5
466 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[A]], -1
467 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[SEL_CMP]], i32 5, i32 [[A]]
468 ; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[SEL]], 4
469 ; CHECK-NEXT: br label [[NEXT:%.*]]
471 ; CHECK-NEXT: ret i1 false
473 ; CHECK-NEXT: ret i1 false
476 %cmp = icmp sge i32 %a, 5
477 br i1 %cmp, label %a_guard, label %out
480 %sel_cmp = icmp eq i32 %a, 5
481 %add = add i32 %a, -1
482 %sel = select i1 %sel_cmp, i32 5, i32 %a
483 %res = icmp eq i32 %sel, 4
491 define i1 @clamp_low2(i32 %a) {
492 ; CHECK-LABEL: @clamp_low2(
494 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[A:%.*]], 5
495 ; CHECK-NEXT: br i1 [[CMP]], label [[A_GUARD:%.*]], label [[OUT:%.*]]
497 ; CHECK-NEXT: [[SEL_CMP:%.*]] = icmp ne i32 [[A]], 5
498 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[A]], -1
499 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[SEL_CMP]], i32 [[A]], i32 5
500 ; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[SEL]], 4
501 ; CHECK-NEXT: br label [[NEXT:%.*]]
503 ; CHECK-NEXT: ret i1 false
505 ; CHECK-NEXT: ret i1 false
508 %cmp = icmp sge i32 %a, 5
509 br i1 %cmp, label %a_guard, label %out
512 %sel_cmp = icmp ne i32 %a, 5
513 %add = add i32 %a, -1
514 %sel = select i1 %sel_cmp, i32 %a, i32 5
515 %res = icmp eq i32 %sel, 4
523 define i1 @clamp_high1(i32 %a) {
524 ; CHECK-LABEL: @clamp_high1(
526 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[A:%.*]], 5
527 ; CHECK-NEXT: br i1 [[CMP]], label [[A_GUARD:%.*]], label [[OUT:%.*]]
529 ; CHECK-NEXT: [[SEL_CMP:%.*]] = icmp eq i32 [[A]], 5
530 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[A]], 1
531 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[SEL_CMP]], i32 5, i32 [[A]]
532 ; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[SEL]], 6
533 ; CHECK-NEXT: br label [[NEXT:%.*]]
535 ; CHECK-NEXT: ret i1 false
537 ; CHECK-NEXT: ret i1 false
540 %cmp = icmp sle i32 %a, 5
541 br i1 %cmp, label %a_guard, label %out
544 %sel_cmp = icmp eq i32 %a, 5
546 %sel = select i1 %sel_cmp, i32 5, i32 %a
547 %res = icmp eq i32 %sel, 6
555 define i1 @clamp_high2(i32 %a) {
556 ; CHECK-LABEL: @clamp_high2(
558 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[A:%.*]], 5
559 ; CHECK-NEXT: br i1 [[CMP]], label [[A_GUARD:%.*]], label [[OUT:%.*]]
561 ; CHECK-NEXT: [[SEL_CMP:%.*]] = icmp ne i32 [[A]], 5
562 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[A]], 1
563 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[SEL_CMP]], i32 [[A]], i32 5
564 ; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[SEL]], 6
565 ; CHECK-NEXT: br label [[NEXT:%.*]]
567 ; CHECK-NEXT: ret i1 false
569 ; CHECK-NEXT: ret i1 false
572 %cmp = icmp sle i32 %a, 5
573 br i1 %cmp, label %a_guard, label %out
576 %sel_cmp = icmp ne i32 %a, 5
578 %sel = select i1 %sel_cmp, i32 %a, i32 5
579 %res = icmp eq i32 %sel, 6
587 ; Just showing arbitrary constants work, not really a clamp
588 define i1 @clamp_high3(i32 %a) {
589 ; CHECK-LABEL: @clamp_high3(
591 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[A:%.*]], 5
592 ; CHECK-NEXT: br i1 [[CMP]], label [[A_GUARD:%.*]], label [[OUT:%.*]]
594 ; CHECK-NEXT: [[SEL_CMP:%.*]] = icmp ne i32 [[A]], 5
595 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[A]], 100
596 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[SEL_CMP]], i32 [[A]], i32 5
597 ; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[SEL]], 105
598 ; CHECK-NEXT: br label [[NEXT:%.*]]
600 ; CHECK-NEXT: ret i1 false
602 ; CHECK-NEXT: ret i1 false
605 %cmp = icmp sle i32 %a, 5
606 br i1 %cmp, label %a_guard, label %out
609 %sel_cmp = icmp ne i32 %a, 5
610 %add = add i32 %a, 100
611 %sel = select i1 %sel_cmp, i32 %a, i32 5
612 %res = icmp eq i32 %sel, 105
620 define void @abs1(i32 %a, i1* %p) {
621 ; CHECK-LABEL: @abs1(
623 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[A:%.*]], 10
624 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[A]], -20
625 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[CMP1]], [[CMP2]]
626 ; CHECK-NEXT: br i1 [[AND]], label [[GUARD:%.*]], label [[EXIT:%.*]]
628 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[A]]
629 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[A]], 0
630 ; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[A]]
631 ; CHECK-NEXT: br label [[SPLIT:%.*]]
633 ; CHECK-NEXT: store i1 true, i1* [[P:%.*]]
634 ; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[ABS]], 19
635 ; CHECK-NEXT: store i1 [[C2]], i1* [[P]]
636 ; CHECK-NEXT: store i1 true, i1* [[P]]
637 ; CHECK-NEXT: [[C4:%.*]] = icmp sge i32 [[ABS]], 1
638 ; CHECK-NEXT: store i1 [[C4]], i1* [[P]]
639 ; CHECK-NEXT: br label [[EXIT]]
641 ; CHECK-NEXT: ret void
644 %cmp1 = icmp slt i32 %a, 10
645 %cmp2 = icmp sgt i32 %a, -20
646 %and = and i1 %cmp1, %cmp2
647 br i1 %and, label %guard, label %exit
651 %cmp = icmp slt i32 %a, 0
652 %abs = select i1 %cmp, i32 %sub, i32 %a
656 %c1 = icmp slt i32 %abs, 20
658 %c2 = icmp slt i32 %abs, 19
660 %c3 = icmp sge i32 %abs, 0
662 %c4 = icmp sge i32 %abs, 1
670 define void @abs2(i32 %a, i1* %p) {
671 ; CHECK-LABEL: @abs2(
673 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[A:%.*]], 10
674 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[A]], -20
675 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[CMP1]], [[CMP2]]
676 ; CHECK-NEXT: br i1 [[AND]], label [[GUARD:%.*]], label [[EXIT:%.*]]
678 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[A]]
679 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[A]], 0
680 ; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[A]], i32 [[SUB]]
681 ; CHECK-NEXT: br label [[SPLIT:%.*]]
683 ; CHECK-NEXT: store i1 true, i1* [[P:%.*]]
684 ; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[ABS]], 19
685 ; CHECK-NEXT: store i1 [[C2]], i1* [[P]]
686 ; CHECK-NEXT: store i1 true, i1* [[P]]
687 ; CHECK-NEXT: [[C4:%.*]] = icmp sge i32 [[ABS]], 1
688 ; CHECK-NEXT: store i1 [[C4]], i1* [[P]]
689 ; CHECK-NEXT: br label [[EXIT]]
691 ; CHECK-NEXT: ret void
694 %cmp1 = icmp slt i32 %a, 10
695 %cmp2 = icmp sgt i32 %a, -20
696 %and = and i1 %cmp1, %cmp2
697 br i1 %and, label %guard, label %exit
701 %cmp = icmp sge i32 %a, 0
702 %abs = select i1 %cmp, i32 %a, i32 %sub
706 %c1 = icmp slt i32 %abs, 20
708 %c2 = icmp slt i32 %abs, 19
710 %c3 = icmp sge i32 %abs, 0
712 %c4 = icmp sge i32 %abs, 1
720 define void @nabs1(i32 %a, i1* %p) {
721 ; CHECK-LABEL: @nabs1(
723 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[A:%.*]], 10
724 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[A]], -20
725 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[CMP1]], [[CMP2]]
726 ; CHECK-NEXT: br i1 [[AND]], label [[GUARD:%.*]], label [[EXIT:%.*]]
728 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[A]]
729 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A]], 0
730 ; CHECK-NEXT: [[NABS:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[A]]
731 ; CHECK-NEXT: br label [[SPLIT:%.*]]
733 ; CHECK-NEXT: store i1 true, i1* [[P:%.*]]
734 ; CHECK-NEXT: [[C2:%.*]] = icmp sgt i32 [[NABS]], -19
735 ; CHECK-NEXT: store i1 [[C2]], i1* [[P]]
736 ; CHECK-NEXT: store i1 true, i1* [[P]]
737 ; CHECK-NEXT: [[C4:%.*]] = icmp sle i32 [[NABS]], -1
738 ; CHECK-NEXT: store i1 [[C4]], i1* [[P]]
739 ; CHECK-NEXT: br label [[EXIT]]
741 ; CHECK-NEXT: ret void
744 %cmp1 = icmp slt i32 %a, 10
745 %cmp2 = icmp sgt i32 %a, -20
746 %and = and i1 %cmp1, %cmp2
747 br i1 %and, label %guard, label %exit
751 %cmp = icmp sgt i32 %a, 0
752 %nabs = select i1 %cmp, i32 %sub, i32 %a
756 %c1 = icmp sgt i32 %nabs, -20
758 %c2 = icmp sgt i32 %nabs, -19
760 %c3 = icmp sle i32 %nabs, 0
762 %c4 = icmp sle i32 %nabs, -1
770 define void @nabs2(i32 %a, i1* %p) {
771 ; CHECK-LABEL: @nabs2(
773 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[A:%.*]], 10
774 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[A]], -20
775 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[CMP1]], [[CMP2]]
776 ; CHECK-NEXT: br i1 [[AND]], label [[GUARD:%.*]], label [[EXIT:%.*]]
778 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[A]]
779 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[A]], 0
780 ; CHECK-NEXT: [[NABS:%.*]] = select i1 [[CMP]], i32 [[A]], i32 [[SUB]]
781 ; CHECK-NEXT: br label [[SPLIT:%.*]]
783 ; CHECK-NEXT: store i1 true, i1* [[P:%.*]]
784 ; CHECK-NEXT: [[C2:%.*]] = icmp sgt i32 [[NABS]], -19
785 ; CHECK-NEXT: store i1 [[C2]], i1* [[P]]
786 ; CHECK-NEXT: store i1 true, i1* [[P]]
787 ; CHECK-NEXT: [[C4:%.*]] = icmp sle i32 [[NABS]], -1
788 ; CHECK-NEXT: store i1 [[C4]], i1* [[P]]
789 ; CHECK-NEXT: br label [[EXIT]]
791 ; CHECK-NEXT: ret void
794 %cmp1 = icmp slt i32 %a, 10
795 %cmp2 = icmp sgt i32 %a, -20
796 %and = and i1 %cmp1, %cmp2
797 br i1 %and, label %guard, label %exit
801 %cmp = icmp slt i32 %a, 0
802 %nabs = select i1 %cmp, i32 %a, i32 %sub
806 %c1 = icmp sgt i32 %nabs, -20
808 %c2 = icmp sgt i32 %nabs, -19
810 %c3 = icmp sle i32 %nabs, 0
812 %c4 = icmp sle i32 %nabs, -1
820 define i1 @zext_unknown(i8 %a) {
821 ; CHECK-LABEL: @zext_unknown(
823 ; CHECK-NEXT: [[A32:%.*]] = zext i8 [[A:%.*]] to i32
824 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[A32]], 256
825 ; CHECK-NEXT: br label [[EXIT:%.*]]
827 ; CHECK-NEXT: ret i1 true
830 %a32 = zext i8 %a to i32
831 %cmp = icmp sle i32 %a32, 256
837 define i1 @trunc_unknown(i32 %a) {
838 ; CHECK-LABEL: @trunc_unknown(
840 ; CHECK-NEXT: [[A8:%.*]] = trunc i32 [[A:%.*]] to i8
841 ; CHECK-NEXT: [[A32:%.*]] = sext i8 [[A8]] to i32
842 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[A32]], 128
843 ; CHECK-NEXT: br label [[EXIT:%.*]]
845 ; CHECK-NEXT: ret i1 true
848 %a8 = trunc i32 %a to i8
849 %a32 = sext i8 %a8 to i32
850 %cmp = icmp sle i32 %a32, 128
856 ; TODO: missed optimization
857 ; Make sure we exercise non-integer inputs to unary operators (i.e. crash check).
858 define i1 @bitcast_unknown(float %a) {
859 ; CHECK-LABEL: @bitcast_unknown(
861 ; CHECK-NEXT: [[A32:%.*]] = bitcast float [[A:%.*]] to i32
862 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[A32]], 128
863 ; CHECK-NEXT: br label [[EXIT:%.*]]
865 ; CHECK-NEXT: ret i1 [[CMP]]
868 %a32 = bitcast float %a to i32
869 %cmp = icmp sle i32 %a32, 128
875 define i1 @bitcast_unknown2(i8* %p) {
876 ; CHECK-LABEL: @bitcast_unknown2(
878 ; CHECK-NEXT: [[P64:%.*]] = ptrtoint i8* [[P:%.*]] to i64
879 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i64 [[P64]], 128
880 ; CHECK-NEXT: br label [[EXIT:%.*]]
882 ; CHECK-NEXT: ret i1 [[CMP]]
885 %p64 = ptrtoint i8* %p to i64
886 %cmp = icmp sle i64 %p64, 128
893 define i1 @and_unknown(i32 %a) {
894 ; CHECK-LABEL: @and_unknown(
896 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[A:%.*]], 128
897 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[AND]], 128
898 ; CHECK-NEXT: br label [[EXIT:%.*]]
900 ; CHECK-NEXT: ret i1 true
903 %and = and i32 %a, 128
904 %cmp = icmp sle i32 %and, 128
910 define i1 @lshr_unknown(i32 %a) {
911 ; CHECK-LABEL: @lshr_unknown(
913 ; CHECK-NEXT: [[AND:%.*]] = lshr i32 [[A:%.*]], 30
914 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[AND]], 128
915 ; CHECK-NEXT: br label [[EXIT:%.*]]
917 ; CHECK-NEXT: ret i1 true
920 %and = lshr i32 %a, 30
921 %cmp = icmp sle i32 %and, 128
927 define i1 @urem_unknown(i32 %a) {
928 ; CHECK-LABEL: @urem_unknown(
930 ; CHECK-NEXT: [[UREM:%.*]] = urem i32 [[A:%.*]], 30
931 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[UREM]], 30
932 ; CHECK-NEXT: br label [[EXIT:%.*]]
934 ; CHECK-NEXT: ret i1 true
937 %urem = urem i32 %a, 30
938 %cmp = icmp ult i32 %urem, 30
944 define i1 @srem_unknown(i32 %a) {
945 ; CHECK-LABEL: @srem_unknown(
947 ; CHECK-NEXT: [[SREM:%.*]] = srem i32 [[A:%.*]], 30
948 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[SREM]], 30
949 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[SREM]], -30
950 ; CHECK-NEXT: br i1 undef, label [[EXIT1:%.*]], label [[EXIT2:%.*]]
952 ; CHECK-NEXT: ret i1 true
954 ; CHECK-NEXT: ret i1 true
957 %srem = srem i32 %a, 30
958 %cmp1 = icmp slt i32 %srem, 30
959 %cmp2 = icmp sgt i32 %srem, -30
960 br i1 undef, label %exit1, label %exit2
967 define i1 @sdiv_unknown(i32 %a) {
968 ; CHECK-LABEL: @sdiv_unknown(
970 ; CHECK-NEXT: [[SREM:%.*]] = sdiv i32 [[A:%.*]], 123
971 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[SREM]], 17459217
972 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[SREM]], -17459217
973 ; CHECK-NEXT: br i1 undef, label [[EXIT1:%.*]], label [[EXIT2:%.*]]
975 ; CHECK-NEXT: ret i1 true
977 ; CHECK-NEXT: ret i1 true
980 %srem = sdiv i32 %a, 123
981 %cmp1 = icmp slt i32 %srem, 17459217
982 %cmp2 = icmp sgt i32 %srem, -17459217
983 br i1 undef, label %exit1, label %exit2
990 define i1 @uadd_sat_unknown(i32 %a) {
991 ; CHECK-LABEL: @uadd_sat_unknown(
993 ; CHECK-NEXT: [[VAL:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[A:%.*]], i32 100)
994 ; CHECK-NEXT: [[CMP1:%.*]] = icmp uge i32 [[VAL]], 100
995 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ugt i32 [[VAL]], 100
996 ; CHECK-NEXT: br i1 undef, label [[EXIT1:%.*]], label [[EXIT2:%.*]]
998 ; CHECK-NEXT: ret i1 true
1000 ; CHECK-NEXT: ret i1 [[CMP2]]
1003 %val = call i32 @llvm.uadd.sat.i32(i32 %a, i32 100)
1004 %cmp1 = icmp uge i32 %val, 100
1005 %cmp2 = icmp ugt i32 %val, 100
1006 br i1 undef, label %exit1, label %exit2
1013 define i1 @usub_sat_unknown(i32 %a) {
1014 ; CHECK-LABEL: @usub_sat_unknown(
1015 ; CHECK-NEXT: entry:
1016 ; CHECK-NEXT: [[VAL:%.*]] = call i32 @llvm.usub.sat.i32(i32 [[A:%.*]], i32 100)
1017 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ule i32 [[VAL]], -101
1018 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i32 [[VAL]], -101
1019 ; CHECK-NEXT: br i1 undef, label [[EXIT1:%.*]], label [[EXIT2:%.*]]
1021 ; CHECK-NEXT: ret i1 true
1023 ; CHECK-NEXT: ret i1 [[CMP2]]
1026 %val = call i32 @llvm.usub.sat.i32(i32 %a, i32 100)
1027 %cmp1 = icmp ule i32 %val, 4294967195
1028 %cmp2 = icmp ult i32 %val, 4294967195
1029 br i1 undef, label %exit1, label %exit2
1036 define i1 @sadd_sat_unknown(i32 %a) {
1037 ; CHECK-LABEL: @sadd_sat_unknown(
1038 ; CHECK-NEXT: entry:
1039 ; CHECK-NEXT: [[VAL:%.*]] = call i32 @llvm.sadd.sat.i32(i32 [[A:%.*]], i32 100)
1040 ; CHECK-NEXT: [[CMP1:%.*]] = icmp sge i32 [[VAL]], -2147483548
1041 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[VAL]], -2147483548
1042 ; CHECK-NEXT: br i1 undef, label [[EXIT1:%.*]], label [[EXIT2:%.*]]
1044 ; CHECK-NEXT: ret i1 true
1046 ; CHECK-NEXT: ret i1 [[CMP2]]
1049 %val = call i32 @llvm.sadd.sat.i32(i32 %a, i32 100)
1050 %cmp1 = icmp sge i32 %val, -2147483548
1051 %cmp2 = icmp sgt i32 %val, -2147483548
1052 br i1 undef, label %exit1, label %exit2
1059 define i1 @ssub_sat_unknown(i32 %a) {
1060 ; CHECK-LABEL: @ssub_sat_unknown(
1061 ; CHECK-NEXT: entry:
1062 ; CHECK-NEXT: [[VAL:%.*]] = call i32 @llvm.ssub.sat.i32(i32 [[A:%.*]], i32 100)
1063 ; CHECK-NEXT: [[CMP1:%.*]] = icmp sle i32 [[VAL]], 2147483547
1064 ; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[VAL]], 2147483547
1065 ; CHECK-NEXT: br i1 undef, label [[EXIT1:%.*]], label [[EXIT2:%.*]]
1067 ; CHECK-NEXT: ret i1 true
1069 ; CHECK-NEXT: ret i1 [[CMP2]]
1072 %val = call i32 @llvm.ssub.sat.i32(i32 %a, i32 100)
1073 %cmp1 = icmp sle i32 %val, 2147483547
1074 %cmp2 = icmp slt i32 %val, 2147483547
1075 br i1 undef, label %exit1, label %exit2
1082 declare i32 @llvm.uadd.sat.i32(i32, i32)
1083 declare i32 @llvm.usub.sat.i32(i32, i32)
1084 declare i32 @llvm.sadd.sat.i32(i32, i32)
1085 declare i32 @llvm.ssub.sat.i32(i32, i32)