1 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2 ; RUN: opt < %s -analyze -scalar-evolution -scalar-evolution-classify-expressions=0 | FileCheck %s
4 ; Trip counts with trivial exit conditions.
6 define void @a(i64 %n) nounwind {
8 ; CHECK-NEXT: Determining loop execution counts for: @a
9 ; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count.
10 ; CHECK-NEXT: Loop %loop: Unpredictable max backedge-taken count.
11 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
14 %t0 = icmp sgt i64 %n, 0
15 br i1 %t0, label %loop, label %return
18 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
19 %i.next = add nsw i64 %i, 1
20 %exitcond = icmp eq i64 %i.next, %n
21 br i1 false, label %return, label %loop
26 define void @b(i64 %n) nounwind {
28 ; CHECK-NEXT: Determining loop execution counts for: @b
29 ; CHECK-NEXT: Loop %loop: backedge-taken count is false
30 ; CHECK-NEXT: Loop %loop: max backedge-taken count is false
31 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is false
32 ; CHECK-NEXT: Predicates:
33 ; CHECK: Loop %loop: Trip multiple is 1
36 %t0 = icmp sgt i64 %n, 0
37 br i1 %t0, label %loop, label %return
40 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
41 %i.next = add nsw i64 %i, 1
42 %exitcond = icmp eq i64 %i.next, %n
43 br i1 true, label %return, label %loop
48 define void @c(i64 %n) nounwind {
50 ; CHECK-NEXT: Determining loop execution counts for: @c
51 ; CHECK-NEXT: Loop %loop: backedge-taken count is false
52 ; CHECK-NEXT: Loop %loop: max backedge-taken count is false
53 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is false
54 ; CHECK-NEXT: Predicates:
55 ; CHECK: Loop %loop: Trip multiple is 1
58 %t0 = icmp sgt i64 %n, 0
59 br i1 %t0, label %loop, label %return
62 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
63 %i.next = add nsw i64 %i, 1
64 %exitcond = icmp eq i64 %i.next, %n
65 br i1 false, label %loop, label %return
70 define void @d(i64 %n) nounwind {
72 ; CHECK-NEXT: Determining loop execution counts for: @d
73 ; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count.
74 ; CHECK-NEXT: Loop %loop: Unpredictable max backedge-taken count.
75 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
78 %t0 = icmp sgt i64 %n, 0
79 br i1 %t0, label %loop, label %return
82 %i = phi i64 [ %i.next, %loop ], [ 0, %entry ]
83 %i.next = add nsw i64 %i, 1
84 %exitcond = icmp eq i64 %i.next, %n
85 br i1 true, label %loop, label %return
91 ; Trip counts for non-polynomial iterations. It's theoretically possible
92 ; to compute a maximum count for these, but short of that, ScalarEvolution
93 ; should return unknown.
96 declare i1 @g() nounwind
98 define void @nonpolynomial() {
99 ; CHECK-LABEL: 'nonpolynomial'
100 ; CHECK-NEXT: Determining loop execution counts for: @nonpolynomial
101 ; CHECK-NEXT: Loop %loophead: Unpredictable backedge-taken count.
102 ; CHECK-NEXT: Loop %loophead: Unpredictable max backedge-taken count.
103 ; CHECK-NEXT: Loop %loophead: Unpredictable predicated backedge-taken count.
108 %x = phi i32 [0, %entry], [%x.1, %bb1], [%x.2, %bb2]
109 %y = icmp slt i32 %x, 100
110 br i1 %y, label %loopbody, label %retbb
113 br i1 %z, label %bb1, label %bb2
124 ; PHI nodes with all constant operands.
126 define void @constant_phi_operands() nounwind {
127 ; CHECK-LABEL: 'constant_phi_operands'
128 ; CHECK-NEXT: Determining loop execution counts for: @constant_phi_operands
129 ; CHECK-NEXT: Loop %loop: backedge-taken count is 1
130 ; CHECK-NEXT: Loop %loop: max backedge-taken count is 1
131 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is 1
132 ; CHECK-NEXT: Predicates:
133 ; CHECK: Loop %loop: Trip multiple is 2
139 %i = phi i64 [ 1, %loop ], [ 0, %entry ]
140 %exitcond = icmp eq i64 %i, 1
141 br i1 %exitcond, label %return, label %loop
147 ; PR16130: Loop exit depends on an 'or' expression.
148 ; One side of the expression test against a value that will be skipped.
149 ; We can't assume undefined behavior just because we have an NSW flag.
151 define void @exit_orcond_nsw(i32 *%a) nounwind {
152 ; CHECK-LABEL: 'exit_orcond_nsw'
153 ; CHECK-NEXT: Determining loop execution counts for: @exit_orcond_nsw
154 ; CHECK-NEXT: Loop %for.body.i: Unpredictable backedge-taken count.
155 ; CHECK-NEXT: Loop %for.body.i: max backedge-taken count is 1
156 ; CHECK-NEXT: Loop %for.body.i: Unpredictable predicated backedge-taken count.
161 for.body.i: ; preds = %for.body.i, %entry
162 %b.01.i = phi i32 [ 0, %entry ], [ %add.i, %for.body.i ]
163 %tobool.i = icmp ne i32 %b.01.i, 0
164 %add.i = add nsw i32 %b.01.i, 8
165 %cmp.i = icmp eq i32 %add.i, 13
166 %or.cond = or i1 %tobool.i, %cmp.i
167 br i1 %or.cond, label %exit, label %for.body.i
169 exit: ; preds = %for.body.i
170 %b.01.i.lcssa = phi i32 [ %b.01.i, %for.body.i ]
171 store i32 %b.01.i.lcssa, i32* %a, align 4