1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -indvars -S | FileCheck %s
4 define void @test1() nounwind {
7 ; CHECK-NEXT: br label [[BB:%.*]]
9 ; CHECK-NEXT: [[IV_INT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[DOTINT:%.*]], [[BB]] ]
10 ; CHECK-NEXT: [[INDVAR_CONV:%.*]] = sitofp i32 [[IV_INT]] to double
11 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @foo(double [[INDVAR_CONV]]) #[[ATTR0:[0-9]+]]
12 ; CHECK-NEXT: [[DOTINT]] = add nuw nsw i32 [[IV_INT]], 1
13 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[DOTINT]], 10000
14 ; CHECK-NEXT: br i1 [[TMP1]], label [[BB]], label [[RETURN:%.*]]
16 ; CHECK-NEXT: ret void
21 bb: ; preds = %bb, %entry
22 %iv = phi double [ 0.000000e+00, %entry ], [ %1, %bb ]
23 %0 = tail call i32 @foo(double %iv) nounwind
24 %1 = fadd double %iv, 1.000000e+00
25 %2 = fcmp olt double %1, 1.000000e+04
26 br i1 %2, label %bb, label %return
32 declare i32 @foo(double)
34 define void @test2() nounwind {
35 ; CHECK-LABEL: @test2(
37 ; CHECK-NEXT: br label [[BB:%.*]]
39 ; CHECK-NEXT: [[IV_INT:%.*]] = phi i32 [ -10, [[ENTRY:%.*]] ], [ [[DOTINT:%.*]], [[BB]] ]
40 ; CHECK-NEXT: [[INDVAR_CONV:%.*]] = sitofp i32 [[IV_INT]] to double
41 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @foo(double [[INDVAR_CONV]]) #[[ATTR0]]
42 ; CHECK-NEXT: [[DOTINT]] = add nsw i32 [[IV_INT]], 2
43 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[DOTINT]], -1
44 ; CHECK-NEXT: br i1 [[TMP1]], label [[BB]], label [[RETURN:%.*]]
46 ; CHECK-NEXT: ret void
51 bb: ; preds = %bb, %entry
52 %iv = phi double [ -10.000000e+00, %entry ], [ %1, %bb ]
53 %0 = tail call i32 @foo(double %iv) nounwind
54 %1 = fadd double %iv, 2.000000e+00
55 %2 = fcmp olt double %1, -1.000000e+00
56 br i1 %2, label %bb, label %return
63 define void @test3() nounwind {
64 ; CHECK-LABEL: @test3(
66 ; CHECK-NEXT: br label [[BB:%.*]]
68 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @foo(double 0.000000e+00) #[[ATTR0]]
69 ; CHECK-NEXT: br i1 false, label [[BB]], label [[RETURN:%.*]]
71 ; CHECK-NEXT: ret void
76 bb: ; preds = %bb, %entry
77 %iv = phi double [ 0.000000e+00, %entry ], [ %1, %bb ]
78 %0 = tail call i32 @foo(double %iv) nounwind
79 %1 = fadd double %iv, 1.000000e+00
80 %2 = fcmp olt double %1, -1.000000e+00
81 br i1 %2, label %bb, label %return
87 define void @test4() nounwind {
88 ; CHECK-LABEL: @test4(
90 ; CHECK-NEXT: br label [[BB:%.*]]
92 ; CHECK-NEXT: [[IV_INT:%.*]] = phi i32 [ 40, [[ENTRY:%.*]] ], [ [[DOTINT:%.*]], [[BB]] ]
93 ; CHECK-NEXT: [[INDVAR_CONV:%.*]] = sitofp i32 [[IV_INT]] to double
94 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @foo(double [[INDVAR_CONV]]) #[[ATTR0]]
95 ; CHECK-NEXT: [[DOTINT]] = add nsw i32 [[IV_INT]], -1
96 ; CHECK-NEXT: br i1 false, label [[BB]], label [[RETURN:%.*]]
98 ; CHECK-NEXT: ret void
103 bb: ; preds = %bb, %entry
104 %iv = phi double [ 40.000000e+00, %entry ], [ %1, %bb ]
105 %0 = tail call i32 @foo(double %iv) nounwind
106 %1 = fadd double %iv, -1.000000e+00
107 %2 = fcmp olt double %1, 1.000000e+00
108 br i1 %2, label %bb, label %return
115 define void @test5() nounwind {
117 ; CHECK-LABEL: @test5(
118 ; CHECK-NEXT: br label [[TMP1:%.*]]
120 ; CHECK-NEXT: [[DOTINT:%.*]] = phi i32 [ 9, [[TMP0:%.*]] ], [ [[DOTINT1:%.*]], [[TMP1]] ]
121 ; CHECK-NEXT: [[TMP2:%.*]] = tail call i32 @foo(double 0.000000e+00)
122 ; CHECK-NEXT: [[DOTINT1]] = add nsw i32 [[DOTINT]], -1
123 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i32 [[DOTINT1]], 0
124 ; CHECK-NEXT: br i1 [[TMP3]], label [[EXIT:%.*]], label [[TMP1]]
126 ; CHECK-NEXT: ret void
131 %2 = phi double [ 9.000000e+00, %0 ], [ %4, %1 ]
132 %3 = tail call i32 @foo(double 0.0)
133 %4 = fadd double %2, -1.000000e+00
134 %5 = fcmp ult double %4, 0.000000e+00
135 br i1 %5, label %exit, label %1
141 define double @test_max_be() {
142 ; CHECK-LABEL: @test_max_be(
144 ; CHECK-NEXT: br label [[BB8:%.*]]
146 ; CHECK-NEXT: [[TMP10:%.*]] = phi double [ 0.000000e+00, [[BB4:%.*]] ], [ [[TMP12:%.*]], [[BB22:%.*]] ]
147 ; CHECK-NEXT: [[TMP11_INT:%.*]] = phi i32 [ 0, [[BB4]] ], [ [[TMP13_INT:%.*]], [[BB22]] ]
148 ; CHECK-NEXT: [[INDVAR_CONV:%.*]] = sitofp i32 [[TMP11_INT]] to double
149 ; CHECK-NEXT: [[TMP12]] = fadd double [[TMP10]], [[INDVAR_CONV]]
150 ; CHECK-NEXT: [[TMP13_INT]] = add nuw nsw i32 [[TMP11_INT]], 1
151 ; CHECK-NEXT: [[TMP14:%.*]] = icmp ult i32 [[TMP13_INT]], 99999
152 ; CHECK-NEXT: br i1 [[TMP14]], label [[BB22]], label [[BB6:%.*]]
154 ; CHECK-NEXT: br i1 true, label [[BB8]], label [[BB6]]
156 ; CHECK-NEXT: [[TMP12_LCSSA:%.*]] = phi double [ [[TMP12]], [[BB22]] ], [ [[TMP12]], [[BB8]] ]
157 ; CHECK-NEXT: ret double [[TMP12_LCSSA]]
163 %tmp9 = phi i64 [ 1, %bb4 ], [ %tmp23, %bb22 ]
164 %tmp10 = phi double [ 0.000000e+00, %bb4 ], [ %tmp12, %bb22 ]
165 %tmp11 = phi double [ 0.000000e+00, %bb4 ], [ %tmp13, %bb22 ]
166 %tmp12 = fadd double %tmp10, %tmp11
167 %tmp13 = fadd double %tmp11, 1.000000e+00
168 %tmp14 = fcmp olt double %tmp13, 9.999900e+04
169 br i1 %tmp14, label %bb22, label %bb6
172 %tmp23 = add nuw nsw i64 %tmp9, 1
173 %tmp24 = icmp ult i64 %tmp9, 1048576
174 br i1 %tmp24, label %bb8, label %bb6
180 define float @test_max_be2() {
181 ; CHECK-LABEL: @test_max_be2(
183 ; CHECK-NEXT: br label [[BB8:%.*]]
185 ; CHECK-NEXT: [[TMP10:%.*]] = phi float [ 0.000000e+00, [[BB4:%.*]] ], [ [[TMP12:%.*]], [[BB22:%.*]] ]
186 ; CHECK-NEXT: [[TMP11_INT:%.*]] = phi i32 [ 0, [[BB4]] ], [ [[TMP13_INT:%.*]], [[BB22]] ]
187 ; CHECK-NEXT: [[INDVAR_CONV:%.*]] = sitofp i32 [[TMP11_INT]] to float
188 ; CHECK-NEXT: [[TMP12]] = fadd float [[TMP10]], [[INDVAR_CONV]]
189 ; CHECK-NEXT: [[TMP13_INT]] = add nuw nsw i32 [[TMP11_INT]], 1
190 ; CHECK-NEXT: [[TMP14:%.*]] = icmp ult i32 [[TMP13_INT]], 99999
191 ; CHECK-NEXT: br i1 [[TMP14]], label [[BB22]], label [[BB6:%.*]]
193 ; CHECK-NEXT: br i1 true, label [[BB8]], label [[BB6]]
195 ; CHECK-NEXT: [[TMP12_LCSSA:%.*]] = phi float [ [[TMP12]], [[BB22]] ], [ [[TMP12]], [[BB8]] ]
196 ; CHECK-NEXT: ret float [[TMP12_LCSSA]]
202 %tmp9 = phi i64 [ 1, %bb4 ], [ %tmp23, %bb22 ]
203 %tmp10 = phi float [ 0.000000e+00, %bb4 ], [ %tmp12, %bb22 ]
204 %tmp11 = phi float [ 0.000000e+00, %bb4 ], [ %tmp13, %bb22 ]
205 %tmp12 = fadd float %tmp10, %tmp11
206 %tmp13 = fadd float %tmp11, 1.000000e+00
207 %tmp14 = fcmp olt float %tmp13, 9.999900e+04
208 br i1 %tmp14, label %bb22, label %bb6
211 %tmp23 = add nuw nsw i64 %tmp9, 1
212 %tmp24 = icmp ult i64 %tmp9, 1048576
213 br i1 %tmp24, label %bb8, label %bb6
220 define float @test_max_be3() {
221 ; CHECK-LABEL: @test_max_be3(
223 ; CHECK-NEXT: br label [[BB8:%.*]]
225 ; CHECK-NEXT: [[TMP10:%.*]] = phi float [ 0.000000e+00, [[BB4:%.*]] ], [ [[TMP12:%.*]], [[BB22:%.*]] ]
226 ; CHECK-NEXT: [[TMP11_INT:%.*]] = phi i32 [ 0, [[BB4]] ], [ [[TMP13_INT:%.*]], [[BB22]] ]
227 ; CHECK-NEXT: [[INDVAR_CONV:%.*]] = sitofp i32 [[TMP11_INT]] to float
228 ; CHECK-NEXT: [[TMP12]] = fadd float [[TMP10]], [[INDVAR_CONV]]
229 ; CHECK-NEXT: [[TMP13_INT]] = add nuw nsw i32 [[TMP11_INT]], 1
230 ; CHECK-NEXT: [[TMP14:%.*]] = icmp ult i32 [[TMP13_INT]], 99999
231 ; CHECK-NEXT: br i1 [[TMP14]], label [[BB22]], label [[BB6:%.*]]
233 ; CHECK-NEXT: br i1 true, label [[BB8]], label [[BB6]]
235 ; CHECK-NEXT: [[TMP12_LCSSA:%.*]] = phi float [ [[TMP12]], [[BB22]] ], [ [[TMP12]], [[BB8]] ]
236 ; CHECK-NEXT: ret float [[TMP12_LCSSA]]
242 %tmp9 = phi i64 [ 1, %bb4 ], [ %tmp23, %bb22 ]
243 %tmp10 = phi float [ 0.000000e+00, %bb4 ], [ %tmp12, %bb22 ]
244 %tmp11 = phi float [ 0.000000e+00, %bb4 ], [ %tmp13, %bb22 ]
245 %tmp12 = fadd float %tmp10, %tmp11
246 %tmp13 = fadd float %tmp11, 1.000000e+00
247 %tmp14 = fcmp olt float %tmp13, 9.999900e+04
248 br i1 %tmp14, label %bb22, label %bb6
251 %tmp23 = add nuw nsw i64 %tmp9, 1
253 %tmp24 = icmp ult i64 %tmp9, 16777215
254 br i1 %tmp24, label %bb8, label %bb6
261 ; Show that given a computeable exit count, we can remove an
262 ; fcmp of a casted integer IV. (TODO)
263 define void @fcmp1() nounwind {
264 ; CHECK-LABEL: @fcmp1(
266 ; CHECK-NEXT: br label [[BB:%.*]]
268 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ]
269 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i64 [[IV]], 20000
270 ; CHECK-NEXT: br i1 [[CMP1]], label [[BACKEDGE]], label [[RETURN:%.*]]
272 ; CHECK-NEXT: [[IV_FP:%.*]] = sitofp i64 [[IV]] to double
273 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @foo(double [[IV_FP]]) #[[ATTR0]]
274 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
275 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp olt double [[IV_FP]], 1.000000e+04
276 ; CHECK-NEXT: br i1 [[CMP2]], label [[BB]], label [[RETURN]]
278 ; CHECK-NEXT: ret void
283 bb: ; preds = %bb, %entry
284 %iv = phi i64 [ 0, %entry ], [ %iv.next, %backedge ]
285 %cmp1 = icmp slt i64 %iv, 20000
286 br i1 %cmp1, label %backedge, label %return
289 %iv.fp = sitofp i64 %iv to double
290 tail call i32 @foo(double %iv.fp) nounwind
291 %iv.next = add nsw nuw i64 %iv, 1
292 %cmp2 = fcmp olt double %iv.fp, 1.000000e+04
293 br i1 %cmp2, label %bb, label %return
295 return: ; preds = %bb
299 define void @fcmp2() nounwind {
300 ; CHECK-LABEL: @fcmp2(
302 ; CHECK-NEXT: br label [[BB:%.*]]
304 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ]
305 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i64 [[IV]], 2000
306 ; CHECK-NEXT: br i1 [[CMP1]], label [[BACKEDGE]], label [[RETURN:%.*]]
308 ; CHECK-NEXT: [[IV_FP:%.*]] = sitofp i64 [[IV]] to double
309 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @foo(double [[IV_FP]]) #[[ATTR0]]
310 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
311 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp olt double [[IV_FP]], 1.000000e+04
312 ; CHECK-NEXT: br i1 [[CMP2]], label [[BB]], label [[RETURN]]
314 ; CHECK-NEXT: ret void
319 bb: ; preds = %bb, %entry
320 %iv = phi i64 [ 0, %entry ], [ %iv.next, %backedge ]
321 %cmp1 = icmp slt i64 %iv, 2000
322 br i1 %cmp1, label %backedge, label %return
325 %iv.fp = sitofp i64 %iv to double
326 tail call i32 @foo(double %iv.fp) nounwind
327 %iv.next = add nsw nuw i64 %iv, 1
328 %cmp2 = fcmp olt double %iv.fp, 1.000000e+04
329 br i1 %cmp2, label %bb, label %return
331 return: ; preds = %bb
335 define void @fcmp_neg1() nounwind {
336 ; CHECK-LABEL: @fcmp_neg1(
338 ; CHECK-NEXT: br label [[BB:%.*]]
340 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ]
341 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i64 [[IV]], -20
342 ; CHECK-NEXT: br i1 [[CMP1]], label [[BACKEDGE]], label [[RETURN:%.*]]
344 ; CHECK-NEXT: [[IV_FP:%.*]] = sitofp i64 [[IV]] to double
345 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @foo(double [[IV_FP]]) #[[ATTR0]]
346 ; CHECK-NEXT: [[IV_NEXT]] = add nuw i64 [[IV]], 1
347 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp olt double [[IV_FP]], 1.000000e+04
348 ; CHECK-NEXT: br i1 [[CMP2]], label [[BB]], label [[RETURN]]
350 ; CHECK-NEXT: ret void
355 bb: ; preds = %bb, %entry
356 %iv = phi i64 [ 0, %entry ], [ %iv.next, %backedge ]
357 ;; Range fact outside precise integer region
358 %cmp1 = icmp ult i64 %iv, -20
359 br i1 %cmp1, label %backedge, label %return
362 %iv.fp = sitofp i64 %iv to double
363 tail call i32 @foo(double %iv.fp) nounwind
364 %iv.next = add nuw i64 %iv, 1
365 %cmp2 = fcmp olt double %iv.fp, 1.000000e+04
366 br i1 %cmp2, label %bb, label %return
368 return: ; preds = %bb