diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp --- a/llvm/lib/Transforms/Utils/LoopPeel.cpp +++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp @@ -224,10 +224,15 @@ return Unknown; } // We need to analyze the input from the back edge and add 1. - Value *Input = Phi->getIncomingValueForBlock(L.getLoopLatch()); + const Value *Input = Phi->getIncomingValueForBlock(L.getLoopLatch()); PeelCounter Iterations = calculate(*Input); assert(IterationsToInvariance[Input] == Iterations && "unexpected value saved"); + if (const PHINode *InputI = dyn_cast(Input)) + if (Phi->getParent() == InputI->getParent() && InputI->comesBefore(Phi)) + // If the input is from a previous phi in the same block, Phi becomes + // loop invariant in the same iteration. + return (IterationsToInvariance[Phi] = Iterations); return (IterationsToInvariance[Phi] = addOne(Iterations)); } if (const Instruction *I = dyn_cast(&V)) { diff --git a/llvm/test/Transforms/LoopUnroll/peel-loop-not-forced.ll b/llvm/test/Transforms/LoopUnroll/peel-loop-not-forced.ll --- a/llvm/test/Transforms/LoopUnroll/peel-loop-not-forced.ll +++ b/llvm/test/Transforms/LoopUnroll/peel-loop-not-forced.ll @@ -69,8 +69,8 @@ } define i32 @invariant_backedge_2(i32 %a, i32 %b) { -; This loop should be peeled twice because it has a Phi which becomes invariant -; starting from 3rd iteration. +; This loop should be peeled once because it has Phis which becomes invariant +; starting from 2nd iteration. ; CHECK-LABEL: define i32 @invariant_backedge_2 ; CHECK-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) { ; CHECK-NEXT: entry: @@ -83,22 +83,16 @@ ; CHECK-NEXT: [[CMP_PEEL:%.*]] = icmp slt i32 0, 1000 ; CHECK-NEXT: br i1 [[CMP_PEEL]], label [[LOOP_PEEL_NEXT:%.*]], label [[EXIT:%.*]] ; CHECK: loop.peel.next: -; CHECK-NEXT: br label [[LOOP_PEEL2:%.*]] -; CHECK: loop.peel2: -; CHECK-NEXT: [[INCSUM_PEEL3:%.*]] = add i32 [[INCSUM_PEEL]], [[A]] -; CHECK-NEXT: [[INC_PEEL4:%.*]] = add i32 [[INC_PEEL]], 1 -; CHECK-NEXT: [[CMP_PEEL5:%.*]] = icmp slt i32 [[INC_PEEL]], 1000 -; CHECK-NEXT: br i1 [[CMP_PEEL5]], label [[LOOP_PEEL_NEXT1:%.*]], label [[EXIT]] +; CHECK-NEXT: br label [[LOOP_PEEL_NEXT1:%.*]] ; CHECK: loop.peel.next1: -; CHECK-NEXT: br label [[LOOP_PEEL_NEXT6:%.*]] -; CHECK: loop.peel.next6: ; CHECK-NEXT: br label [[ENTRY_PEEL_NEWPH:%.*]] ; CHECK: entry.peel.newph: ; CHECK-NEXT: br label [[LOOP:%.*]] ; CHECK: loop: -; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[INC_PEEL4]], [[ENTRY_PEEL_NEWPH]] ], [ [[INC:%.*]], [[LOOP]] ] -; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ [[INCSUM_PEEL3]], [[ENTRY_PEEL_NEWPH]] ], [ [[INCSUM:%.*]], [[LOOP]] ] -; CHECK-NEXT: [[INCSUM]] = add i32 [[SUM]], [[B]] +; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[INC_PEEL]], [[ENTRY_PEEL_NEWPH]] ], [ [[INC:%.*]], [[LOOP]] ] +; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ [[INCSUM_PEEL]], [[ENTRY_PEEL_NEWPH]] ], [ [[INCSUM:%.*]], [[LOOP]] ] +; CHECK-NEXT: [[PLUS:%.*]] = phi i32 [ [[A]], [[ENTRY_PEEL_NEWPH]] ], [ [[B]], [[LOOP]] ] +; CHECK-NEXT: [[INCSUM]] = add i32 [[SUM]], [[PLUS]] ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I]], 1 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[I]], 1000 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]], !llvm.loop [[LOOP2:![0-9]+]] @@ -106,7 +100,7 @@ ; CHECK-NEXT: [[SUM_LCSSA_PH:%.*]] = phi i32 [ [[SUM]], [[LOOP]] ] ; CHECK-NEXT: br label [[EXIT]] ; CHECK: exit: -; CHECK-NEXT: [[SUM_LCSSA:%.*]] = phi i32 [ 0, [[LOOP_PEEL]] ], [ [[INCSUM_PEEL]], [[LOOP_PEEL2]] ], [ [[SUM_LCSSA_PH]], [[EXIT_LOOPEXIT]] ] +; CHECK-NEXT: [[SUM_LCSSA:%.*]] = phi i32 [ 0, [[LOOP_PEEL]] ], [ [[SUM_LCSSA_PH]], [[EXIT_LOOPEXIT]] ] ; CHECK-NEXT: ret i32 [[SUM_LCSSA]] ; ; DISABLE-LABEL: define i32 @invariant_backedge_2 @@ -146,8 +140,8 @@ } define i32 @invariant_backedge_3(i32 %a, i32 %b) { -; This loop should be peeled thrice because it has a Phi which becomes invariant -; starting from 4th iteration. +; This loop should be peeled once because it has Phis which becomes invariant +; starting from 2nd iteration. ; CHECK-LABEL: define i32 @invariant_backedge_3 ; CHECK-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) { ; CHECK-NEXT: entry: @@ -160,37 +154,25 @@ ; CHECK-NEXT: [[CMP_PEEL:%.*]] = icmp slt i32 0, 1000 ; CHECK-NEXT: br i1 [[CMP_PEEL]], label [[LOOP_PEEL_NEXT:%.*]], label [[EXIT:%.*]] ; CHECK: loop.peel.next: -; CHECK-NEXT: br label [[LOOP_PEEL2:%.*]] -; CHECK: loop.peel2: -; CHECK-NEXT: [[INCSUM_PEEL3:%.*]] = add i32 [[INCSUM_PEEL]], [[A]] -; CHECK-NEXT: [[INC_PEEL4:%.*]] = add i32 [[INC_PEEL]], 1 -; CHECK-NEXT: [[CMP_PEEL5:%.*]] = icmp slt i32 [[INC_PEEL]], 1000 -; CHECK-NEXT: br i1 [[CMP_PEEL5]], label [[LOOP_PEEL_NEXT1:%.*]], label [[EXIT]] +; CHECK-NEXT: br label [[LOOP_PEEL_NEXT1:%.*]] ; CHECK: loop.peel.next1: -; CHECK-NEXT: br label [[LOOP_PEEL7:%.*]] -; CHECK: loop.peel7: -; CHECK-NEXT: [[INCSUM_PEEL8:%.*]] = add i32 [[INCSUM_PEEL3]], [[A]] -; CHECK-NEXT: [[INC_PEEL9:%.*]] = add i32 [[INC_PEEL4]], 1 -; CHECK-NEXT: [[CMP_PEEL10:%.*]] = icmp slt i32 [[INC_PEEL4]], 1000 -; CHECK-NEXT: br i1 [[CMP_PEEL10]], label [[LOOP_PEEL_NEXT6:%.*]], label [[EXIT]] -; CHECK: loop.peel.next6: -; CHECK-NEXT: br label [[LOOP_PEEL_NEXT11:%.*]] -; CHECK: loop.peel.next11: ; CHECK-NEXT: br label [[ENTRY_PEEL_NEWPH:%.*]] ; CHECK: entry.peel.newph: ; CHECK-NEXT: br label [[LOOP:%.*]] ; CHECK: loop: -; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[INC_PEEL9]], [[ENTRY_PEEL_NEWPH]] ], [ [[INC:%.*]], [[LOOP]] ] -; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ [[INCSUM_PEEL8]], [[ENTRY_PEEL_NEWPH]] ], [ [[INCSUM:%.*]], [[LOOP]] ] -; CHECK-NEXT: [[INCSUM]] = add i32 [[SUM]], [[B]] +; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[INC_PEEL]], [[ENTRY_PEEL_NEWPH]] ], [ [[INC:%.*]], [[LOOP]] ] +; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ [[INCSUM_PEEL]], [[ENTRY_PEEL_NEWPH]] ], [ [[INCSUM:%.*]], [[LOOP]] ] +; CHECK-NEXT: [[HALF_INV_2:%.*]] = phi i32 [ [[A]], [[ENTRY_PEEL_NEWPH]] ], [ [[B]], [[LOOP]] ] +; CHECK-NEXT: [[PLUS:%.*]] = phi i32 [ [[A]], [[ENTRY_PEEL_NEWPH]] ], [ [[HALF_INV_2]], [[LOOP]] ] +; CHECK-NEXT: [[INCSUM]] = add i32 [[SUM]], [[PLUS]] ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I]], 1 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[I]], 1000 -; CHECK-NEXT: br i1 [[CMP]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]], !llvm.loop [[LOOP4:![0-9]+]] +; CHECK-NEXT: br i1 [[CMP]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]], !llvm.loop [[LOOP3:![0-9]+]] ; CHECK: exit.loopexit: ; CHECK-NEXT: [[SUM_LCSSA_PH:%.*]] = phi i32 [ [[SUM]], [[LOOP]] ] ; CHECK-NEXT: br label [[EXIT]] ; CHECK: exit: -; CHECK-NEXT: [[SUM_LCSSA:%.*]] = phi i32 [ 0, [[LOOP_PEEL]] ], [ [[INCSUM_PEEL]], [[LOOP_PEEL2]] ], [ [[INCSUM_PEEL3]], [[LOOP_PEEL7]] ], [ [[SUM_LCSSA_PH]], [[EXIT_LOOPEXIT]] ] +; CHECK-NEXT: [[SUM_LCSSA:%.*]] = phi i32 [ 0, [[LOOP_PEEL]] ], [ [[SUM_LCSSA_PH]], [[EXIT_LOOPEXIT]] ] ; CHECK-NEXT: ret i32 [[SUM_LCSSA]] ; ; DISABLE-LABEL: define i32 @invariant_backedge_3 @@ -247,25 +229,24 @@ ; CHECK-NEXT: [[INCSUM_PEEL:%.*]] = add i32 0, [[A]] ; CHECK-NEXT: [[INC_PEEL:%.*]] = add i32 0, 1 ; CHECK-NEXT: [[CMP_PEEL:%.*]] = icmp slt i32 0, 1000 +; CHECK-NEXT: [[PHIBACKEDGE1_PEEL:%.*]] = add i32 [[A]], 1 +; CHECK-NEXT: [[PHIBACKEDGE2_PEEL:%.*]] = add i32 [[A]], 1 ; CHECK-NEXT: [[INCSUM2_PEEL:%.*]] = add i32 [[INCSUM_PEEL]], [[A]] ; CHECK-NEXT: [[INCSUM3_PEEL:%.*]] = add i32 [[INCSUM_PEEL]], [[A]] ; CHECK-NEXT: [[INCSUM4_PEEL:%.*]] = add i32 [[INCSUM_PEEL]], [[A]] ; CHECK-NEXT: [[INCSUM5_PEEL:%.*]] = add i32 [[INCSUM_PEEL]], [[A]] -; CHECK-NEXT: [[INCSUM6_PEEL:%.*]] = add i32 [[INCSUM_PEEL]], [[A]] -; CHECK-NEXT: [[INCSUM7_PEEL:%.*]] = add i32 [[INCSUM_PEEL]], [[A]] ; CHECK-NEXT: br i1 [[CMP_PEEL]], label [[LOOP_PEEL_NEXT:%.*]], label [[EXIT:%.*]] ; CHECK: loop.peel.next: ; CHECK-NEXT: br label [[LOOP_PEEL2:%.*]] ; CHECK: loop.peel2: -; CHECK-NEXT: [[INCSUM_PEEL3:%.*]] = add i32 [[INCSUM_PEEL]], [[A]] +; CHECK-NEXT: [[INCSUM_PEEL3:%.*]] = add i32 [[INCSUM_PEEL]], [[PHIBACKEDGE2_PEEL]] ; CHECK-NEXT: [[INC_PEEL4:%.*]] = add i32 [[INC_PEEL]], 1 ; CHECK-NEXT: [[CMP_PEEL5:%.*]] = icmp slt i32 [[INC_PEEL]], 1000 -; CHECK-NEXT: [[INCSUM2_PEEL6:%.*]] = add i32 [[INCSUM_PEEL3]], [[A]] -; CHECK-NEXT: [[INCSUM3_PEEL7:%.*]] = add i32 [[INCSUM_PEEL3]], [[A]] -; CHECK-NEXT: [[INCSUM4_PEEL8:%.*]] = add i32 [[INCSUM_PEEL3]], [[A]] -; CHECK-NEXT: [[INCSUM5_PEEL9:%.*]] = add i32 [[INCSUM_PEEL3]], [[A]] -; CHECK-NEXT: [[INCSUM6_PEEL10:%.*]] = add i32 [[INCSUM_PEEL3]], [[A]] -; CHECK-NEXT: [[INCSUM7_PEEL11:%.*]] = add i32 [[INCSUM_PEEL3]], [[A]] +; CHECK-NEXT: [[PHIBACKEDGE2_PEEL7:%.*]] = add i32 [[B]], 1 +; CHECK-NEXT: [[INCSUM2_PEEL8:%.*]] = add i32 [[INCSUM_PEEL3]], [[PHIBACKEDGE2_PEEL]] +; CHECK-NEXT: [[INCSUM3_PEEL9:%.*]] = add i32 [[INCSUM_PEEL3]], [[PHIBACKEDGE2_PEEL]] +; CHECK-NEXT: [[INCSUM4_PEEL10:%.*]] = add i32 [[INCSUM_PEEL3]], [[PHIBACKEDGE2_PEEL]] +; CHECK-NEXT: [[INCSUM5_PEEL11:%.*]] = add i32 [[INCSUM_PEEL3]], [[PHIBACKEDGE2_PEEL]] ; CHECK-NEXT: br i1 [[CMP_PEEL5]], label [[LOOP_PEEL_NEXT1:%.*]], label [[EXIT]] ; CHECK: loop.peel.next1: ; CHECK-NEXT: br label [[LOOP_PEEL_NEXT12:%.*]] @@ -276,11 +257,12 @@ ; CHECK: loop: ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[INC_PEEL4]], [[ENTRY_PEEL_NEWPH]] ], [ [[INC:%.*]], [[LOOP]] ] ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ [[INCSUM_PEEL3]], [[ENTRY_PEEL_NEWPH]] ], [ [[INCSUM:%.*]], [[LOOP]] ] -; CHECK-NEXT: [[PLUS:%.*]] = phi i32 [ [[A]], [[ENTRY_PEEL_NEWPH]] ], [ [[B]], [[LOOP]] ] +; CHECK-NEXT: [[PLUS:%.*]] = phi i32 [ [[PHIBACKEDGE2_PEEL7]], [[ENTRY_PEEL_NEWPH]] ], [ [[PHIBACKEDGE2:%.*]], [[LOOP]] ] ; CHECK-NEXT: [[INCSUM]] = add i32 [[SUM]], [[PLUS]] ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I]], 1 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[I]], 1000 -; CHECK-NEXT: br i1 [[CMP]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]], !llvm.loop [[LOOP6:![0-9]+]] +; CHECK-NEXT: [[PHIBACKEDGE2]] = add i32 [[B]], 1 +; CHECK-NEXT: br i1 [[CMP]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]], !llvm.loop [[LOOP4:![0-9]+]] ; CHECK: exit.loopexit: ; CHECK-NEXT: [[SUM_LCSSA_PH:%.*]] = phi i32 [ [[SUM]], [[LOOP]] ] ; CHECK-NEXT: br label [[EXIT]] @@ -296,17 +278,17 @@ ; DISABLE-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[LOOP]] ] ; DISABLE-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[INCSUM:%.*]], [[LOOP]] ] ; DISABLE-NEXT: [[HALF_INV:%.*]] = phi i32 [ [[A]], [[ENTRY]] ], [ [[B]], [[LOOP]] ] -; DISABLE-NEXT: [[HALF_INV_2:%.*]] = phi i32 [ [[A]], [[ENTRY]] ], [ [[HALF_INV]], [[LOOP]] ] -; DISABLE-NEXT: [[PLUS:%.*]] = phi i32 [ [[A]], [[ENTRY]] ], [ [[HALF_INV_2]], [[LOOP]] ] +; DISABLE-NEXT: [[HALF_INV_2:%.*]] = phi i32 [ [[A]], [[ENTRY]] ], [ [[PHIBACKEDGE1:%.*]], [[LOOP]] ] +; DISABLE-NEXT: [[PLUS:%.*]] = phi i32 [ [[A]], [[ENTRY]] ], [ [[PHIBACKEDGE2:%.*]], [[LOOP]] ] ; DISABLE-NEXT: [[INCSUM]] = add i32 [[SUM]], [[PLUS]] ; DISABLE-NEXT: [[INC]] = add i32 [[I]], 1 ; DISABLE-NEXT: [[CMP:%.*]] = icmp slt i32 [[I]], 1000 +; DISABLE-NEXT: [[PHIBACKEDGE1]] = add i32 [[HALF_INV]], 1 +; DISABLE-NEXT: [[PHIBACKEDGE2]] = add i32 [[HALF_INV]], 1 ; DISABLE-NEXT: [[INCSUM2:%.*]] = add i32 [[INCSUM]], [[PLUS]] ; DISABLE-NEXT: [[INCSUM3:%.*]] = add i32 [[INCSUM]], [[PLUS]] ; DISABLE-NEXT: [[INCSUM4:%.*]] = add i32 [[INCSUM]], [[PLUS]] ; DISABLE-NEXT: [[INCSUM5:%.*]] = add i32 [[INCSUM]], [[PLUS]] -; DISABLE-NEXT: [[INCSUM6:%.*]] = add i32 [[INCSUM]], [[PLUS]] -; DISABLE-NEXT: [[INCSUM7:%.*]] = add i32 [[INCSUM]], [[PLUS]] ; DISABLE-NEXT: br i1 [[CMP]], label [[LOOP]], label [[EXIT:%.*]] ; DISABLE: exit: ; DISABLE-NEXT: [[SUM_LCSSA:%.*]] = phi i32 [ [[SUM]], [[LOOP]] ] @@ -319,19 +301,20 @@ %i = phi i32 [ 0, %entry ], [ %inc, %loop ] %sum = phi i32 [ 0, %entry ], [ %incsum, %loop ] %half.inv = phi i32 [ %a, %entry ], [ %b, %loop ] - %half.inv.2 = phi i32 [ %a, %entry ], [ %half.inv, %loop ] - %plus = phi i32 [ %a, %entry ], [ %half.inv.2, %loop ] + %half.inv.2 = phi i32 [ %a, %entry ], [ %phibackedge1, %loop ] + %plus = phi i32 [ %a, %entry ], [ %phibackedge2, %loop ] %incsum = add i32 %sum, %plus %inc = add i32 %i, 1 %cmp = icmp slt i32 %i, 1000 + %phibackedge1 = add i32 %half.inv, 1 + %phibackedge2 = add i32 %half.inv, 1 + %incsum2 = add i32 %incsum, %plus %incsum3 = add i32 %incsum, %plus %incsum4 = add i32 %incsum, %plus %incsum5 = add i32 %incsum, %plus - %incsum6 = add i32 %incsum, %plus - %incsum7 = add i32 %incsum, %plus br i1 %cmp, label %loop, label %exit diff --git a/llvm/test/Transforms/LoopUnroll/peel-loop-phi-analysis.ll b/llvm/test/Transforms/LoopUnroll/peel-loop-phi-analysis.ll --- a/llvm/test/Transforms/LoopUnroll/peel-loop-phi-analysis.ll +++ b/llvm/test/Transforms/LoopUnroll/peel-loop-phi-analysis.ll @@ -60,17 +60,8 @@ ; CHECK-NEXT: [[EXITCOND_PEEL5:%.*]] = icmp ne i32 [[INC_PEEL4]], 100000 ; CHECK-NEXT: br i1 [[EXITCOND_PEEL5]], label [[FOR_BODY_PEEL_NEXT1:%.*]], label [[FOR_COND_CLEANUP]] ; CHECK: for.body.peel.next1: -; CHECK-NEXT: br label [[FOR_BODY_PEEL7:%.*]] -; CHECK: for.body.peel7: -; CHECK-NEXT: tail call void @_Z1gi(i32 noundef signext [[CONV_PEEL3]]) -; CHECK-NEXT: [[CONV_PEEL8:%.*]] = fptosi float 5.000000e+00 to i32 -; CHECK-NEXT: tail call void @_Z1ff(float noundef 5.000000e+00) -; CHECK-NEXT: [[INC_PEEL9:%.*]] = add nuw nsw i32 [[INC_PEEL4]], 1 -; CHECK-NEXT: [[EXITCOND_PEEL10:%.*]] = icmp ne i32 [[INC_PEEL9]], 100000 -; CHECK-NEXT: br i1 [[EXITCOND_PEEL10]], label [[FOR_BODY_PEEL_NEXT6:%.*]], label [[FOR_COND_CLEANUP]] +; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT6:%.*]] ; CHECK: for.body.peel.next6: -; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT11:%.*]] -; CHECK: for.body.peel.next11: ; CHECK-NEXT: br label [[ENTRY_PEEL_NEWPH:%.*]] ; CHECK: entry.peel.newph: ; CHECK-NEXT: br label [[FOR_BODY:%.*]] @@ -79,8 +70,8 @@ ; CHECK: for.cond.cleanup: ; CHECK-NEXT: ret void ; CHECK: for.body: -; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[INC_PEEL9]], [[ENTRY_PEEL_NEWPH]] ], [ [[INC:%.*]], [[FOR_BODY]] ] -; CHECK-NEXT: [[X:%.*]] = phi i32 [ [[CONV_PEEL8]], [[ENTRY_PEEL_NEWPH]] ], [ 5, [[FOR_BODY]] ] +; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[INC_PEEL4]], [[ENTRY_PEEL_NEWPH]] ], [ [[INC:%.*]], [[FOR_BODY]] ] +; CHECK-NEXT: [[X:%.*]] = phi i32 [ [[CONV_PEEL3]], [[ENTRY_PEEL_NEWPH]] ], [ 5, [[FOR_BODY]] ] ; CHECK-NEXT: tail call void @_Z1gi(i32 noundef signext [[X]]) ; CHECK-NEXT: tail call void @_Z1ff(float noundef 5.000000e+00) ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I]], 1 @@ -150,20 +141,13 @@ ; CHECK: for.body.peel2: ; CHECK-NEXT: tail call void @_Z1gi(i32 signext 0) ; CHECK-NEXT: tail call void @_Z1gi(i32 signext 5) +; CHECK-NEXT: [[ADD_PEEL3:%.*]] = add nuw nsw i32 5, 1 ; CHECK-NEXT: [[INC_PEEL4:%.*]] = add nuw nsw i32 [[INC_PEEL]], 1 ; CHECK-NEXT: [[EXITCOND_PEEL5:%.*]] = icmp eq i32 [[INC_PEEL4]], 100000 ; CHECK-NEXT: br i1 [[EXITCOND_PEEL5]], label [[FOR_COND_CLEANUP]], label [[FOR_BODY_PEEL_NEXT1:%.*]] ; CHECK: for.body.peel.next1: -; CHECK-NEXT: br label [[FOR_BODY_PEEL7:%.*]] -; CHECK: for.body.peel7: -; CHECK-NEXT: tail call void @_Z1gi(i32 signext [[ADD_PEEL]]) -; CHECK-NEXT: tail call void @_Z1gi(i32 signext 5) -; CHECK-NEXT: [[INC_PEEL9:%.*]] = add nuw nsw i32 [[INC_PEEL4]], 1 -; CHECK-NEXT: [[EXITCOND_PEEL10:%.*]] = icmp eq i32 [[INC_PEEL9]], 100000 -; CHECK-NEXT: br i1 [[EXITCOND_PEEL10]], label [[FOR_COND_CLEANUP]], label [[FOR_BODY_PEEL_NEXT6:%.*]] +; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT6:%.*]] ; CHECK: for.body.peel.next6: -; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT11:%.*]] -; CHECK: for.body.peel.next11: ; CHECK-NEXT: br label [[ENTRY_PEEL_NEWPH:%.*]] ; CHECK: entry.peel.newph: ; CHECK-NEXT: br label [[FOR_BODY:%.*]] @@ -172,8 +156,10 @@ ; CHECK: for.cond.cleanup: ; CHECK-NEXT: ret void ; CHECK: for.body: -; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[INC_PEEL9]], [[ENTRY_PEEL_NEWPH]] ], [ [[INC:%.*]], [[FOR_BODY]] ] -; CHECK-NEXT: tail call void @_Z1gi(i32 signext 6) +; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[INC_PEEL4]], [[ENTRY_PEEL_NEWPH]] ], [ [[INC:%.*]], [[FOR_BODY]] ] +; CHECK-NEXT: [[Y:%.*]] = phi i32 [ [[ADD_PEEL3]], [[ENTRY_PEEL_NEWPH]] ], [ 6, [[FOR_BODY]] ] +; CHECK-NEXT: [[X:%.*]] = phi i32 [ [[ADD_PEEL]], [[ENTRY_PEEL_NEWPH]] ], [ [[Y]], [[FOR_BODY]] ] +; CHECK-NEXT: tail call void @_Z1gi(i32 signext [[X]]) ; CHECK-NEXT: tail call void @_Z1gi(i32 signext 5) ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I]], 1 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], 100000