1 ; RUN: opt < %s -analyze -scalar-evolution -scalar-evolution-max-iterations=0 | FileCheck %s
5 @A = weak global [1000 x i32] zeroinitializer, align 32
7 define void @test1(i32 %N) {
9 %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
13 %tmp = getelementptr [1000 x i32], [1000 x i32]* @A, i32 0, i32 %i.0 ; <i32*> [#uses=1]
14 store i32 123, i32* %tmp
15 %tmp2 = add i32 %i.0, 1 ; <i32> [#uses=1]
18 bb3: ; preds = %bb, %entry
19 %i.0 = phi i32 [ 2, %entry ], [ %tmp2, %bb ] ; <i32> [#uses=3]
20 %SQ = mul i32 %i.0, %i.0
21 %tmp4 = mul i32 %i.0, 2
22 %tmp5 = sub i32 %SQ, %tmp4
23 %tmp3 = icmp sle i32 %tmp5, 9999 ; <i1> [#uses=1]
24 br i1 %tmp3, label %bb, label %bb5
29 return: ; preds = %bb5
32 ; CHECK: Determining loop execution counts for: @test1
33 ; CHECK-NEXT: backedge-taken count is 100
37 ; These next two used to crash.
39 define void @test2(i1 %cmp, i64 %n) {
44 %a0.08 = phi i64 [ 0, %entry ], [ %inc512, %for.body1 ]
45 %inc512 = add i64 %a0.08, 1
46 br i1 %cmp, label %preheader, label %for.body1
52 %indvar = phi i64 [ 0, %preheader ], [ %indvar.next, %for.body2 ]
53 %tmp111 = add i64 %n, %indvar
54 %tmp114 = mul i64 %a0.08, %indvar
55 %mul542 = mul i64 %tmp114, %tmp111
56 %indvar.next = add i64 %indvar, 1
57 br i1 undef, label %end, label %for.body2
62 ; CHECK: Determining loop execution counts for: @test2
66 br i1 undef, label %for.cond539.preheader, label %for.inc479
69 %a2.07 = phi i32 [ %add495, %for.inc479 ], [ 0, %if.then466 ]
70 %j.36 = phi i32 [ %inc497, %for.inc479 ], [ undef, %if.then466 ]
71 %mul484 = mul nsw i32 %j.36, %j.36
72 %mul491 = mul i32 %j.36, %j.36
73 %mul493 = mul i32 %mul491, %mul484
74 %add495 = add nsw i32 %mul493, %a2.07
75 %inc497 = add nsw i32 %j.36, 1
76 br i1 undef, label %for.cond539.preheader, label %for.inc479
78 for.cond539.preheader:
81 ; CHECK: Determining loop execution counts for: @test3
84 ; We used to crash on this too.
86 define void @test4() {
90 for.body: ; preds = %for.body, %entry
91 %v2.02 = phi i64 [ 2, %entry ], [ %phitmp, %for.body ]
92 %v1.01 = phi i64 [ -2, %entry ], [ %sub1, %for.body ]
93 %sub1 = sub i64 %v1.01, %v2.02
94 %phitmp = add i64 %v2.02, 2
95 %tobool = icmp eq i64 %sub1, %phitmp
96 br i1 %tobool, label %for.end, label %for.body
98 for.end: ; preds = %for.body
102 ; CHECK: Determining loop execution counts for: @test4