1 ; RUN: opt < %s -analyze -enable-new-pm=0 -scalar-evolution -scalar-evolution-max-iterations=0 | FileCheck %s
2 ; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" -scalar-evolution-max-iterations=0 2>&1 | FileCheck %s
6 @A = weak global [1000 x i32] zeroinitializer, align 32
8 define void @test1(i32 %N) {
10 %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
14 %tmp = getelementptr [1000 x i32], [1000 x i32]* @A, i32 0, i32 %i.0 ; <i32*> [#uses=1]
15 store i32 123, i32* %tmp
16 %tmp2 = add i32 %i.0, 1 ; <i32> [#uses=1]
19 bb3: ; preds = %bb, %entry
20 %i.0 = phi i32 [ 2, %entry ], [ %tmp2, %bb ] ; <i32> [#uses=3]
21 %SQ = mul i32 %i.0, %i.0
22 %tmp4 = mul i32 %i.0, 2
23 %tmp5 = sub i32 %SQ, %tmp4
24 %tmp3 = icmp sle i32 %tmp5, 9999 ; <i1> [#uses=1]
25 br i1 %tmp3, label %bb, label %bb5
30 return: ; preds = %bb5
33 ; CHECK: Determining loop execution counts for: @test1
34 ; CHECK-NEXT: backedge-taken count is 100
38 ; These next two used to crash.
40 define void @test2(i1 %cmp, i64 %n) {
45 %a0.08 = phi i64 [ 0, %entry ], [ %inc512, %for.body1 ]
46 %inc512 = add i64 %a0.08, 1
47 br i1 %cmp, label %preheader, label %for.body1
53 %indvar = phi i64 [ 0, %preheader ], [ %indvar.next, %for.body2 ]
54 %tmp111 = add i64 %n, %indvar
55 %tmp114 = mul i64 %a0.08, %indvar
56 %mul542 = mul i64 %tmp114, %tmp111
57 %indvar.next = add i64 %indvar, 1
58 br i1 undef, label %end, label %for.body2
63 ; CHECK: Determining loop execution counts for: @test2
67 br i1 undef, label %for.cond539.preheader, label %for.inc479
70 %a2.07 = phi i32 [ %add495, %for.inc479 ], [ 0, %if.then466 ]
71 %j.36 = phi i32 [ %inc497, %for.inc479 ], [ undef, %if.then466 ]
72 %mul484 = mul nsw i32 %j.36, %j.36
73 %mul491 = mul i32 %j.36, %j.36
74 %mul493 = mul i32 %mul491, %mul484
75 %add495 = add nsw i32 %mul493, %a2.07
76 %inc497 = add nsw i32 %j.36, 1
77 br i1 undef, label %for.cond539.preheader, label %for.inc479
79 for.cond539.preheader:
82 ; CHECK: Determining loop execution counts for: @test3
85 ; We used to crash on this too.
87 define void @test4() {
91 for.body: ; preds = %for.body, %entry
92 %v2.02 = phi i64 [ 2, %entry ], [ %phitmp, %for.body ]
93 %v1.01 = phi i64 [ -2, %entry ], [ %sub1, %for.body ]
94 %sub1 = sub i64 %v1.01, %v2.02
95 %phitmp = add i64 %v2.02, 2
96 %tobool = icmp eq i64 %sub1, %phitmp
97 br i1 %tobool, label %for.end, label %for.body
99 for.end: ; preds = %for.body
103 ; CHECK: Determining loop execution counts for: @test4