1 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2 ; RUN: opt -S -disable-output "-passes=print<scalar-evolution>" -scalar-evolution-classify-expressions=0 < %s 2>&1 | FileCheck %s
4 define void @s32_max1(i32 %n, ptr %p) {
5 ; CHECK-LABEL: 's32_max1'
6 ; CHECK-NEXT: Determining loop execution counts for: @s32_max1
7 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((1 + %n) smax %n))
8 ; CHECK-NEXT: Loop %do.body: constant max backedge-taken count is 1, actual taken count either this or zero.
9 ; CHECK-NEXT: Loop %do.body: symbolic max backedge-taken count is ((-1 * %n) + ((1 + %n) smax %n)), actual taken count either this or zero.
10 ; CHECK-NEXT: Loop %do.body: Predicated backedge-taken count is ((-1 * %n) + ((1 + %n) smax %n))
11 ; CHECK-NEXT: Predicates:
12 ; CHECK-NEXT: Loop %do.body: Trip multiple is 1
19 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
20 %arrayidx = getelementptr i32, ptr %p, i32 %i.0
21 store i32 %i.0, ptr %arrayidx, align 4
22 %inc = add i32 %i.0, 1
23 %cmp = icmp slt i32 %i.0, %add
24 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or 1 times
30 define void @s32_max2(i32 %n, ptr %p) {
31 ; CHECK-LABEL: 's32_max2'
32 ; CHECK-NEXT: Determining loop execution counts for: @s32_max2
33 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((2 + %n) smax %n))
34 ; CHECK-NEXT: Loop %do.body: constant max backedge-taken count is 2, actual taken count either this or zero.
35 ; CHECK-NEXT: Loop %do.body: symbolic max backedge-taken count is ((-1 * %n) + ((2 + %n) smax %n)), actual taken count either this or zero.
36 ; CHECK-NEXT: Loop %do.body: Predicated backedge-taken count is ((-1 * %n) + ((2 + %n) smax %n))
37 ; CHECK-NEXT: Predicates:
38 ; CHECK-NEXT: Loop %do.body: Trip multiple is 1
45 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
46 %arrayidx = getelementptr i32, ptr %p, i32 %i.0
47 store i32 %i.0, ptr %arrayidx, align 4
48 %inc = add i32 %i.0, 1
49 %cmp = icmp slt i32 %i.0, %add
50 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or 2 times
56 define void @s32_maxx(i32 %n, i32 %x, ptr %p) {
57 ; CHECK-LABEL: 's32_maxx'
58 ; CHECK-NEXT: Determining loop execution counts for: @s32_maxx
59 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((%n + %x) smax %n))
60 ; CHECK-NEXT: Loop %do.body: constant max backedge-taken count is -1
61 ; CHECK-NEXT: Loop %do.body: symbolic max backedge-taken count is ((-1 * %n) + ((%n + %x) smax %n))
62 ; CHECK-NEXT: Loop %do.body: Predicated backedge-taken count is ((-1 * %n) + ((%n + %x) smax %n))
63 ; CHECK-NEXT: Predicates:
64 ; CHECK-NEXT: Loop %do.body: Trip multiple is 1
71 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
72 %arrayidx = getelementptr i32, ptr %p, i32 %i.0
73 store i32 %i.0, ptr %arrayidx, align 4
74 %inc = add i32 %i.0, 1
75 %cmp = icmp slt i32 %i.0, %add
76 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or x times
82 define void @s32_max2_unpredictable_exit(i32 %n, i32 %x, ptr %p) {
83 ; CHECK-LABEL: 's32_max2_unpredictable_exit'
84 ; CHECK-NEXT: Determining loop execution counts for: @s32_max2_unpredictable_exit
85 ; CHECK-NEXT: Loop %do.body: <multiple exits> backedge-taken count is (((-1 * %n) + ((2 + %n) smax %n)) umin ((-1 * %n) + %x))
86 ; CHECK-NEXT: exit count for do.body: ((-1 * %n) + %x)
87 ; CHECK-NEXT: exit count for if.end: ((-1 * %n) + ((2 + %n) smax %n))
88 ; CHECK-NEXT: Loop %do.body: constant max backedge-taken count is 2
89 ; CHECK-NEXT: Loop %do.body: symbolic max backedge-taken count is (((-1 * %n) + ((2 + %n) smax %n)) umin ((-1 * %n) + %x))
90 ; CHECK-NEXT: symbolic max exit count for do.body: ((-1 * %n) + %x)
91 ; CHECK-NEXT: symbolic max exit count for if.end: ((-1 * %n) + ((2 + %n) smax %n))
92 ; CHECK-NEXT: Loop %do.body: Predicated backedge-taken count is (((-1 * %n) + ((2 + %n) smax %n)) umin ((-1 * %n) + %x))
93 ; CHECK-NEXT: Predicates:
94 ; CHECK-NEXT: Loop %do.body: Trip multiple is 1
101 %i.0 = phi i32 [ %n, %entry ], [ %inc, %if.end ]
102 %cmp = icmp eq i32 %i.0, %x
103 br i1 %cmp, label %do.end, label %if.end ; unpredictable
106 %arrayidx = getelementptr i32, ptr %p, i32 %i.0
107 store i32 %i.0, ptr %arrayidx, align 4
108 %inc = add i32 %i.0, 1
109 %cmp1 = icmp slt i32 %i.0, %add
110 br i1 %cmp1, label %do.body, label %do.end ; taken either 0 or 2 times
116 define void @u32_max1(i32 %n, ptr %p) {
117 ; CHECK-LABEL: 'u32_max1'
118 ; CHECK-NEXT: Determining loop execution counts for: @u32_max1
119 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((1 + %n) umax %n))
120 ; CHECK-NEXT: Loop %do.body: constant max backedge-taken count is 1, actual taken count either this or zero.
121 ; CHECK-NEXT: Loop %do.body: symbolic max backedge-taken count is ((-1 * %n) + ((1 + %n) umax %n)), actual taken count either this or zero.
122 ; CHECK-NEXT: Loop %do.body: Predicated backedge-taken count is ((-1 * %n) + ((1 + %n) umax %n))
123 ; CHECK-NEXT: Predicates:
124 ; CHECK-NEXT: Loop %do.body: Trip multiple is 1
131 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
132 %arrayidx = getelementptr i32, ptr %p, i32 %i.0
133 store i32 %i.0, ptr %arrayidx, align 4
134 %inc = add i32 %i.0, 1
135 %cmp = icmp ult i32 %i.0, %add
136 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or 1 times
142 define void @u32_max2(i32 %n, ptr %p) {
143 ; CHECK-LABEL: 'u32_max2'
144 ; CHECK-NEXT: Determining loop execution counts for: @u32_max2
145 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((2 + %n) umax %n))
146 ; CHECK-NEXT: Loop %do.body: constant max backedge-taken count is 2, actual taken count either this or zero.
147 ; CHECK-NEXT: Loop %do.body: symbolic max backedge-taken count is ((-1 * %n) + ((2 + %n) umax %n)), actual taken count either this or zero.
148 ; CHECK-NEXT: Loop %do.body: Predicated backedge-taken count is ((-1 * %n) + ((2 + %n) umax %n))
149 ; CHECK-NEXT: Predicates:
150 ; CHECK-NEXT: Loop %do.body: Trip multiple is 1
157 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
158 %arrayidx = getelementptr i32, ptr %p, i32 %i.0
159 store i32 %i.0, ptr %arrayidx, align 4
160 %inc = add i32 %i.0, 1
161 %cmp = icmp ult i32 %i.0, %add
162 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or 2 times
168 define void @u32_maxx(i32 %n, i32 %x, ptr %p) {
169 ; CHECK-LABEL: 'u32_maxx'
170 ; CHECK-NEXT: Determining loop execution counts for: @u32_maxx
171 ; CHECK-NEXT: Loop %do.body: backedge-taken count is ((-1 * %n) + ((%n + %x) umax %n))
172 ; CHECK-NEXT: Loop %do.body: constant max backedge-taken count is -1
173 ; CHECK-NEXT: Loop %do.body: symbolic max backedge-taken count is ((-1 * %n) + ((%n + %x) umax %n))
174 ; CHECK-NEXT: Loop %do.body: Predicated backedge-taken count is ((-1 * %n) + ((%n + %x) umax %n))
175 ; CHECK-NEXT: Predicates:
176 ; CHECK-NEXT: Loop %do.body: Trip multiple is 1
179 %add = add i32 %x, %n
183 %i.0 = phi i32 [ %n, %entry ], [ %inc, %do.body ]
184 %arrayidx = getelementptr i32, ptr %p, i32 %i.0
185 store i32 %i.0, ptr %arrayidx, align 4
186 %inc = add i32 %i.0, 1
187 %cmp = icmp ult i32 %i.0, %add
188 br i1 %cmp, label %do.body, label %do.end ; taken either 0 or x times
194 define void @u32_max2_unpredictable_exit(i32 %n, i32 %x, ptr %p) {
195 ; CHECK-LABEL: 'u32_max2_unpredictable_exit'
196 ; CHECK-NEXT: Determining loop execution counts for: @u32_max2_unpredictable_exit
197 ; CHECK-NEXT: Loop %do.body: <multiple exits> backedge-taken count is (((-1 * %n) + ((2 + %n) umax %n)) umin ((-1 * %n) + %x))
198 ; CHECK-NEXT: exit count for do.body: ((-1 * %n) + %x)
199 ; CHECK-NEXT: exit count for if.end: ((-1 * %n) + ((2 + %n) umax %n))
200 ; CHECK-NEXT: Loop %do.body: constant max backedge-taken count is 2
201 ; CHECK-NEXT: Loop %do.body: symbolic max backedge-taken count is (((-1 * %n) + ((2 + %n) umax %n)) umin ((-1 * %n) + %x))
202 ; CHECK-NEXT: symbolic max exit count for do.body: ((-1 * %n) + %x)
203 ; CHECK-NEXT: symbolic max exit count for if.end: ((-1 * %n) + ((2 + %n) umax %n))
204 ; CHECK-NEXT: Loop %do.body: Predicated backedge-taken count is (((-1 * %n) + ((2 + %n) umax %n)) umin ((-1 * %n) + %x))
205 ; CHECK-NEXT: Predicates:
206 ; CHECK-NEXT: Loop %do.body: Trip multiple is 1
213 %i.0 = phi i32 [ %n, %entry ], [ %inc, %if.end ]
214 %cmp = icmp eq i32 %i.0, %x
215 br i1 %cmp, label %do.end, label %if.end ; unpredictable
218 %arrayidx = getelementptr i32, ptr %p, i32 %i.0
219 store i32 %i.0, ptr %arrayidx, align 4
220 %inc = add i32 %i.0, 1
221 %cmp1 = icmp ult i32 %i.0, %add
222 br i1 %cmp1, label %do.body, label %do.end ; taken either 0 or 2 times