1; RUN: opt -analyze -scalar-evolution < %s | FileCheck %s 2 3define void @test0(i32 %init) { 4; CHECK-LABEL: Classifying expressions for: @test0 5; CHECK: Loop %loop: max backedge-taken count is 32 6 entry: 7 br label %loop 8 9 loop: 10 %iv = phi i32 [ %init, %entry ], [ %iv.shift, %loop ] 11 %iv.shift = lshr i32 %iv, 1 12 %exit.cond = icmp eq i32 %iv, 0 13 br i1 %exit.cond, label %leave, label %loop 14 15 leave: 16 ret void 17} 18 19define void @test1(i32 %init) { 20; CHECK-LABEL: Classifying expressions for: @test1 21; CHECK: Loop %loop: max backedge-taken count is 32 22 entry: 23 br label %loop 24 25 loop: 26 %iv = phi i32 [ %init, %entry ], [ %iv.shift, %loop ] 27 %iv.shift = shl i32 %iv, 1 28 %exit.cond = icmp eq i32 %iv, 0 29 br i1 %exit.cond, label %leave, label %loop 30 31 leave: 32 ret void 33} 34 35define void @test2(i32 %init) { 36; CHECK-LABEL: Determining loop execution counts for: @test2 37; CHECK: Loop %loop: Unpredictable max backedge-taken count. 38 39; Unpredictable because %iv could "stabilize" to either -1 or 0, 40; depending on %init. 41 entry: 42 br label %loop 43 44 loop: 45 %iv = phi i32 [ %init, %entry ], [ %iv.shift, %loop ] 46 %iv.shift = ashr i32 %iv, 1 47 %exit.cond = icmp eq i32 %iv, 0 48 br i1 %exit.cond, label %leave, label %loop 49 50 leave: 51 ret void 52} 53 54define void @test3(i32* %init.ptr) { 55; CHECK-LABEL: Determining loop execution counts for: @test3 56; CHECK: Loop %loop: max backedge-taken count is 32 57 entry: 58 %init = load i32, i32* %init.ptr, !range !0 59 br label %loop 60 61 loop: 62 %iv = phi i32 [ %init, %entry ], [ %iv.shift, %loop ] 63 %iv.shift = ashr i32 %iv, 1 64 %exit.cond = icmp eq i32 %iv, 0 65 br i1 %exit.cond, label %leave, label %loop 66 67 leave: 68 ret void 69} 70 71define void @test4(i32* %init.ptr) { 72; CHECK-LABEL: Classifying expressions for: @test4 73; CHECK-LABEL: Loop %loop: max backedge-taken count is 32 74 entry: 75 %init = load i32, i32* %init.ptr, !range !1 76 br label %loop 77 78 loop: 79 %iv = phi i32 [ %init, %entry ], [ %iv.shift, %loop ] 80 %iv.shift = ashr i32 %iv, 1 81 %exit.cond = icmp eq i32 %iv, -1 82 br i1 %exit.cond, label %leave, label %loop 83 84 leave: 85 ret void 86} 87 88define void @test5(i32* %init.ptr) { 89; CHECK-LABEL: Determining loop execution counts for: @test5 90; CHECK: Loop %loop: Unpredictable max backedge-taken count. 91 92; %iv will "stabilize" to -1, so this is an infinite loop 93 entry: 94 %init = load i32, i32* %init.ptr, !range !1 95 br label %loop 96 97 loop: 98 %iv = phi i32 [ %init, %entry ], [ %iv.shift, %loop ] 99 %iv.shift = ashr i32 %iv, 1 100 %exit.cond = icmp eq i32 %iv, 0 101 br i1 %exit.cond, label %leave, label %loop 102 103 leave: 104 ret void 105} 106 107define void @test6(i32 %init, i32 %shift.amt) { 108; CHECK-LABEL: Determining loop execution counts for: @test6 109; CHECK: Loop %loop: Unpredictable max backedge-taken count. 110 111; Potentially infinite loop, since %shift.amt could be 0 112 entry: 113 br label %loop 114 115 loop: 116 %iv = phi i32 [ %init, %entry ], [ %iv.shift, %loop ] 117 %iv.shift = lshr i32 %iv, %shift.amt 118 %exit.cond = icmp eq i32 %iv, 0 119 br i1 %exit.cond, label %leave, label %loop 120 121 leave: 122 ret void 123} 124 125define void @test7(i32 %init) { 126; CHECK-LABEL: Classifying expressions for: @test7 127; CHECK: Loop %loop: max backedge-taken count is 32 128 129 entry: 130 br label %loop 131 132 loop: 133 %iv = phi i32 [ %init, %entry ], [ %iv.shift, %loop ] 134 %iv.shift = lshr i32 %iv, 1 135 %exit.cond = icmp eq i32 %iv.shift, 0 136 br i1 %exit.cond, label %leave, label %loop 137 138 leave: 139 ret void 140} 141 142define void @test8(i32 %init) { 143; CHECK-LABEL: Classifying expressions for: @test8 144; CHECK: Loop %loop: Unpredictable max backedge-taken count. 145 146; In this test case, %iv.test stabilizes to 127, not -1, so the loop 147; is infinite. 148 149 entry: 150 br label %loop 151 152 loop: 153 %iv = phi i32 [ %init, %entry ], [ %iv.shift, %loop ] 154 %iv.shift = ashr i32 %iv, 1 155 %iv.test = lshr i32 %iv, 1 156 %exit.cond = icmp eq i32 %iv.test, -1 157 br i1 %exit.cond, label %leave, label %loop 158 159 leave: 160 ret void 161} 162 163!0 = !{i32 0, i32 50000} 164!1 = !{i32 -5000, i32 -1} 165