@@ -4018,8 +4018,8 @@ void LoopVectorizationPlanner::emitInvalidCostRemarks(
40184018 if (VF.isScalar ())
40194019 continue ;
40204020
4021- VPCostContext CostCtx (CM.TTI , *CM.TLI , Legal-> getWidestInductionType () ,
4022- CM, CM. CostKind );
4021+ VPCostContext CostCtx (CM.TTI , *CM.TLI , *Plan, CM, CM. CostKind ,
4022+ *CM. PSE . getSE (), OrigLoop );
40234023 precomputeCosts (*Plan, VF, CostCtx);
40244024 auto Iter = vp_depth_first_deep (Plan->getVectorLoopRegion ()->getEntry ());
40254025 for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(Iter)) {
@@ -4273,8 +4273,8 @@ VectorizationFactor LoopVectorizationPlanner::selectVectorizationFactor() {
42734273
42744274 // Add on other costs that are modelled in VPlan, but not in the legacy
42754275 // cost model.
4276- VPCostContext CostCtx (CM.TTI , *CM.TLI , CM. Legal -> getWidestInductionType () ,
4277- CM, CM. CostKind );
4276+ VPCostContext CostCtx (CM.TTI , *CM.TLI , *P, CM, CM. CostKind ,
4277+ *CM. PSE . getSE (), OrigLoop );
42784278 VPRegionBlock *VectorRegion = P->getVectorLoopRegion ();
42794279 assert (VectorRegion && " Expected to have a vector region!" );
42804280 for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
@@ -6874,8 +6874,8 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
68746874
68756875InstructionCost LoopVectorizationPlanner::cost (VPlan &Plan,
68766876 ElementCount VF) const {
6877- VPCostContext CostCtx (CM.TTI , *CM.TLI , Legal-> getWidestInductionType () , CM,
6878- CM. CostKind );
6877+ VPCostContext CostCtx (CM.TTI , *CM.TLI , Plan , CM, CM. CostKind , *PSE. getSE () ,
6878+ OrigLoop );
68796879 InstructionCost Cost = precomputeCosts (Plan, VF, CostCtx);
68806880
68816881 // Now compute and add the VPlan-based cost.
@@ -7075,13 +7075,14 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() {
70757075 // simplifications not accounted for in the legacy cost model. If that's the
70767076 // case, don't trigger the assertion, as the extra simplifications may cause a
70777077 // different VF to be picked by the VPlan-based cost model.
7078- VPCostContext CostCtx (CM.TTI , *CM.TLI , Legal-> getWidestInductionType () , CM,
7079- CM.CostKind );
7078+ VPCostContext CostCtx (CM.TTI , *CM.TLI , BestPlan , CM, CM. CostKind ,
7079+ * CM.PSE . getSE (), OrigLoop );
70807080 precomputeCosts (BestPlan, BestFactor.Width , CostCtx);
70817081 // Verify that the VPlan-based and legacy cost models agree, except for VPlans
70827082 // with early exits and plans with additional VPlan simplifications. The
70837083 // legacy cost model doesn't properly model costs for such loops.
70847084 assert ((BestFactor.Width == LegacyVF.Width || BestPlan.hasEarlyExit () ||
7085+ !Legal->getLAI ()->getSymbolicStrides ().empty () ||
70857086 planContainsAdditionalSimplifications (getPlanFor (BestFactor.Width ),
70867087 CostCtx, OrigLoop,
70877088 BestFactor.Width ) ||
@@ -8337,6 +8338,8 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
83378338 std::unique_ptr<VPlan>(VPlan0->duplicate ()), SubRange, &LVer)) {
83388339 bool HasScalarVF = Plan->hasScalarVFOnly ();
83398340 // Now optimize the initial VPlan.
8341+ VPlanTransforms::hoistPredicatedLoads (*Plan, *PSE.getSE (), OrigLoop);
8342+ VPlanTransforms::sinkPredicatedStores (*Plan, *PSE.getSE (), OrigLoop);
83408343 if (!HasScalarVF)
83418344 VPlanTransforms::runPass (VPlanTransforms::truncateToMinimalBitwidths,
83428345 *Plan, CM.getMinimalBitwidths ());
@@ -8832,8 +8835,8 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
88328835 // TODO: Enable following transform when the EVL-version of extended-reduction
88338836 // and mulacc-reduction are implemented.
88348837 if (!CM.foldTailWithEVL ()) {
8835- VPCostContext CostCtx (CM.TTI , *CM.TLI , Legal-> getWidestInductionType () , CM,
8836- CM.CostKind );
8838+ VPCostContext CostCtx (CM.TTI , *CM.TLI , *Plan , CM, CM. CostKind ,
8839+ * CM.PSE . getSE (), OrigLoop );
88378840 VPlanTransforms::runPass (VPlanTransforms::convertToAbstractRecipes, *Plan,
88388841 CostCtx, Range);
88398842 }
@@ -10108,8 +10111,8 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1010810111 // Check if it is profitable to vectorize with runtime checks.
1010910112 bool ForceVectorization =
1011010113 Hints.getForce () == LoopVectorizeHints::FK_Enabled;
10111- VPCostContext CostCtx (CM.TTI , *CM.TLI , CM. Legal -> getWidestInductionType () ,
10112- CM, CM.CostKind );
10114+ VPCostContext CostCtx (CM.TTI , *CM.TLI , LVP. getPlanFor (VF. Width ), CM ,
10115+ CM. CostKind , * CM.PSE . getSE (), L );
1011310116 if (!ForceVectorization &&
1011410117 !isOutsideLoopWorkProfitable (Checks, VF, L, PSE, CostCtx,
1011510118 LVP.getPlanFor (VF.Width ), SEL,
0 commit comments