1 ; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" 2>&1 | FileCheck %s
3 declare void @llvm.experimental.guard(i1, ...)
5 define void @test_1(i32 %n) nounwind {
6 ; Prove that (n > 1) ===> (n / 2 > 0).
7 ; CHECK: Determining loop execution counts for: @test_1
8 ; CHECK: Loop %header: backedge-taken count is (-1 + %n.div.2)<nsw>
10 %cmp1 = icmp sgt i32 %n, 1
11 %n.div.2 = sdiv i32 %n, 2
12 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
16 %indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
17 %indvar.next = add i32 %indvar, 1
18 %exitcond = icmp sgt i32 %n.div.2, %indvar.next
19 br i1 %exitcond, label %header, label %exit
25 define void @test_1neg(i32 %n) nounwind {
26 ; Prove that (n > 0) =\=> (n / 2 > 0).
27 ; CHECK: Determining loop execution counts for: @test_1neg
28 ; CHECK: Loop %header: backedge-taken count is (-1 + (1 smax %n.div.2))<nsw>
30 %cmp1 = icmp sgt i32 %n, 0
31 %n.div.2 = sdiv i32 %n, 2
32 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
36 %indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
37 %indvar.next = add i32 %indvar, 1
38 %exitcond = icmp sgt i32 %n.div.2, %indvar.next
39 br i1 %exitcond, label %header, label %exit
45 define void @test_2(i32 %n) nounwind {
46 ; Prove that (n >= 2) ===> (n / 2 > 0).
47 ; CHECK: Determining loop execution counts for: @test_2
48 ; CHECK: Loop %header: backedge-taken count is (-1 + %n.div.2)<nsw>
50 %cmp1 = icmp sge i32 %n, 2
51 %n.div.2 = sdiv i32 %n, 2
52 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
56 %indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
57 %indvar.next = add i32 %indvar, 1
58 %exitcond = icmp sgt i32 %n.div.2, %indvar.next
59 br i1 %exitcond, label %header, label %exit
65 define void @test_2neg(i32 %n) nounwind {
66 ; Prove that (n >= 1) =\=> (n / 2 > 0).
67 ; CHECK: Determining loop execution counts for: @test_2neg
68 ; CHECK: Loop %header: backedge-taken count is (-1 + (1 smax %n.div.2))<nsw>
70 %cmp1 = icmp sge i32 %n, 1
71 %n.div.2 = sdiv i32 %n, 2
72 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
76 %indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
77 %indvar.next = add i32 %indvar, 1
78 %exitcond = icmp sgt i32 %n.div.2, %indvar.next
79 br i1 %exitcond, label %header, label %exit
85 define void @test_3(i32 %n) nounwind {
86 ; Prove that (n > -2) ===> (n / 2 >= 0).
87 ; CHECK: Determining loop execution counts for: @test_3
88 ; CHECK: Loop %header: backedge-taken count is (1 + %n.div.2)<nsw>
90 %cmp1 = icmp sgt i32 %n, -2
91 %n.div.2 = sdiv i32 %n, 2
92 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
96 %indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
97 %indvar.next = add i32 %indvar, 1
98 %exitcond = icmp sge i32 %n.div.2, %indvar
99 br i1 %exitcond, label %header, label %exit
105 define void @test_3neg(i32 %n) nounwind {
106 ; Prove that (n > -3) =\=> (n / 2 >= 0).
107 ; CHECK: Determining loop execution counts for: @test_3neg
108 ; CHECK: Loop %header: backedge-taken count is (0 smax (1 + %n.div.2)<nsw>)
110 %cmp1 = icmp sgt i32 %n, -3
111 %n.div.2 = sdiv i32 %n, 2
112 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
116 %indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
117 %indvar.next = add i32 %indvar, 1
118 %exitcond = icmp sge i32 %n.div.2, %indvar
119 br i1 %exitcond, label %header, label %exit
125 define void @test_4(i32 %n) nounwind {
126 ; Prove that (n >= -1) ===> (n / 2 >= 0).
127 ; CHECK: Determining loop execution counts for: @test_4
128 ; CHECK: Loop %header: backedge-taken count is (1 + %n.div.2)<nsw>
130 %cmp1 = icmp sge i32 %n, -1
131 %n.div.2 = sdiv i32 %n, 2
132 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
136 %indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
137 %indvar.next = add i32 %indvar, 1
138 %exitcond = icmp sge i32 %n.div.2, %indvar
139 br i1 %exitcond, label %header, label %exit
145 define void @test_4neg(i32 %n) nounwind {
146 ; Prove that (n >= -2) =\=> (n / 2 >= 0).
147 ; CHECK: Determining loop execution counts for: @test_4neg
148 ; CHECK: Loop %header: backedge-taken count is (0 smax (1 + %n.div.2)<nsw>)
150 %cmp1 = icmp sge i32 %n, -2
151 %n.div.2 = sdiv i32 %n, 2
152 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
156 %indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
157 %indvar.next = add i32 %indvar, 1
158 %exitcond = icmp sge i32 %n.div.2, %indvar
159 br i1 %exitcond, label %header, label %exit
165 define void @test_ext_01(i32 %n) nounwind {
166 ; Prove that (n > 1) ===> (n / 2 > 0).
167 ; CHECK: Determining loop execution counts for: @test_ext_01
168 ; CHECK: Loop %header: backedge-taken count is (-1 + (sext i32 %n.div.2 to i64))<nsw>
170 %cmp1 = icmp sgt i32 %n, 1
171 %n.div.2 = sdiv i32 %n, 2
172 %n.div.2.ext = sext i32 %n.div.2 to i64
173 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
177 %indvar = phi i64 [ %indvar.next, %header ], [ 0, %entry ]
178 %indvar.next = add i64 %indvar, 1
179 %exitcond = icmp sgt i64 %n.div.2.ext, %indvar.next
180 br i1 %exitcond, label %header, label %exit
186 define void @test_ext_01neg(i32 %n) nounwind {
187 ; Prove that (n > 0) =\=> (n / 2 > 0).
188 ; CHECK: Determining loop execution counts for: @test_ext_01neg
189 ; CHECK: Loop %header: backedge-taken count is (-1 + (1 smax (sext i32 %n.div.2 to i64)))<nsw>
191 %cmp1 = icmp sgt i32 %n, 0
192 %n.div.2 = sdiv i32 %n, 2
193 %n.div.2.ext = sext i32 %n.div.2 to i64
194 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
198 %indvar = phi i64 [ %indvar.next, %header ], [ 0, %entry ]
199 %indvar.next = add i64 %indvar, 1
200 %exitcond = icmp sgt i64 %n.div.2.ext, %indvar.next
201 br i1 %exitcond, label %header, label %exit
207 define void @test_ext_02(i32 %n) nounwind {
208 ; Prove that (n >= 2) ===> (n / 2 > 0).
209 ; CHECK: Determining loop execution counts for: @test_ext_02
210 ; CHECK: Loop %header: backedge-taken count is (-1 + (sext i32 %n.div.2 to i64))<nsw>
212 %cmp1 = icmp sge i32 %n, 2
213 %n.div.2 = sdiv i32 %n, 2
214 %n.div.2.ext = sext i32 %n.div.2 to i64
215 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
219 %indvar = phi i64 [ %indvar.next, %header ], [ 0, %entry ]
220 %indvar.next = add i64 %indvar, 1
221 %exitcond = icmp sgt i64 %n.div.2.ext, %indvar.next
222 br i1 %exitcond, label %header, label %exit
228 define void @test_ext_02neg(i32 %n) nounwind {
229 ; Prove that (n >= 1) =\=> (n / 2 > 0).
230 ; CHECK: Determining loop execution counts for: @test_ext_02neg
231 ; CHECK: Loop %header: backedge-taken count is (-1 + (1 smax (sext i32 %n.div.2 to i64)))<nsw>
233 %cmp1 = icmp sge i32 %n, 1
234 %n.div.2 = sdiv i32 %n, 2
235 %n.div.2.ext = sext i32 %n.div.2 to i64
236 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
240 %indvar = phi i64 [ %indvar.next, %header ], [ 0, %entry ]
241 %indvar.next = add i64 %indvar, 1
242 %exitcond = icmp sgt i64 %n.div.2.ext, %indvar.next
243 br i1 %exitcond, label %header, label %exit
249 define void @test_ext_03(i32 %n) nounwind {
250 ; Prove that (n > -2) ===> (n / 2 >= 0).
251 ; CHECK: Determining loop execution counts for: @test_ext_03
252 ; CHECK: Loop %header: backedge-taken count is (1 + (sext i32 %n.div.2 to i64))<nsw>
254 %cmp1 = icmp sgt i32 %n, -2
255 %n.div.2 = sdiv i32 %n, 2
256 %n.div.2.ext = sext i32 %n.div.2 to i64
257 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
261 %indvar = phi i64 [ %indvar.next, %header ], [ 0, %entry ]
262 %indvar.next = add i64 %indvar, 1
263 %exitcond = icmp sge i64 %n.div.2.ext, %indvar
264 br i1 %exitcond, label %header, label %exit
270 define void @test_ext_03neg(i32 %n) nounwind {
271 ; Prove that (n > -3) =\=> (n / 2 >= 0).
272 ; CHECK: Determining loop execution counts for: @test_ext_03neg
273 ; CHECK: Loop %header: backedge-taken count is (0 smax (1 + (sext i32 %n.div.2 to i64))<nsw>)
275 %cmp1 = icmp sgt i32 %n, -3
276 %n.div.2 = sdiv i32 %n, 2
277 %n.div.2.ext = sext i32 %n.div.2 to i64
278 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
282 %indvar = phi i64 [ %indvar.next, %header ], [ 0, %entry ]
283 %indvar.next = add i64 %indvar, 1
284 %exitcond = icmp sge i64 %n.div.2.ext, %indvar
285 br i1 %exitcond, label %header, label %exit
291 define void @test_ext_04(i32 %n) nounwind {
292 ; Prove that (n >= -1) ===> (n / 2 >= 0).
293 ; CHECK: Determining loop execution counts for: @test_ext_04
294 ; CHECK: Loop %header: backedge-taken count is (1 + (sext i32 %n.div.2 to i64))<nsw>
296 %cmp1 = icmp sge i32 %n, -1
297 %n.div.2 = sdiv i32 %n, 2
298 %n.div.2.ext = sext i32 %n.div.2 to i64
299 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
303 %indvar = phi i64 [ %indvar.next, %header ], [ 0, %entry ]
304 %indvar.next = add i64 %indvar, 1
305 %exitcond = icmp sge i64 %n.div.2.ext, %indvar
306 br i1 %exitcond, label %header, label %exit
312 define void @test_ext_04neg(i32 %n) nounwind {
313 ; Prove that (n >= -2) =\=> (n / 2 >= 0).
314 ; CHECK: Determining loop execution counts for: @test_ext_04neg
315 ; CHECK: Loop %header: backedge-taken count is (0 smax (1 + (sext i32 %n.div.2 to i64))<nsw>)
317 %cmp1 = icmp sge i32 %n, -2
318 %n.div.2 = sdiv i32 %n, 2
319 %n.div.2.ext = sext i32 %n.div.2 to i64
320 call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
324 %indvar = phi i64 [ %indvar.next, %header ], [ 0, %entry ]
325 %indvar.next = add i64 %indvar, 1
326 %exitcond = icmp sge i64 %n.div.2.ext, %indvar
327 br i1 %exitcond, label %header, label %exit