1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=indvars -S -indvars-predicate-loops=0 | FileCheck %s
4 ; Make sure that indvars isn't inserting canonical IVs.
5 ; This is kinda hard to do until linear function test replacement is removed.
7 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
9 ; We should only have 2 IVs.
10 ; sext should be eliminated while preserving gep inboundsness.
11 define i32 @sum(ptr %arr, i32 %n) nounwind {
14 ; CHECK-NEXT: [[PRECOND:%.*]] = icmp slt i32 0, [[N:%.*]]
15 ; CHECK-NEXT: br i1 [[PRECOND]], label [[PH:%.*]], label [[RETURN:%.*]]
17 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[N]] to i64
18 ; CHECK-NEXT: br label [[LOOP:%.*]]
20 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LOOP]] ], [ 0, [[PH]] ]
21 ; CHECK-NEXT: [[S_01:%.*]] = phi i32 [ 0, [[PH]] ], [ [[SINC:%.*]], [[LOOP]] ]
22 ; CHECK-NEXT: [[ADR:%.*]] = getelementptr inbounds i32, ptr [[ARR:%.*]], i64 [[INDVARS_IV]]
23 ; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ADR]], align 4
24 ; CHECK-NEXT: [[SINC]] = add nsw i32 [[S_01]], [[VAL]]
25 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
26 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
27 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT:%.*]]
29 ; CHECK-NEXT: [[S_LCSSA:%.*]] = phi i32 [ [[SINC]], [[LOOP]] ]
30 ; CHECK-NEXT: br label [[RETURN]]
32 ; CHECK-NEXT: [[S_0_LCSSA:%.*]] = phi i32 [ [[S_LCSSA]], [[EXIT]] ], [ 0, [[ENTRY:%.*]] ]
33 ; CHECK-NEXT: ret i32 [[S_0_LCSSA]]
36 %precond = icmp slt i32 0, %n
37 br i1 %precond, label %ph, label %return
43 %i.02 = phi i32 [ 0, %ph ], [ %iinc, %loop ]
44 %s.01 = phi i32 [ 0, %ph ], [ %sinc, %loop ]
45 %ofs = sext i32 %i.02 to i64
46 %adr = getelementptr inbounds i32, ptr %arr, i64 %ofs
47 %val = load i32, ptr %adr
48 %sinc = add nsw i32 %s.01, %val
49 %iinc = add nsw i32 %i.02, 1
50 %cond = icmp slt i32 %iinc, %n
51 br i1 %cond, label %loop, label %exit
54 %s.lcssa = phi i32 [ %sinc, %loop ]
58 %s.0.lcssa = phi i32 [ %s.lcssa, %exit ], [ 0, %entry ]
62 ; We should only have 2 IVs.
63 ; %ofs sext should be eliminated while preserving gep inboundsness.
64 ; %vall sext should obviously not be eliminated
65 define i64 @suml(ptr %arr, i32 %n) nounwind {
68 ; CHECK-NEXT: [[PRECOND:%.*]] = icmp slt i32 0, [[N:%.*]]
69 ; CHECK-NEXT: br i1 [[PRECOND]], label [[PH:%.*]], label [[RETURN:%.*]]
71 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[N]] to i64
72 ; CHECK-NEXT: br label [[LOOP:%.*]]
74 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LOOP]] ], [ 0, [[PH]] ]
75 ; CHECK-NEXT: [[S_01:%.*]] = phi i64 [ 0, [[PH]] ], [ [[SINC:%.*]], [[LOOP]] ]
76 ; CHECK-NEXT: [[ADR:%.*]] = getelementptr inbounds i32, ptr [[ARR:%.*]], i64 [[INDVARS_IV]]
77 ; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ADR]], align 4
78 ; CHECK-NEXT: [[VALL:%.*]] = sext i32 [[VAL]] to i64
79 ; CHECK-NEXT: [[SINC]] = add nsw i64 [[S_01]], [[VALL]]
80 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
81 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
82 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT:%.*]]
84 ; CHECK-NEXT: [[S_LCSSA:%.*]] = phi i64 [ [[SINC]], [[LOOP]] ]
85 ; CHECK-NEXT: br label [[RETURN]]
87 ; CHECK-NEXT: [[S_0_LCSSA:%.*]] = phi i64 [ [[S_LCSSA]], [[EXIT]] ], [ 0, [[ENTRY:%.*]] ]
88 ; CHECK-NEXT: ret i64 [[S_0_LCSSA]]
91 %precond = icmp slt i32 0, %n
92 br i1 %precond, label %ph, label %return
98 %i.02 = phi i32 [ 0, %ph ], [ %iinc, %loop ]
99 %s.01 = phi i64 [ 0, %ph ], [ %sinc, %loop ]
100 %ofs = sext i32 %i.02 to i64
101 %adr = getelementptr inbounds i32, ptr %arr, i64 %ofs
102 %val = load i32, ptr %adr
103 %vall = sext i32 %val to i64
104 %sinc = add nsw i64 %s.01, %vall
105 %iinc = add nsw i32 %i.02, 1
106 %cond = icmp slt i32 %iinc, %n
107 br i1 %cond, label %loop, label %exit
110 %s.lcssa = phi i64 [ %sinc, %loop ]
114 %s.0.lcssa = phi i64 [ %s.lcssa, %exit ], [ 0, %entry ]
118 ; It's not indvars' job to perform LICM on %ofs
119 ; Preserve exactly one pointer type IV.
120 ; Don't create any extra adds.
121 ; Preserve gep inboundsness, and don't factor it.
122 define void @outofbounds(ptr %first, ptr %last, i32 %idx) nounwind {
123 ; CHECK-LABEL: @outofbounds(
124 ; CHECK-NEXT: [[PRECOND:%.*]] = icmp ne ptr [[FIRST:%.*]], [[LAST:%.*]]
125 ; CHECK-NEXT: br i1 [[PRECOND]], label [[PH:%.*]], label [[RETURN:%.*]]
127 ; CHECK-NEXT: br label [[LOOP:%.*]]
129 ; CHECK-NEXT: [[PTRIV:%.*]] = phi ptr [ [[FIRST]], [[PH]] ], [ [[PTRPOST:%.*]], [[LOOP]] ]
130 ; CHECK-NEXT: [[OFS:%.*]] = sext i32 [[IDX:%.*]] to i64
131 ; CHECK-NEXT: [[ADR:%.*]] = getelementptr inbounds i32, ptr [[PTRIV]], i64 [[OFS]]
132 ; CHECK-NEXT: store i32 3, ptr [[ADR]], align 4
133 ; CHECK-NEXT: [[PTRPOST]] = getelementptr inbounds i32, ptr [[PTRIV]], i32 1
134 ; CHECK-NEXT: [[COND:%.*]] = icmp ne ptr [[PTRPOST]], [[LAST]]
135 ; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT:%.*]]
137 ; CHECK-NEXT: br label [[RETURN]]
139 ; CHECK-NEXT: ret void
141 %precond = icmp ne ptr %first, %last
142 br i1 %precond, label %ph, label %return
148 %ptriv = phi ptr [ %first, %ph ], [ %ptrpost, %loop ]
149 %ofs = sext i32 %idx to i64
150 %adr = getelementptr inbounds i32, ptr %ptriv, i64 %ofs
151 store i32 3, ptr %adr
152 %ptrpost = getelementptr inbounds i32, ptr %ptriv, i32 1
153 %cond = icmp ne ptr %ptrpost, %last
154 br i1 %cond, label %loop, label %exit
163 %structI = type { i32 }
166 define void @bitcastiv(i32 %start, i32 %limit, i32 %step, ptr %base)
167 ; CHECK-LABEL: @bitcastiv(
169 ; CHECK-NEXT: br label [[LOOP:%.*]]
171 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[START:%.*]], [[ENTRY:%.*]] ], [ [[NEXT:%.*]], [[LOOP]] ]
172 ; CHECK-NEXT: [[P:%.*]] = phi ptr [ [[BASE:%.*]], [[ENTRY]] ], [ [[PINC:%.*]], [[LOOP]] ]
173 ; CHECK-NEXT: store i32 3, ptr [[P]], align 4
174 ; CHECK-NEXT: store i32 4, ptr [[P]], align 4
175 ; CHECK-NEXT: [[PINC]] = getelementptr [[STRUCTI:%.*]], ptr [[P]], i32 1
176 ; CHECK-NEXT: [[NEXT]] = add i32 [[IV]], 1
177 ; CHECK-NEXT: [[COND:%.*]] = icmp ne i32 [[NEXT]], [[LIMIT:%.*]]
178 ; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT:%.*]]
180 ; CHECK-NEXT: ret void
188 %iv = phi i32 [%start, %entry], [%next, %loop]
189 %p = phi ptr [%base, %entry], [%pinc, %loop]
192 %pinc = getelementptr %structI, ptr %p, i32 1
193 %next = add i32 %iv, 1
194 %cond = icmp ne i32 %next, %limit
195 br i1 %cond, label %loop, label %exit
201 ; Test inserting a truncate at a phi use.
202 define void @maxvisitor(i32 %limit, ptr %base) nounwind {
203 ; CHECK-LABEL: @maxvisitor(
205 ; CHECK-NEXT: [[SMAX:%.*]] = call i32 @llvm.smax.i32(i32 [[LIMIT:%.*]], i32 1)
206 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[SMAX]] to i64
207 ; CHECK-NEXT: br label [[LOOP:%.*]]
209 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LOOP_INC:%.*]] ], [ 0, [[ENTRY:%.*]] ]
210 ; CHECK-NEXT: [[MAX:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[MAX_NEXT:%.*]], [[LOOP_INC]] ]
211 ; CHECK-NEXT: [[ADR:%.*]] = getelementptr inbounds i32, ptr [[BASE:%.*]], i64 [[INDVARS_IV]]
212 ; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ADR]], align 4
213 ; CHECK-NEXT: [[CMP19:%.*]] = icmp sgt i32 [[VAL]], [[MAX]]
214 ; CHECK-NEXT: br i1 [[CMP19]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
216 ; CHECK-NEXT: [[TMP0:%.*]] = trunc nuw nsw i64 [[INDVARS_IV]] to i32
217 ; CHECK-NEXT: br label [[LOOP_INC]]
219 ; CHECK-NEXT: br label [[LOOP_INC]]
221 ; CHECK-NEXT: [[MAX_NEXT]] = phi i32 [ [[TMP0]], [[IF_THEN]] ], [ [[MAX]], [[IF_ELSE]] ]
222 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
223 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
224 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT:%.*]]
226 ; CHECK-NEXT: ret void
232 %idx = phi i32 [ 0, %entry ], [ %idx.next, %loop.inc ]
233 %max = phi i32 [ 0, %entry ], [ %max.next, %loop.inc ]
234 %idxprom = sext i32 %idx to i64
235 %adr = getelementptr inbounds i32, ptr %base, i64 %idxprom
236 %val = load i32, ptr %adr
237 %cmp19 = icmp sgt i32 %val, %max
238 br i1 %cmp19, label %if.then, label %if.else
247 %max.next = phi i32 [ %idx, %if.then ], [ %max, %if.else ]
248 %idx.next = add nsw i32 %idx, 1
249 %cmp = icmp slt i32 %idx.next, %limit
250 br i1 %cmp, label %loop, label %exit
256 ; Test an edge case of removing an identity phi that directly feeds
257 ; back to the loop iv.
258 define void @identityphi(i32 %limit, i1 %arg) nounwind {
259 ; CHECK-LABEL: @identityphi(
261 ; CHECK-NEXT: br label [[LOOP:%.*]]
263 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[CONTROL:%.*]] ]
264 ; CHECK-NEXT: br i1 [[ARG:%.*]], label [[IF_THEN:%.*]], label [[CONTROL]]
266 ; CHECK-NEXT: br label [[CONTROL]]
268 ; CHECK-NEXT: [[IV_NEXT]] = phi i32 [ [[IV]], [[LOOP]] ], [ undef, [[IF_THEN]] ]
269 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[IV_NEXT]], [[LIMIT:%.*]]
270 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP]], label [[EXIT:%.*]]
272 ; CHECK-NEXT: ret void
278 %iv = phi i32 [ 0, %entry], [ %iv.next, %control ]
279 br i1 %arg, label %if.then, label %control
285 %iv.next = phi i32 [ %iv, %loop ], [ undef, %if.then ]
286 %cmp = icmp slt i32 %iv.next, %limit
287 br i1 %cmp, label %loop, label %exit
293 ; Test cloning an or, which is not an OverflowBinaryOperator.
294 define i64 @cloneOr(i32 %limit, ptr %base) nounwind {
295 ; CHECK-LABEL: @cloneOr(
297 ; CHECK-NEXT: [[HALFLIM:%.*]] = ashr i32 [[LIMIT:%.*]], 2
298 ; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[HALFLIM]] to i64
299 ; CHECK-NEXT: br label [[LOOP:%.*]]
301 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LOOP]] ], [ 0, [[ENTRY:%.*]] ]
302 ; CHECK-NEXT: [[ADR:%.*]] = getelementptr i64, ptr [[BASE:%.*]], i64 [[INDVARS_IV]]
303 ; CHECK-NEXT: [[VAL:%.*]] = load i64, ptr [[ADR]], align 8
304 ; CHECK-NEXT: [[TMP1:%.*]] = or disjoint i64 [[INDVARS_IV]], 1
305 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 2
306 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[INDVARS_IV_NEXT]], [[TMP0]]
307 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP]], label [[EXIT:%.*]]
309 ; CHECK-NEXT: [[VAL_LCSSA:%.*]] = phi i64 [ [[VAL]], [[LOOP]] ]
310 ; CHECK-NEXT: [[T3_LCSSA:%.*]] = phi i64 [ [[TMP1]], [[LOOP]] ]
311 ; CHECK-NEXT: [[RESULT:%.*]] = and i64 [[VAL_LCSSA]], [[T3_LCSSA]]
312 ; CHECK-NEXT: ret i64 [[RESULT]]
315 ; ensure that the loop can't overflow
316 %halfLim = ashr i32 %limit, 2
320 %iv = phi i32 [ 0, %entry], [ %iv.next, %loop ]
321 %t1 = sext i32 %iv to i64
322 %adr = getelementptr i64, ptr %base, i64 %t1
323 %val = load i64, ptr %adr
324 %t2 = or disjoint i32 %iv, 1
325 %t3 = sext i32 %t2 to i64
326 %iv.next = add i32 %iv, 2
327 %cmp = icmp slt i32 %iv.next, %halfLim
328 br i1 %cmp, label %loop, label %exit
331 %result = and i64 %val, %t3
335 ; The i induction variable looks like a wrap-around, but it really is just
336 ; a simple affine IV. Make sure that indvars simplifies through.
337 ; ReplaceLoopExitValue should fold the return value to constant 9.
338 define i32 @indirectRecurrence() nounwind {
339 ; CHECK-LABEL: @indirectRecurrence(
341 ; CHECK-NEXT: br label [[LOOP:%.*]]
343 ; CHECK-NEXT: [[J_0:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[J_NEXT:%.*]], [[COND_TRUE:%.*]] ]
344 ; CHECK-NEXT: [[TMP:%.*]] = icmp ne i32 [[J_0]], 10
345 ; CHECK-NEXT: br i1 [[TMP]], label [[COND_TRUE]], label [[RETURN:%.*]]
347 ; CHECK-NEXT: [[J_NEXT]] = add nuw nsw i32 [[J_0]], 1
348 ; CHECK-NEXT: br label [[LOOP]]
350 ; CHECK-NEXT: ret i32 9
356 %j.0 = phi i32 [ 1, %entry ], [ %j.next, %cond_true ]
357 %i.0 = phi i32 [ 0, %entry ], [ %j.0, %cond_true ]
358 %tmp = icmp ne i32 %j.0, 10
359 br i1 %tmp, label %cond_true, label %return
362 %j.next = add i32 %j.0, 1
369 ; Eliminate the congruent phis j, k, and l.
370 ; Eliminate the redundant IV increments k.next and l.next.
371 ; Two phis should remain, one starting at %init, and one at %init1.
372 ; Two increments should remain, one by %step and one by %step1.
373 ; Five live-outs should remain.
374 define i32 @isomorphic(i32 %init, i32 %step, i32 %lim) nounwind {
375 ; CHECK-LABEL: @isomorphic(
377 ; CHECK-NEXT: [[STEP1:%.*]] = add i32 [[STEP:%.*]], 1
378 ; CHECK-NEXT: [[INIT1:%.*]] = add i32 [[INIT:%.*]], [[STEP1]]
379 ; CHECK-NEXT: br label [[LOOP:%.*]]
381 ; CHECK-NEXT: [[II:%.*]] = phi i32 [ [[INIT1]], [[ENTRY:%.*]] ], [ [[II_NEXT:%.*]], [[LOOP]] ]
382 ; CHECK-NEXT: [[J:%.*]] = phi i32 [ [[INIT]], [[ENTRY]] ], [ [[J_NEXT:%.*]], [[LOOP]] ]
383 ; CHECK-NEXT: [[II_NEXT]] = add i32 [[II]], [[STEP1]]
384 ; CHECK-NEXT: [[J_NEXT]] = add i32 [[J]], [[STEP1]]
385 ; CHECK-NEXT: [[L_STEP:%.*]] = add i32 [[J]], [[STEP]]
386 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[II_NEXT]], [[LIM:%.*]]
387 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP]], label [[RETURN:%.*]]
389 ; CHECK-NEXT: [[I_LCSSA:%.*]] = phi i32 [ [[J]], [[LOOP]] ]
390 ; CHECK-NEXT: [[J_NEXT_LCSSA:%.*]] = phi i32 [ [[J_NEXT]], [[LOOP]] ]
391 ; CHECK-NEXT: [[K_NEXT_LCSSA:%.*]] = phi i32 [ [[II_NEXT]], [[LOOP]] ]
392 ; CHECK-NEXT: [[L_STEP_LCSSA:%.*]] = phi i32 [ [[L_STEP]], [[LOOP]] ]
393 ; CHECK-NEXT: [[L_NEXT_LCSSA:%.*]] = phi i32 [ [[J_NEXT]], [[LOOP]] ]
394 ; CHECK-NEXT: [[SUM1:%.*]] = add i32 [[I_LCSSA]], [[J_NEXT_LCSSA]]
395 ; CHECK-NEXT: [[SUM2:%.*]] = add i32 [[SUM1]], [[K_NEXT_LCSSA]]
396 ; CHECK-NEXT: [[SUM3:%.*]] = add i32 [[SUM1]], [[L_STEP_LCSSA]]
397 ; CHECK-NEXT: [[SUM4:%.*]] = add i32 [[SUM1]], [[L_NEXT_LCSSA]]
398 ; CHECK-NEXT: ret i32 [[SUM4]]
401 %step1 = add i32 %step, 1
402 %init1 = add i32 %init, %step1
403 %l.0 = sub i32 %init1, %step1
407 %ii = phi i32 [ %init1, %entry ], [ %ii.next, %loop ]
408 %i = phi i32 [ %init, %entry ], [ %ii, %loop ]
409 %j = phi i32 [ %init, %entry ], [ %j.next, %loop ]
410 %k = phi i32 [ %init1, %entry ], [ %k.next, %loop ]
411 %l = phi i32 [ %l.0, %entry ], [ %l.next, %loop ]
412 %ii.next = add i32 %ii, %step1
413 %j.next = add i32 %j, %step1
414 %k.next = add i32 %k, %step1
415 %l.step = add i32 %l, %step
416 %l.next = add i32 %l.step, 1
417 %cmp = icmp ne i32 %ii.next, %lim
418 br i1 %cmp, label %loop, label %return
421 %sum1 = add i32 %i, %j.next
422 %sum2 = add i32 %sum1, %k.next
423 %sum3 = add i32 %sum1, %l.step
424 %sum4 = add i32 %sum1, %l.next
428 ; Test a GEP IV that is derived from another GEP IV by a nop gep that
429 ; lowers the type without changing the expression.
430 %structIF = type { i32, float }
432 define void @congruentgepiv(ptr %base, i1 %arg) nounwind uwtable ssp {
433 ; CHECK-LABEL: @congruentgepiv(
435 ; CHECK-NEXT: br label [[LOOP:%.*]]
437 ; CHECK-NEXT: store i32 4, ptr [[BASE:%.*]], align 4
438 ; CHECK-NEXT: br i1 [[ARG:%.*]], label [[LATCH:%.*]], label [[EXIT:%.*]]
440 ; CHECK-NEXT: br label [[LOOP]]
442 ; CHECK-NEXT: ret void
448 %ptr.iv = phi ptr [ %ptr.inc, %latch ], [ %base, %entry ]
449 %next = phi ptr [ %next, %latch ], [ %base, %entry ]
450 store i32 4, ptr %next
451 br i1 %arg, label %latch, label %exit
453 latch: ; preds = %for.inc50.i
454 %ptr.inc = getelementptr inbounds %structIF, ptr %ptr.iv, i64 1
461 declare void @use32(i32 %x)
462 declare void @use64(i64 %x)
464 ; Test a widened IV that is used by a phi on different paths within the loop.
465 define void @phiUsesTrunc(i1 %arg) nounwind {
466 ; CHECK-LABEL: @phiUsesTrunc(
468 ; CHECK-NEXT: br i1 [[ARG:%.*]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_END:%.*]]
469 ; CHECK: for.body.preheader:
470 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
472 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 1, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_INC:%.*]] ]
473 ; CHECK-NEXT: [[TMP0:%.*]] = trunc nuw nsw i64 [[INDVARS_IV]] to i32
474 ; CHECK-NEXT: br i1 [[ARG]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
476 ; CHECK-NEXT: br i1 [[ARG]], label [[IF_THEN33:%.*]], label [[FOR_INC]]
478 ; CHECK-NEXT: br label [[FOR_INC]]
480 ; CHECK-NEXT: br i1 [[ARG]], label [[IF_THEN97:%.*]], label [[FOR_INC]]
482 ; CHECK-NEXT: call void @use64(i64 [[INDVARS_IV]])
483 ; CHECK-NEXT: br label [[FOR_INC]]
485 ; CHECK-NEXT: [[KMIN_1:%.*]] = phi i32 [ [[TMP0]], [[IF_THEN33]] ], [ 0, [[IF_THEN]] ], [ [[TMP0]], [[IF_THEN97]] ], [ 0, [[IF_ELSE]] ]
486 ; CHECK-NEXT: call void @use32(i32 [[KMIN_1]])
487 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
488 ; CHECK-NEXT: br i1 [[ARG]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
489 ; CHECK: for.end.loopexit:
490 ; CHECK-NEXT: br label [[FOR_END]]
492 ; CHECK-NEXT: ret void
495 br i1 %arg, label %for.body, label %for.end
498 %iv = phi i32 [ %inc, %for.inc ], [ 1, %entry ]
499 br i1 %arg, label %if.then, label %if.else
502 br i1 %arg, label %if.then33, label %for.inc
508 br i1 %arg, label %if.then97, label %for.inc
511 %idxprom100 = sext i32 %iv to i64
512 call void @use64(i64 %idxprom100)
516 %kmin.1 = phi i32 [ %iv, %if.then33 ], [ 0, %if.then ], [ %iv, %if.then97 ], [ 0, %if.else ]
517 call void @use32(i32 %kmin.1)
518 %inc = add nsw i32 %iv, 1
519 br i1 %arg, label %for.body, label %for.end