1 ; RUN: opt -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s
3 define void @test0(i32 %init) {
4 ; CHECK-LABEL: Classifying expressions for: @test0
5 ; CHECK: Loop %loop: constant max backedge-taken count is 32
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
19 define void @test1(i32 %init) {
20 ; CHECK-LABEL: Classifying expressions for: @test1
21 ; CHECK: Loop %loop: constant max backedge-taken count is 32
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
35 define void @test2(i32 %init) {
36 ; CHECK-LABEL: Determining loop execution counts for: @test2
37 ; CHECK: Loop %loop: Unpredictable constant max backedge-taken count.
39 ; Unpredictable because %iv could "stabilize" to either -1 or 0,
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
54 define void @test3(ptr %init.ptr) {
55 ; CHECK-LABEL: Determining loop execution counts for: @test3
56 ; CHECK: Loop %loop: constant max backedge-taken count is 32
58 %init = load i32, ptr %init.ptr, !range !0
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
71 define void @test4(ptr %init.ptr) {
72 ; CHECK-LABEL: Classifying expressions for: @test4
73 ; CHECK-LABEL: Loop %loop: constant max backedge-taken count is 32
75 %init = load i32, ptr %init.ptr, !range !1
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
88 define void @test5(ptr %init.ptr) {
89 ; CHECK-LABEL: Determining loop execution counts for: @test5
90 ; CHECK: Loop %loop: Unpredictable constant max backedge-taken count.
92 ; %iv will "stabilize" to -1, so this is an infinite loop
94 %init = load i32, ptr %init.ptr, !range !1
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
107 define void @test6(i32 %init, i32 %shift.amt) {
108 ; CHECK-LABEL: Determining loop execution counts for: @test6
109 ; CHECK: Loop %loop: Unpredictable constant max backedge-taken count.
111 ; Potentially infinite loop, since %shift.amt could be 0
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
125 define void @test7(i32 %init) {
126 ; CHECK-LABEL: Classifying expressions for: @test7
127 ; CHECK: Loop %loop: constant max backedge-taken count is 32
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
142 define void @test8(i32 %init) {
143 ; CHECK-LABEL: Classifying expressions for: @test8
144 ; CHECK: Loop %loop: Unpredictable constant max backedge-taken count.
146 ; In this test case, %iv.test stabilizes to 127, not -1, so the 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
163 define void @test9() {
164 ; CHECK-LABEL: Determining loop execution counts for: @test9
165 ; CHECK: Loop %loop: Unpredictable constant max backedge-taken count.
167 ; This is an infinite loop, make sure that it recognized as such.
176 %iv = phi i32 [ -20, %entry ], [ %iv.shift, %loop ]
177 %iv.shift = ashr i32 %iv, 1
178 %exit.cond = icmp sgt i32 %iv, -1
179 br i1 %exit.cond, label %leave, label %loop
182 !0 = !{i32 0, i32 50000}
183 !1 = !{i32 -5000, i32 -1}