1 ; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s
3 ; ScalarEvolution should be able to compute trip count of the loop by proving
4 ; that this is not an infinite loop with side effects.
6 ; CHECK: Determining loop execution counts for: @foo1
7 ; CHECK: backedge-taken count is ((-1 + %n) /u %s)
9 ; We should have a conservative estimate for the max backedge taken count for
10 ; loops with unknown stride.
11 ; CHECK: max backedge-taken count is -1
13 target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
15 ; Function Attrs: norecurse nounwind
16 define void @foo1(i32* nocapture %A, i32 %n, i32 %s) #0 {
18 %cmp4 = icmp sgt i32 %n, 0
19 br i1 %cmp4, label %for.body, label %for.end
21 for.body: ; preds = %entry, %for.body
22 %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
23 %arrayidx = getelementptr inbounds i32, i32* %A, i32 %i.05
24 %0 = load i32, i32* %arrayidx, align 4
25 %inc = add nsw i32 %0, 1
26 store i32 %inc, i32* %arrayidx, align 4
27 %add = add nsw i32 %i.05, %s
28 %cmp = icmp slt i32 %add, %n
29 br i1 %cmp, label %for.body, label %for.end
31 for.end: ; preds = %for.body, %entry
36 ; Check that we are able to compute trip count of a loop without an entry guard.
37 ; CHECK: Determining loop execution counts for: @foo2
38 ; CHECK: backedge-taken count is ((-1 + (%n smax %s)) /u %s)
40 ; We should have a conservative estimate for the max backedge taken count for
41 ; loops with unknown stride.
42 ; CHECK: max backedge-taken count is -1
44 ; Function Attrs: norecurse nounwind
45 define void @foo2(i32* nocapture %A, i32 %n, i32 %s) #0 {
49 for.body: ; preds = %entry, %for.body
50 %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
51 %arrayidx = getelementptr inbounds i32, i32* %A, i32 %i.05
52 %0 = load i32, i32* %arrayidx, align 4
53 %inc = add nsw i32 %0, 1
54 store i32 %inc, i32* %arrayidx, align 4
55 %add = add nsw i32 %i.05, %s
56 %cmp = icmp slt i32 %add, %n
57 br i1 %cmp, label %for.body, label %for.end
59 for.end: ; preds = %for.body, %entry