@@ -7306,6 +7306,16 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
73067306 VPlanTransforms::materializeVFAndVFxUF (BestVPlan, VectorPH, BestVF);
73077307 VPlanTransforms::simplifyRecipes (BestVPlan);
73087308
7309+ // 0. Generate SCEV-dependent code in the entry, including TripCount, before
7310+ // making any changes to the CFG.
7311+ DenseMap<const SCEV *, Value *> ExpandedSCEVs =
7312+ VPlanTransforms::expandSCEVs (BestVPlan, *PSE.getSE ());
7313+ if (!ILV.getTripCount ())
7314+ ILV.setTripCount (BestVPlan.getTripCount ()->getLiveInIRValue ());
7315+ else
7316+ assert (VectorizingEpilogue && " should only re-use the existing trip "
7317+ " count during epilogue vectorization" );
7318+
73097319 // Perform the actual loop transformation.
73107320 VPTransformState State (&TTI, BestVF, LI, DT, ILV.AC , ILV.Builder , &BestVPlan,
73117321 OrigLoop->getParentLoop (),
@@ -7315,30 +7325,6 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
73157325 assert (DT->verify (DominatorTree::VerificationLevel::Fast));
73167326#endif
73177327
7318- // 0. Generate SCEV-dependent code in the entry, including TripCount, before
7319- // making any changes to the CFG.
7320- DenseMap<const SCEV *, Value *> ExpandedSCEVs;
7321- auto *Entry = cast<VPIRBasicBlock>(BestVPlan.getEntry ());
7322- State.Builder .SetInsertPoint (Entry->getIRBasicBlock ()->getTerminator ());
7323- for (VPRecipeBase &R : make_early_inc_range (*Entry)) {
7324- auto *ExpSCEV = dyn_cast<VPExpandSCEVRecipe>(&R);
7325- if (!ExpSCEV)
7326- continue ;
7327- ExpSCEV->execute (State);
7328- ExpandedSCEVs[ExpSCEV->getSCEV ()] = State.get (ExpSCEV, VPLane (0 ));
7329- VPValue *Exp = BestVPlan.getOrAddLiveIn (ExpandedSCEVs[ExpSCEV->getSCEV ()]);
7330- ExpSCEV->replaceAllUsesWith (Exp);
7331- if (BestVPlan.getTripCount () == ExpSCEV)
7332- BestVPlan.resetTripCount (Exp);
7333- ExpSCEV->eraseFromParent ();
7334- }
7335-
7336- if (!ILV.getTripCount ())
7337- ILV.setTripCount (State.get (BestVPlan.getTripCount (), VPLane (0 )));
7338- else
7339- assert (VectorizingEpilogue && " should only re-use the existing trip "
7340- " count during epilogue vectorization" );
7341-
73427328 // 1. Set up the skeleton for vectorization, including vector pre-header and
73437329 // middle block. The vector loop is created during VPlan execution.
73447330 BasicBlock *EntryBB =
@@ -7776,7 +7762,7 @@ createWidenInductionRecipes(PHINode *Phi, Instruction *PhiOrTrunc,
77767762 " step must be loop invariant" );
77777763
77787764 VPValue *Step =
7779- vputils::getOrCreateVPValueForSCEVExpr (Plan, IndDesc.getStep (), SE );
7765+ vputils::getOrCreateVPValueForSCEVExpr (Plan, IndDesc.getStep ());
77807766 if (auto *TruncI = dyn_cast<TruncInst>(PhiOrTrunc)) {
77817767 return new VPWidenIntOrFpInductionRecipe (Phi, Start, Step, &Plan.getVF (),
77827768 IndDesc, TruncI,
@@ -7798,8 +7784,7 @@ VPHeaderPHIRecipe *VPRecipeBuilder::tryToOptimizeInductionPHI(
77987784
77997785 // Check if this is pointer induction. If so, build the recipe for it.
78007786 if (auto *II = Legal->getPointerInductionDescriptor (Phi)) {
7801- VPValue *Step = vputils::getOrCreateVPValueForSCEVExpr (Plan, II->getStep (),
7802- *PSE.getSE ());
7787+ VPValue *Step = vputils::getOrCreateVPValueForSCEVExpr (Plan, II->getStep ());
78037788 return new VPWidenPointerInductionRecipe (
78047789 Phi, Operands[0 ], Step, &Plan.getVFxUF (), *II,
78057790 LoopVectorizationPlanner::getDecisionAndClampRange (
@@ -8957,7 +8942,7 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
89578942 [this ](PHINode *P) {
89588943 return Legal->getIntOrFpInductionDescriptor (P);
89598944 },
8960- *PSE. getSE (), * TLI))
8945+ *TLI))
89618946 return nullptr ;
89628947
89638948 // Collect mapping of IR header phis to header phi recipes, to be used in
0 commit comments