Florian Hahn | d0208b4 | 2017-10-30 10:07:42 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -ipsccp -S | FileCheck %s |
| 2 | |
| 3 | ; Constant range for %a is [1, 48) and for %b is [301, 1000) |
| 4 | ; CHECK-LABEL: f1 |
| 5 | ; CHECK-NOT: icmp |
| 6 | ; CHECK: %a.1 = select i1 false, i32 1, i32 2 |
| 7 | ; CHECK: %b.1 = select i1 true, i32 1, i32 2 |
| 8 | ; CHECK: %a.2 = select i1 false, i32 1, i32 2 |
| 9 | ; CHECK: %b.2 = select i1 true, i32 1, i32 2 |
| 10 | define internal i32 @f1(i32 %a, i32 %b) { |
| 11 | entry: |
| 12 | %cmp.a = icmp sgt i32 %a, 300 |
| 13 | %cmp.b = icmp sgt i32 %b, 300 |
| 14 | %cmp.a2 = icmp ugt i32 %a, 300 |
| 15 | %cmp.b2 = icmp ugt i32 %b, 300 |
| 16 | |
| 17 | %a.1 = select i1 %cmp.a, i32 1, i32 2 |
| 18 | %b.1 = select i1 %cmp.b, i32 1, i32 2 |
| 19 | %a.2 = select i1 %cmp.a2, i32 1, i32 2 |
| 20 | %b.2 = select i1 %cmp.b2, i32 1, i32 2 |
| 21 | %res1 = add i32 %a.1, %b.1 |
| 22 | %res2 = add i32 %a.2, %b.2 |
| 23 | %res3 = add i32 %res1, %res2 |
| 24 | ret i32 %res3 |
| 25 | } |
| 26 | |
| 27 | ; Constant range for %x is [47, 302) |
| 28 | ; CHECK-LABEL: f2 |
| 29 | ; CHECK: %cmp = icmp sgt i32 %x, 300 |
| 30 | ; CHECK: %res1 = select i1 %cmp, i32 1, i32 2 |
| 31 | ; CHECK-NEXT: %res2 = select i1 true, i32 3, i32 4 |
| 32 | ; CHECK-NEXT: %res3 = select i1 true, i32 5, i32 6 |
| 33 | ; CHECK-NEXT: %res4 = select i1 %cmp4, i32 3, i32 4 |
| 34 | ; CHECK-NEXT: %res5 = select i1 true, i32 5, i32 6 |
| 35 | define internal i32 @f2(i32 %x) { |
| 36 | entry: |
| 37 | %cmp = icmp sgt i32 %x, 300 |
| 38 | %cmp2 = icmp ne i32 %x, 10 |
| 39 | %cmp3 = icmp sge i32 %x, 47 |
| 40 | %cmp4 = icmp ugt i32 %x, 300 |
| 41 | %cmp5 = icmp uge i32 %x, 47 |
| 42 | %res1 = select i1 %cmp, i32 1, i32 2 |
| 43 | %res2 = select i1 %cmp2, i32 3, i32 4 |
| 44 | %res3 = select i1 %cmp3, i32 5, i32 6 |
| 45 | %res4 = select i1 %cmp4, i32 3, i32 4 |
| 46 | %res5 = select i1 %cmp5, i32 5, i32 6 |
| 47 | |
| 48 | %res6 = add i32 %res1, %res2 |
| 49 | %res7 = add i32 %res3, %res4 |
| 50 | %res = add i32 %res6, %res5 |
| 51 | ret i32 %res |
| 52 | } |
| 53 | |
| 54 | define i32 @caller1() { |
| 55 | entry: |
| 56 | %call1 = tail call i32 @f1(i32 1, i32 301) |
| 57 | %call2 = tail call i32 @f1(i32 47, i32 999) |
| 58 | %call3 = tail call i32 @f2(i32 47) |
| 59 | %call4 = tail call i32 @f2(i32 301) |
| 60 | %res = add nsw i32 %call1, %call2 |
| 61 | %res.1 = add nsw i32 %res, %call3 |
| 62 | %res.2 = add nsw i32 %res.1, %call4 |
| 63 | ret i32 %res.2 |
| 64 | } |
| 65 | |
| 66 | ; x is overdefined, because constant ranges are only used for parameter |
| 67 | ; values. |
| 68 | ; CHECK-LABEL: f3 |
| 69 | ; CHECK: %cmp = icmp sgt i32 %x, 300 |
| 70 | ; CHECK: %res = select i1 %cmp, i32 1, i32 2 |
| 71 | ; CHECK: ret i32 %res |
| 72 | define internal i32 @f3(i32 %x) { |
| 73 | entry: |
| 74 | %cmp = icmp sgt i32 %x, 300 |
| 75 | %res = select i1 %cmp, i32 1, i32 2 |
| 76 | ret i32 %res |
| 77 | } |
| 78 | |
| 79 | ; The phi node could be converted in a ConstantRange. |
| 80 | define i32 @caller2(i1 %cmp) { |
| 81 | entry: |
| 82 | br i1 %cmp, label %if.true, label %end |
| 83 | |
| 84 | if.true: |
| 85 | br label %end |
| 86 | |
| 87 | end: |
| 88 | %res = phi i32 [ 0, %entry], [ 1, %if.true ] |
| 89 | %call1 = tail call i32 @f3(i32 %res) |
| 90 | ret i32 %call1 |
| 91 | } |
| 92 | |
| 93 | ; CHECK-LABEL: f4 |
| 94 | ; CHECK: %cmp = icmp sgt i32 %x, 300 |
| 95 | ; CHECK: %res = select i1 %cmp, i32 1, i32 2 |
| 96 | ; CHECK: ret i32 %res |
| 97 | define internal i32 @f4(i32 %x) { |
| 98 | entry: |
| 99 | %cmp = icmp sgt i32 %x, 300 |
| 100 | %res = select i1 %cmp, i32 1, i32 2 |
| 101 | ret i32 %res |
| 102 | } |
| 103 | |
| 104 | ; ICmp could introduce bounds on ConstantRanges. |
| 105 | define i32 @caller3(i32 %x) { |
| 106 | entry: |
| 107 | %cmp = icmp sgt i32 %x, 300 |
| 108 | br i1 %cmp, label %if.true, label %end |
| 109 | |
| 110 | if.true: |
| 111 | %x.1 = tail call i32 @f4(i32 %x) |
| 112 | br label %end |
| 113 | |
| 114 | end: |
| 115 | %res = phi i32 [ 0, %entry], [ %x.1, %if.true ] |
| 116 | ret i32 %res |
| 117 | } |
| 118 | |
| 119 | ; Check to make sure we do not attempt to access lattice values in unreachable |
| 120 | ; blocks. |
| 121 | define i32 @test_unreachable() { |
| 122 | entry: |
| 123 | call i1 @test_unreachable_callee(i32 1) |
| 124 | call i1 @test_unreachable_callee(i32 2) |
| 125 | ret i32 1 |
| 126 | } |
| 127 | |
| 128 | define internal i1 @test_unreachable_callee(i32 %a) { |
| 129 | entry: |
| 130 | ret i1 true |
| 131 | |
| 132 | unreachablebb: |
| 133 | %cmp = icmp eq i32 undef, %a |
| 134 | unreachable |
| 135 | } |
| 136 | |
| 137 | ; Check that we do not attempt to get range info for non-integer types and |
| 138 | ; crash. |
| 139 | define double @test_struct({ double, double } %test) { |
| 140 | %v = extractvalue { double, double } %test, 0 |
| 141 | %r = fmul double %v, %v |
| 142 | ret double %r |
| 143 | } |