@@ -352,8 +352,10 @@ std::unique_ptr<VPlan> PlainCFGBuilder::buildPlainCFG(
352352 Plan->getEntry ()->setOneSuccessor (getOrCreateVPBB (TheLoop->getHeader ()));
353353 Plan->getEntry ()->setPlan (&*Plan);
354354
355- // Fix VPlan loop-closed-ssa exit phi's by add incoming operands to the
355+ // Fix VPlan loop-closed-ssa exit phi's by adding incoming operands to the
356356 // VPIRInstructions wrapping them.
357+ // Note that the operand order may need adjusting when predecessors are added,
358+ // if an exit block has multiple predecessor.
357359 for (auto *EB : Plan->getExitBlocks ()) {
358360 for (VPRecipeBase &R : EB->phis ()) {
359361 auto *PhiR = cast<VPIRPhi>(&R);
@@ -476,6 +478,17 @@ void VPlanTransforms::createLoopRegions(VPlan &Plan, Type *InductionTy,
476478
477479 VPBasicBlock *ScalarPH = Plan.createVPBasicBlock (" scalar.ph" );
478480 VPBlockUtils::connectBlocks (ScalarPH, Plan.getScalarHeader ());
481+
482+ // If needed, add a check in the middle block to see if we have completed
483+ // all of the iterations in the first vector loop. Three cases:
484+ // 1) If we require a scalar epilogue, there is no conditional branch as
485+ // we unconditionally branch to the scalar preheader. Remove the recipes
486+ // from the exit blocks.
487+ // 2) If (N - N%VF) == N, then we *don't* need to run the remainder.
488+ // Thus if tail is to be folded, we know we don't need to run the
489+ // remainder and we can set the condition to true.
490+ // 3) Otherwise, construct a runtime check.
491+
479492 if (!RequiresScalarEpilogueCheck) {
480493 VPBlockUtils::connectBlocks (MiddleVPBB, ScalarPH);
481494 // The exit blocks are unreachable, remove their recipes to make sure no
@@ -487,14 +500,6 @@ void VPlanTransforms::createLoopRegions(VPlan &Plan, Type *InductionTy,
487500 return ;
488501 }
489502
490- // If needed, add a check in the middle block to see if we have completed
491- // all of the iterations in the first vector loop. Three cases:
492- // 1) If (N - N%VF) == N, then we *don't* need to run the remainder.
493- // Thus if tail is to be folded, we know we don't need to run the
494- // remainder and we can set the condition to true.
495- // 2) If we require a scalar epilogue, there is no conditional branch as
496- // we unconditionally branch to the scalar preheader. Do nothing.
497- // 3) Otherwise, construct a runtime check.
498503 BasicBlock *IRExitBlock = TheLoop->getUniqueLatchExitBlock ();
499504 auto *VPExitBlock = Plan.getExitBlock (IRExitBlock);
500505 // The connection order corresponds to the operands of the conditional branch.
0 commit comments