@@ -467,11 +467,12 @@ class InnerLoopVectorizer {
467467 ElementCount MinProfitableTripCount,
468468 unsigned UnrollFactor, LoopVectorizationLegality *LVL,
469469 LoopVectorizationCostModel *CM, BlockFrequencyInfo *BFI,
470- ProfileSummaryInfo *PSI, GeneratedRTChecks &RTChecks)
470+ ProfileSummaryInfo *PSI, GeneratedRTChecks &RTChecks,
471+ VPlan &Plan)
471472 : OrigLoop(OrigLoop), PSE(PSE), LI(LI), DT(DT), TLI(TLI), TTI(TTI),
472473 AC (AC), ORE(ORE), VF(VecWidth), UF(UnrollFactor),
473474 Builder(PSE.getSE()->getContext()), Legal(LVL), Cost(CM), BFI(BFI),
474- PSI(PSI), RTChecks(RTChecks) {
475+ PSI(PSI), RTChecks(RTChecks), Plan(Plan) {
475476 // Query this against the original loop and save it here because the profile
476477 // of the original loop header may change as the transformation happens.
477478 OptForSizeBasedOnProfile = llvm::shouldOptimizeForSize (
@@ -498,7 +499,7 @@ class InnerLoopVectorizer {
498499 createVectorizedLoopSkeleton (const SCEV2ValueTy &ExpandedSCEVs);
499500
500501 // / Fix the vectorized code, taking care of header phi's, live-outs, and more.
501- void fixVectorizedLoop (VPTransformState &State, VPlan &Plan );
502+ void fixVectorizedLoop (VPTransformState &State);
502503
503504 // Return true if any runtime check is added.
504505 bool areSafetyChecksAdded () { return AddedSafetyChecks; }
@@ -513,7 +514,7 @@ class InnerLoopVectorizer {
513514 VPTransformState &State);
514515
515516 // / Fix the non-induction PHIs in \p Plan.
516- void fixNonInductionPHIs (VPlan &Plan, VPTransformState &State);
517+ void fixNonInductionPHIs (VPTransformState &State);
517518
518519 // / Create a new phi node for the induction variable \p OrigPhi to resume
519520 // / iteration count in the scalar epilogue, from where the vectorized loop
@@ -541,8 +542,7 @@ class InnerLoopVectorizer {
541542 // / Set up the values of the IVs correctly when exiting the vector loop.
542543 virtual void fixupIVUsers (PHINode *OrigPhi, const InductionDescriptor &II,
543544 Value *VectorTripCount, Value *EndValue,
544- BasicBlock *MiddleBlock, VPlan &Plan,
545- VPTransformState &State);
545+ BasicBlock *MiddleBlock, VPTransformState &State);
546546
547547 // / Iteratively sink the scalarized operands of a predicated instruction into
548548 // / the block that was created for it.
@@ -674,6 +674,8 @@ class InnerLoopVectorizer {
674674 // / Structure to hold information about generated runtime checks, responsible
675675 // / for cleaning the checks, if vectorization turns out unprofitable.
676676 GeneratedRTChecks &RTChecks;
677+
678+ VPlan &Plan;
677679};
678680
679681// / Encapsulate information regarding vectorization of a loop and its epilogue.
@@ -715,10 +717,10 @@ class InnerLoopAndEpilogueVectorizer : public InnerLoopVectorizer {
715717 OptimizationRemarkEmitter *ORE, EpilogueLoopVectorizationInfo &EPI,
716718 LoopVectorizationLegality *LVL, llvm::LoopVectorizationCostModel *CM,
717719 BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI,
718- GeneratedRTChecks &Checks)
720+ GeneratedRTChecks &Checks, VPlan &Plan )
719721 : InnerLoopVectorizer(OrigLoop, PSE, LI, DT, TLI, TTI, AC, ORE,
720722 EPI.MainLoopVF, EPI.MainLoopVF, EPI.MainLoopUF, LVL,
721- CM, BFI, PSI, Checks),
723+ CM, BFI, PSI, Checks, Plan ),
722724 EPI (EPI) {}
723725
724726 // Override this function to handle the more complex control flow around the
@@ -755,9 +757,9 @@ class EpilogueVectorizerMainLoop : public InnerLoopAndEpilogueVectorizer {
755757 OptimizationRemarkEmitter *ORE, EpilogueLoopVectorizationInfo &EPI,
756758 LoopVectorizationLegality *LVL, llvm::LoopVectorizationCostModel *CM,
757759 BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI,
758- GeneratedRTChecks &Check)
760+ GeneratedRTChecks &Check, VPlan &Plan )
759761 : InnerLoopAndEpilogueVectorizer(OrigLoop, PSE, LI, DT, TLI, TTI, AC, ORE,
760- EPI, LVL, CM, BFI, PSI, Check) {}
762+ EPI, LVL, CM, BFI, PSI, Check, Plan ) {}
761763 // / Implements the interface for creating a vectorized skeleton using the
762764 // / *main loop* strategy (ie the first pass of vplan execution).
763765 std::pair<BasicBlock *, Value *>
@@ -773,7 +775,7 @@ class EpilogueVectorizerMainLoop : public InnerLoopAndEpilogueVectorizer {
773775
774776 void fixupIVUsers (PHINode *OrigPhi, const InductionDescriptor &II,
775777 Value *VectorTripCount, Value *EndValue,
776- BasicBlock *MiddleBlock, VPlan &Plan,
778+ BasicBlock *MiddleBlock,
777779 VPTransformState &State) override {};
778780};
779781
@@ -789,9 +791,9 @@ class EpilogueVectorizerEpilogueLoop : public InnerLoopAndEpilogueVectorizer {
789791 OptimizationRemarkEmitter *ORE, EpilogueLoopVectorizationInfo &EPI,
790792 LoopVectorizationLegality *LVL, llvm::LoopVectorizationCostModel *CM,
791793 BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI,
792- GeneratedRTChecks &Checks)
794+ GeneratedRTChecks &Checks, VPlan &Plan )
793795 : InnerLoopAndEpilogueVectorizer(OrigLoop, PSE, LI, DT, TLI, TTI, AC, ORE,
794- EPI, LVL, CM, BFI, PSI, Checks) {
796+ EPI, LVL, CM, BFI, PSI, Checks, Plan ) {
795797 TripCount = EPI.TripCount ;
796798 }
797799 // / Implements the interface for creating a vectorized skeleton using the
@@ -2751,7 +2753,7 @@ InnerLoopVectorizer::createVectorizedLoopSkeleton(
27512753void InnerLoopVectorizer::fixupIVUsers (PHINode *OrigPhi,
27522754 const InductionDescriptor &II,
27532755 Value *VectorTripCount, Value *EndValue,
2754- BasicBlock *MiddleBlock, VPlan &Plan,
2756+ BasicBlock *MiddleBlock,
27552757 VPTransformState &State) {
27562758 // There are two kinds of external IV usages - those that use the value
27572759 // computed in the last iteration (the PHI) and those that use the penultimate
@@ -2931,11 +2933,10 @@ LoopVectorizationCostModel::getVectorIntrinsicCost(CallInst *CI,
29312933 TargetTransformInfo::TCK_RecipThroughput);
29322934}
29332935
2934- void InnerLoopVectorizer::fixVectorizedLoop (VPTransformState &State,
2935- VPlan &Plan) {
2936+ void InnerLoopVectorizer::fixVectorizedLoop (VPTransformState &State) {
29362937 // Fix widened non-induction PHIs by setting up the PHI operands.
29372938 if (EnableVPlanNativePath)
2938- fixNonInductionPHIs (Plan, State);
2939+ fixNonInductionPHIs (State);
29392940
29402941 // Forget the original basic block.
29412942 PSE.getSE ()->forgetLoop (OrigLoop);
@@ -2966,7 +2967,7 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State,
29662967 for (const auto &Entry : Legal->getInductionVars ())
29672968 fixupIVUsers (Entry.first , Entry.second ,
29682969 getOrCreateVectorTripCount (nullptr ),
2969- IVEndValues[Entry.first ], LoopMiddleBlock, Plan, State);
2970+ IVEndValues[Entry.first ], LoopMiddleBlock, State);
29702971 }
29712972
29722973 // Fix live-out phis not already fixed earlier.
@@ -3077,8 +3078,7 @@ void InnerLoopVectorizer::sinkScalarOperands(Instruction *PredInst) {
30773078 } while (Changed);
30783079}
30793080
3080- void InnerLoopVectorizer::fixNonInductionPHIs (VPlan &Plan,
3081- VPTransformState &State) {
3081+ void InnerLoopVectorizer::fixNonInductionPHIs (VPTransformState &State) {
30823082 auto Iter = vp_depth_first_deep (Plan.getEntry ());
30833083 for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(Iter)) {
30843084 for (VPRecipeBase &P : VPBB->phis ()) {
@@ -7744,7 +7744,7 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
77447744
77457745 // 3. Fix the vectorized code: take care of header phi's, live-outs,
77467746 // predication, updating analyses.
7747- ILV.fixVectorizedLoop (State, BestVPlan );
7747+ ILV.fixVectorizedLoop (State);
77487748
77497749 ILV.printDebugTracesAtEnd ();
77507750
@@ -9727,7 +9727,7 @@ static bool processLoopInVPlanNativePath(
97279727 GeneratedRTChecks Checks (PSE, DT, LI, TTI, F->getDataLayout (),
97289728 AddBranchWeights);
97299729 InnerLoopVectorizer LB (L, PSE, LI, DT, TLI, TTI, AC, ORE, VF.Width ,
9730- VF.Width , 1 , LVL, &CM, BFI, PSI, Checks);
9730+ VF.Width , 1 , LVL, &CM, BFI, PSI, Checks, BestPlan );
97319731 LLVM_DEBUG (dbgs () << " Vectorizing outer loop in \" "
97329732 << L->getHeader ()->getParent ()->getName () << " \"\n " );
97339733 LVP.executePlan (VF.Width , 1 , BestPlan, LB, DT, false );
@@ -10215,11 +10215,11 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1021510215 assert (IC > 1 && " interleave count should not be 1 or 0" );
1021610216 // If we decided that it is not legal to vectorize the loop, then
1021710217 // interleave it.
10218+ VPlan &BestPlan = LVP.getPlanFor (VF.Width );
1021810219 InnerLoopVectorizer Unroller (
1021910220 L, PSE, LI, DT, TLI, TTI, AC, ORE, ElementCount::getFixed (1 ),
10220- ElementCount::getFixed (1 ), IC, &LVL, &CM, BFI, PSI, Checks);
10221+ ElementCount::getFixed (1 ), IC, &LVL, &CM, BFI, PSI, Checks, BestPlan );
1022110222
10222- VPlan &BestPlan = LVP.getPlanFor (VF.Width );
1022310223 LVP.executePlan (VF.Width , IC, BestPlan, Unroller, DT, false );
1022410224
1022510225 ORE->emit ([&]() {
@@ -10236,15 +10236,16 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1023610236 VectorizationFactor EpilogueVF =
1023710237 LVP.selectEpilogueVectorizationFactor (VF.Width , IC);
1023810238 if (EpilogueVF.Width .isVector ()) {
10239+ std::unique_ptr<VPlan> BestMainPlan (BestPlan.duplicate ());
1023910240
1024010241 // The first pass vectorizes the main loop and creates a scalar epilogue
1024110242 // to be vectorized by executing the plan (potentially with a different
1024210243 // factor) again shortly afterwards.
1024310244 EpilogueLoopVectorizationInfo EPI (VF.Width , IC, EpilogueVF.Width , 1 );
1024410245 EpilogueVectorizerMainLoop MainILV (L, PSE, LI, DT, TLI, TTI, AC, ORE,
10245- EPI, &LVL, &CM, BFI, PSI, Checks);
10246+ EPI, &LVL, &CM, BFI, PSI, Checks,
10247+ *BestMainPlan);
1024610248
10247- std::unique_ptr<VPlan> BestMainPlan (BestPlan.duplicate ());
1024810249 auto ExpandedSCEVs = LVP.executePlan (EPI.MainLoopVF , EPI.MainLoopUF ,
1024910250 *BestMainPlan, MainILV, DT, false );
1025010251 ++LoopsVectorized;
@@ -10253,11 +10254,11 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1025310254 // edges from the first pass.
1025410255 EPI.MainLoopVF = EPI.EpilogueVF ;
1025510256 EPI.MainLoopUF = EPI.EpilogueUF ;
10257+ VPlan &BestEpiPlan = LVP.getPlanFor (EPI.EpilogueVF );
1025610258 EpilogueVectorizerEpilogueLoop EpilogILV (L, PSE, LI, DT, TLI, TTI, AC,
1025710259 ORE, EPI, &LVL, &CM, BFI, PSI,
10258- Checks);
10260+ Checks, BestEpiPlan );
1025910261
10260- VPlan &BestEpiPlan = LVP.getPlanFor (EPI.EpilogueVF );
1026110262 VPRegionBlock *VectorLoop = BestEpiPlan.getVectorLoopRegion ();
1026210263 VPBasicBlock *Header = VectorLoop->getEntryBasicBlock ();
1026310264 Header->setName (" vec.epilog.vector.body" );
@@ -10340,7 +10341,7 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1034010341 } else {
1034110342 InnerLoopVectorizer LB (L, PSE, LI, DT, TLI, TTI, AC, ORE, VF.Width ,
1034210343 VF.MinProfitableTripCount , IC, &LVL, &CM, BFI,
10343- PSI, Checks);
10344+ PSI, Checks, BestPlan );
1034410345 LVP.executePlan (VF.Width , IC, BestPlan, LB, DT, false );
1034510346 ++LoopsVectorized;
1034610347
0 commit comments