@@ -7673,7 +7673,8 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
7673
7673
// cost model is complete for better cost estimates.
7674
7674
VPlanTransforms::runPass (VPlanTransforms::unrollByUF, BestVPlan, BestUF,
7675
7675
OrigLoop->getHeader ()->getContext ());
7676
- VPlanTransforms::materializeBroadcasts (BestVPlan);
7676
+ VPlanTransforms::materializeBroadcasts (
7677
+ BestVPlan, OrigLoop->getHeader ()->getDataLayout ());
7677
7678
VPlanTransforms::optimizeForVFAndUF (BestVPlan, BestVF, BestUF, PSE);
7678
7679
VPlanTransforms::simplifyRecipes (BestVPlan, *Legal->getWidestInductionType ());
7679
7680
VPlanTransforms::narrowInterleaveGroups (
@@ -8966,7 +8967,8 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
8966
8967
// Discard the plan if it is not EVL-compatible
8967
8968
if (CM.foldTailWithEVL () && !HasScalarVF &&
8968
8969
!VPlanTransforms::runPass (VPlanTransforms::tryAddExplicitVectorLength,
8969
- *Plan, CM.getMaxSafeElements ()))
8970
+ *Plan, CM.getMaxSafeElements (),
8971
+ OrigLoop->getHeader ()->getDataLayout ()))
8970
8972
break ;
8971
8973
assert (verifyVPlanIsValid (*Plan) && " VPlan is invalid" );
8972
8974
VPlans.push_back (std::move (Plan));
@@ -8978,7 +8980,7 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
8978
8980
// Add the necessary canonical IV and branch recipes required to control the
8979
8981
// loop.
8980
8982
static void addCanonicalIVRecipes (VPlan &Plan, Type *IdxTy, bool HasNUW,
8981
- DebugLoc DL) {
8983
+ DebugLoc DL, const DataLayout &Layout ) {
8982
8984
Value *StartIdx = ConstantInt::get (IdxTy, 0 );
8983
8985
auto *StartV = Plan.getOrAddLiveIn (StartIdx);
8984
8986
@@ -8988,7 +8990,7 @@ static void addCanonicalIVRecipes(VPlan &Plan, Type *IdxTy, bool HasNUW,
8988
8990
VPBasicBlock *Header = TopRegion->getEntryBasicBlock ();
8989
8991
Header->insert (CanonicalIVPHI, Header->begin ());
8990
8992
8991
- VPBuilder Builder (TopRegion->getExitingBasicBlock ());
8993
+ VPBuilder Builder (Layout, TopRegion->getExitingBasicBlock ());
8992
8994
// Add a VPInstruction to increment the scalar canonical IV by VF * UF.
8993
8995
auto *CanonicalIVIncrement = Builder.createOverflowingOp (
8994
8996
Instruction::Add, {CanonicalIVPHI, &Plan.getVFxUF ()}, {HasNUW, false }, DL,
@@ -9042,15 +9044,16 @@ static VPInstruction *addResumePhiRecipeForInduction(
9042
9044
// / original phis in the scalar header. End values for inductions are added to
9043
9045
// / \p IVEndValues.
9044
9046
static void addScalarResumePhis (VPRecipeBuilder &Builder, VPlan &Plan,
9045
- DenseMap<VPValue *, VPValue *> &IVEndValues) {
9047
+ DenseMap<VPValue *, VPValue *> &IVEndValues,
9048
+ const DataLayout &DL) {
9046
9049
VPTypeAnalysis TypeInfo (Plan.getCanonicalIV ()->getScalarType ());
9047
9050
auto *ScalarPH = Plan.getScalarPreheader ();
9048
9051
auto *MiddleVPBB = cast<VPBasicBlock>(ScalarPH->getSinglePredecessor ());
9049
9052
VPRegionBlock *VectorRegion = Plan.getVectorLoopRegion ();
9050
9053
VPBuilder VectorPHBuilder (
9051
- cast<VPBasicBlock>(VectorRegion->getSinglePredecessor ()));
9052
- VPBuilder MiddleBuilder (MiddleVPBB, MiddleVPBB->getFirstNonPhi ());
9053
- VPBuilder ScalarPHBuilder (ScalarPH);
9054
+ DL, cast<VPBasicBlock>(VectorRegion->getSinglePredecessor ()));
9055
+ VPBuilder MiddleBuilder (DL, MiddleVPBB, MiddleVPBB->getFirstNonPhi ());
9056
+ VPBuilder ScalarPHBuilder (DL, ScalarPH);
9054
9057
VPValue *OneVPV = Plan.getOrAddLiveIn (
9055
9058
ConstantInt::get (Plan.getCanonicalIV ()->getScalarType (), 1 ));
9056
9059
for (VPRecipeBase &ScalarPhiR : *Plan.getScalarHeader ()) {
@@ -9141,12 +9144,13 @@ collectUsersInExitBlocks(Loop *OrigLoop, VPRecipeBuilder &Builder,
9141
9144
// ExitUsersToFix if needed and their operands are updated.
9142
9145
static void
9143
9146
addUsersInExitBlocks (VPlan &Plan,
9144
- const SetVector<VPIRInstruction *> &ExitUsersToFix) {
9147
+ const SetVector<VPIRInstruction *> &ExitUsersToFix,
9148
+ const DataLayout &DL) {
9145
9149
if (ExitUsersToFix.empty ())
9146
9150
return ;
9147
9151
9148
9152
auto *MiddleVPBB = Plan.getMiddleBlock ();
9149
- VPBuilder B (MiddleVPBB, MiddleVPBB->getFirstNonPhi ());
9153
+ VPBuilder B (DL, MiddleVPBB, MiddleVPBB->getFirstNonPhi ());
9150
9154
9151
9155
// Introduce extract for exiting values and update the VPIRInstructions
9152
9156
// modeling the corresponding LCSSA phis.
@@ -9164,12 +9168,13 @@ addUsersInExitBlocks(VPlan &Plan,
9164
9168
// / users in the original exit block using the VPIRInstruction wrapping to the
9165
9169
// / LCSSA phi.
9166
9170
static void addExitUsersForFirstOrderRecurrences (
9167
- VPlan &Plan, SetVector<VPIRInstruction *> &ExitUsersToFix) {
9171
+ VPlan &Plan, SetVector<VPIRInstruction *> &ExitUsersToFix,
9172
+ const DataLayout &DL) {
9168
9173
VPRegionBlock *VectorRegion = Plan.getVectorLoopRegion ();
9169
9174
auto *ScalarPHVPBB = Plan.getScalarPreheader ();
9170
9175
auto *MiddleVPBB = Plan.getMiddleBlock ();
9171
- VPBuilder ScalarPHBuilder (ScalarPHVPBB);
9172
- VPBuilder MiddleBuilder (MiddleVPBB, MiddleVPBB->getFirstNonPhi ());
9176
+ VPBuilder ScalarPHBuilder (DL, ScalarPHVPBB);
9177
+ VPBuilder MiddleBuilder (DL, MiddleVPBB, MiddleVPBB->getFirstNonPhi ());
9173
9178
VPValue *TwoVPV = Plan.getOrAddLiveIn (
9174
9179
ConstantInt::get (Plan.getCanonicalIV ()->getScalarType (), 2 ));
9175
9180
@@ -9312,7 +9317,9 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
9312
9317
// that the canonical induction increment will not overflow as the vector trip
9313
9318
// count is >= increment and a multiple of the increment.
9314
9319
bool HasNUW = !IVUpdateMayOverflow || Style == TailFoldingStyle::None;
9315
- addCanonicalIVRecipes (*Plan, Legal->getWidestInductionType (), HasNUW, DL);
9320
+ const DataLayout &Layout = OrigLoop->getHeader ()->getDataLayout ();
9321
+ addCanonicalIVRecipes (*Plan, Legal->getWidestInductionType (), HasNUW, DL,
9322
+ Layout);
9316
9323
9317
9324
VPRecipeBuilder RecipeBuilder (*Plan, OrigLoop, TLI, &TTI, Legal, CM, PSE,
9318
9325
Builder);
@@ -9499,11 +9506,11 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
9499
9506
RecipeBuilder);
9500
9507
}
9501
9508
DenseMap<VPValue *, VPValue *> IVEndValues;
9502
- addScalarResumePhis (RecipeBuilder, *Plan, IVEndValues);
9509
+ addScalarResumePhis (RecipeBuilder, *Plan, IVEndValues, Layout );
9503
9510
SetVector<VPIRInstruction *> ExitUsersToFix =
9504
9511
collectUsersInExitBlocks (OrigLoop, RecipeBuilder, *Plan);
9505
- addExitUsersForFirstOrderRecurrences (*Plan, ExitUsersToFix);
9506
- addUsersInExitBlocks (*Plan, ExitUsersToFix);
9512
+ addExitUsersForFirstOrderRecurrences (*Plan, ExitUsersToFix, Layout );
9513
+ addUsersInExitBlocks (*Plan, ExitUsersToFix, Layout );
9507
9514
9508
9515
// ---------------------------------------------------------------------------
9509
9516
// Transform initial VPlan: Apply previously taken decisions, in order, to
@@ -9575,7 +9582,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
9575
9582
bool WithoutRuntimeCheck =
9576
9583
Style == TailFoldingStyle::DataAndControlFlowWithoutRuntimeCheck;
9577
9584
VPlanTransforms::addActiveLaneMask (*Plan, ForControlFlow,
9578
- WithoutRuntimeCheck);
9585
+ WithoutRuntimeCheck, Layout );
9579
9586
}
9580
9587
VPlanTransforms::optimizeInductionExitUsers (*Plan, IVEndValues);
9581
9588
@@ -9614,8 +9621,9 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
9614
9621
// Tail folding is not supported for outer loops, so the induction increment
9615
9622
// is guaranteed to not wrap.
9616
9623
bool HasNUW = true ;
9624
+ const DataLayout &DL = OrigLoop->getHeader ()->getDataLayout ();
9617
9625
addCanonicalIVRecipes (*Plan, Legal->getWidestInductionType (), HasNUW,
9618
- DebugLoc ());
9626
+ DebugLoc (), DL );
9619
9627
9620
9628
// Collect mapping of IR header phis to header phi recipes, to be used in
9621
9629
// addScalarResumePhis.
@@ -9630,7 +9638,7 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
9630
9638
DenseMap<VPValue *, VPValue *> IVEndValues;
9631
9639
// TODO: IVEndValues are not used yet in the native path, to optimize exit
9632
9640
// values.
9633
- addScalarResumePhis (RecipeBuilder, *Plan, IVEndValues);
9641
+ addScalarResumePhis (RecipeBuilder, *Plan, IVEndValues, DL );
9634
9642
9635
9643
assert (verifyVPlanIsValid (*Plan) && " VPlan is invalid" );
9636
9644
return Plan;
@@ -10070,7 +10078,7 @@ static bool processLoopInVPlanNativePath(
10070
10078
// TODO: CM is not used at this point inside the planner. Turn CM into an
10071
10079
// optional argument if we don't need it in the future.
10072
10080
LoopVectorizationPlanner LVP (L, LI, DT, TLI, *TTI, LVL, CM, IAI, PSE, Hints,
10073
- ORE);
10081
+ ORE, F-> getDataLayout () );
10074
10082
10075
10083
// Get user vectorization factor.
10076
10084
ElementCount UserVF = Hints.getWidth ();
@@ -10298,7 +10306,8 @@ LoopVectorizePass::LoopVectorizePass(LoopVectorizeOptions Opts)
10298
10306
// / Prepare \p MainPlan for vectorizing the main vector loop during epilogue
10299
10307
// / vectorization. Remove ResumePhis from \p MainPlan for inductions that
10300
10308
// / don't have a corresponding wide induction in \p EpiPlan.
10301
- static void preparePlanForMainVectorLoop (VPlan &MainPlan, VPlan &EpiPlan) {
10309
+ static void preparePlanForMainVectorLoop (VPlan &MainPlan, VPlan &EpiPlan,
10310
+ const DataLayout &DL) {
10302
10311
// Collect PHI nodes of widened phis in the VPlan for the epilogue. Those
10303
10312
// will need their resume-values computed in the main vector loop. Others
10304
10313
// can be removed from the main VPlan.
@@ -10338,7 +10347,7 @@ static void preparePlanForMainVectorLoop(VPlan &MainPlan, VPlan &EpiPlan) {
10338
10347
m_Specific (VectorTC), m_SpecificInt (0 )));
10339
10348
}))
10340
10349
return ;
10341
- VPBuilder ScalarPHBuilder (MainScalarPH, MainScalarPH->begin ());
10350
+ VPBuilder ScalarPHBuilder (DL, MainScalarPH, MainScalarPH->begin ());
10342
10351
ScalarPHBuilder.createNaryOp (
10343
10352
VPInstruction::ResumePhi,
10344
10353
{VectorTC, MainPlan.getCanonicalIV ()->getStartValue ()}, {},
@@ -10671,7 +10680,7 @@ bool LoopVectorizePass::processLoop(Loop *L) {
10671
10680
F, &Hints, IAI, PSI, BFI);
10672
10681
// Use the planner for vectorization.
10673
10682
LoopVectorizationPlanner LVP (L, LI, DT, TLI, *TTI, &LVL, CM, IAI, PSE, Hints,
10674
- ORE);
10683
+ ORE, F-> getDataLayout () );
10675
10684
10676
10685
// Get user vectorization factor and interleave count.
10677
10686
ElementCount UserVF = Hints.getWidth ();
@@ -10854,7 +10863,8 @@ bool LoopVectorizePass::processLoop(Loop *L) {
10854
10863
// factor) again shortly afterwards.
10855
10864
VPlan &BestEpiPlan = LVP.getPlanFor (EpilogueVF.Width );
10856
10865
BestEpiPlan.getMiddleBlock ()->setName (" vec.epilog.middle.block" );
10857
- preparePlanForMainVectorLoop (*BestMainPlan, BestEpiPlan);
10866
+ preparePlanForMainVectorLoop (*BestMainPlan, BestEpiPlan,
10867
+ F->getDataLayout ());
10858
10868
EpilogueLoopVectorizationInfo EPI (VF.Width , IC, EpilogueVF.Width , 1 ,
10859
10869
BestEpiPlan);
10860
10870
EpilogueVectorizerMainLoop MainILV (L, PSE, LI, DT, TLI, TTI, AC, ORE,
0 commit comments