@@ -9521,55 +9521,52 @@ static SmallVector<Instruction *> preparePlanForEpilogueVectorLoop(
9521
9521
VPBasicBlock *Header = VectorLoop->getEntryBasicBlock ();
9522
9522
Header->setName (" vec.epilog.vector.body" );
9523
9523
9524
- DenseMap<Value *, Value *> ToFrozen;
9525
- SmallVector<Instruction *> InstsToMove;
9526
9524
// Ensure that the start values for all header phi recipes are updated before
9527
9525
// vectorizing the epilogue loop.
9528
- for (VPRecipeBase &R : Header->phis ()) {
9529
- if (auto *IV = dyn_cast<VPCanonicalIVPHIRecipe>(&R)) {
9530
- // When vectorizing the epilogue loop, the canonical induction start
9531
- // value needs to be changed from zero to the value after the main
9532
- // vector loop. Find the resume value created during execution of the main
9533
- // VPlan. It must be the first phi in the loop preheader.
9534
- // FIXME: Improve modeling for canonical IV start values in the epilogue
9535
- // loop.
9536
- using namespace llvm ::PatternMatch;
9537
- PHINode *EPResumeVal = &*L->getLoopPreheader ()->phis ().begin ();
9538
- for (Value *Inc : EPResumeVal->incoming_values ()) {
9539
- if (match (Inc, m_SpecificInt (0 )))
9540
- continue ;
9541
- assert (!EPI.VectorTripCount &&
9542
- " Must only have a single non-zero incoming value" );
9543
- EPI.VectorTripCount = Inc;
9544
- }
9545
- // If we didn't find a non-zero vector trip count, all incoming values
9546
- // must be zero, which also means the vector trip count is zero. Pick the
9547
- // first zero as vector trip count.
9548
- // TODO: We should not choose VF * UF so the main vector loop is known to
9549
- // be dead.
9550
- if (!EPI.VectorTripCount ) {
9551
- assert (
9552
- EPResumeVal->getNumIncomingValues () > 0 &&
9553
- all_of (EPResumeVal->incoming_values (),
9554
- [](Value *Inc) { return match (Inc, m_SpecificInt (0 )); }) &&
9555
- " all incoming values must be 0" );
9556
- EPI.VectorTripCount = EPResumeVal->getOperand (0 );
9557
- }
9558
- VPValue *VPV = Plan.getOrAddLiveIn (EPResumeVal);
9559
- assert (all_of (IV->users (),
9560
- [](const VPUser *U) {
9561
- return isa<VPScalarIVStepsRecipe>(U) ||
9562
- isa<VPDerivedIVRecipe>(U) ||
9563
- cast<VPRecipeBase>(U)->isScalarCast () ||
9564
- cast<VPInstruction>(U)->getOpcode () ==
9565
- Instruction::Add;
9566
- }) &&
9567
- " the canonical IV should only be used by its increment or "
9568
- " ScalarIVSteps when resetting the start value" );
9569
- IV->setOperand (0 , VPV);
9526
+ VPCanonicalIVPHIRecipe *IV = Plan.getCanonicalIV ();
9527
+ // When vectorizing the epilogue loop, the canonical induction start
9528
+ // value needs to be changed from zero to the value after the main
9529
+ // vector loop. Find the resume value created during execution of the main
9530
+ // VPlan. It must be the first phi in the loop preheader.
9531
+ // FIXME: Improve modeling for canonical IV start values in the epilogue
9532
+ // loop.
9533
+ using namespace llvm ::PatternMatch;
9534
+ PHINode *EPResumeVal = &*L->getLoopPreheader ()->phis ().begin ();
9535
+ for (Value *Inc : EPResumeVal->incoming_values ()) {
9536
+ if (match (Inc, m_SpecificInt (0 )))
9570
9537
continue ;
9571
- }
9538
+ assert (!EPI.VectorTripCount &&
9539
+ " Must only have a single non-zero incoming value" );
9540
+ EPI.VectorTripCount = Inc;
9541
+ }
9542
+ // If we didn't find a non-zero vector trip count, all incoming values
9543
+ // must be zero, which also means the vector trip count is zero. Pick the
9544
+ // first zero as vector trip count.
9545
+ // TODO: We should not choose VF * UF so the main vector loop is known to
9546
+ // be dead.
9547
+ if (!EPI.VectorTripCount ) {
9548
+ assert (EPResumeVal->getNumIncomingValues () > 0 &&
9549
+ all_of (EPResumeVal->incoming_values (),
9550
+ [](Value *Inc) { return match (Inc, m_SpecificInt (0 )); }) &&
9551
+ " all incoming values must be 0" );
9552
+ EPI.VectorTripCount = EPResumeVal->getOperand (0 );
9553
+ }
9554
+ VPValue *VPV = Plan.getOrAddLiveIn (EPResumeVal);
9555
+ assert (all_of (IV->users (),
9556
+ [](const VPUser *U) {
9557
+ return isa<VPScalarIVStepsRecipe>(U) ||
9558
+ isa<VPDerivedIVRecipe>(U) ||
9559
+ cast<VPRecipeBase>(U)->isScalarCast () ||
9560
+ cast<VPInstruction>(U)->getOpcode () ==
9561
+ Instruction::Add;
9562
+ }) &&
9563
+ " the canonical IV should only be used by its increment or "
9564
+ " ScalarIVSteps when resetting the start value" );
9565
+ IV->setOperand (0 , VPV);
9572
9566
9567
+ DenseMap<Value *, Value *> ToFrozen;
9568
+ SmallVector<Instruction *> InstsToMove;
9569
+ for (VPRecipeBase &R : drop_begin (Header->phis ())) {
9573
9570
Value *ResumeV = nullptr ;
9574
9571
// TODO: Move setting of resume values to prepareToExecute.
9575
9572
if (auto *ReductionPhi = dyn_cast<VPReductionPHIRecipe>(&R)) {
0 commit comments