@@ -7698,7 +7698,8 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
7698
7698
// cost model is complete for better cost estimates.
7699
7699
VPlanTransforms::runPass (VPlanTransforms::unrollByUF, BestVPlan, BestUF,
7700
7700
OrigLoop->getHeader ()->getContext ());
7701
- VPlanTransforms::materializeBroadcasts (BestVPlan);
7701
+ VPlanTransforms::materializeBroadcasts (
7702
+ BestVPlan, OrigLoop->getHeader ()->getDataLayout ());
7702
7703
VPlanTransforms::optimizeForVFAndUF (BestVPlan, BestVF, BestUF, PSE);
7703
7704
VPlanTransforms::simplifyRecipes (BestVPlan, *Legal->getWidestInductionType ());
7704
7705
VPlanTransforms::narrowInterleaveGroups (
@@ -8991,7 +8992,8 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
8991
8992
// Discard the plan if it is not EVL-compatible
8992
8993
if (CM.foldTailWithEVL () && !HasScalarVF &&
8993
8994
!VPlanTransforms::runPass (VPlanTransforms::tryAddExplicitVectorLength,
8994
- *Plan, CM.getMaxSafeElements ()))
8995
+ *Plan, CM.getMaxSafeElements (),
8996
+ OrigLoop->getHeader ()->getDataLayout ()))
8995
8997
break ;
8996
8998
assert (verifyVPlanIsValid (*Plan) && " VPlan is invalid" );
8997
8999
VPlans.push_back (std::move (Plan));
@@ -9003,7 +9005,7 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
9003
9005
// Add the necessary canonical IV and branch recipes required to control the
9004
9006
// loop.
9005
9007
static void addCanonicalIVRecipes (VPlan &Plan, Type *IdxTy, bool HasNUW,
9006
- DebugLoc DL) {
9008
+ DebugLoc DL, const DataLayout &Layout ) {
9007
9009
Value *StartIdx = ConstantInt::get (IdxTy, 0 );
9008
9010
auto *StartV = Plan.getOrAddLiveIn (StartIdx);
9009
9011
@@ -9013,7 +9015,7 @@ static void addCanonicalIVRecipes(VPlan &Plan, Type *IdxTy, bool HasNUW,
9013
9015
VPBasicBlock *Header = TopRegion->getEntryBasicBlock ();
9014
9016
Header->insert (CanonicalIVPHI, Header->begin ());
9015
9017
9016
- VPBuilder Builder (TopRegion->getExitingBasicBlock ());
9018
+ VPBuilder Builder (Layout, TopRegion->getExitingBasicBlock ());
9017
9019
// Add a VPInstruction to increment the scalar canonical IV by VF * UF.
9018
9020
auto *CanonicalIVIncrement = Builder.createOverflowingOp (
9019
9021
Instruction::Add, {CanonicalIVPHI, &Plan.getVFxUF ()}, {HasNUW, false }, DL,
@@ -9067,15 +9069,16 @@ static VPInstruction *addResumePhiRecipeForInduction(
9067
9069
// / original phis in the scalar header. End values for inductions are added to
9068
9070
// / \p IVEndValues.
9069
9071
static void addScalarResumePhis (VPRecipeBuilder &Builder, VPlan &Plan,
9070
- DenseMap<VPValue *, VPValue *> &IVEndValues) {
9072
+ DenseMap<VPValue *, VPValue *> &IVEndValues,
9073
+ const DataLayout &DL) {
9071
9074
VPTypeAnalysis TypeInfo (Plan.getCanonicalIV ()->getScalarType ());
9072
9075
auto *ScalarPH = Plan.getScalarPreheader ();
9073
9076
auto *MiddleVPBB = cast<VPBasicBlock>(ScalarPH->getSinglePredecessor ());
9074
9077
VPRegionBlock *VectorRegion = Plan.getVectorLoopRegion ();
9075
9078
VPBuilder VectorPHBuilder (
9076
- cast<VPBasicBlock>(VectorRegion->getSinglePredecessor ()));
9077
- VPBuilder MiddleBuilder (MiddleVPBB, MiddleVPBB->getFirstNonPhi ());
9078
- VPBuilder ScalarPHBuilder (ScalarPH);
9079
+ DL, cast<VPBasicBlock>(VectorRegion->getSinglePredecessor ()));
9080
+ VPBuilder MiddleBuilder (DL, MiddleVPBB, MiddleVPBB->getFirstNonPhi ());
9081
+ VPBuilder ScalarPHBuilder (DL, ScalarPH);
9079
9082
VPValue *OneVPV = Plan.getOrAddLiveIn (
9080
9083
ConstantInt::get (Plan.getCanonicalIV ()->getScalarType (), 1 ));
9081
9084
for (VPRecipeBase &ScalarPhiR : *Plan.getScalarHeader ()) {
@@ -9165,12 +9168,13 @@ collectUsersInExitBlocks(Loop *OrigLoop, VPRecipeBuilder &Builder,
9165
9168
// ExitUsersToFix if needed and their operands are updated.
9166
9169
static void
9167
9170
addUsersInExitBlocks (VPlan &Plan,
9168
- const SetVector<VPIRInstruction *> &ExitUsersToFix) {
9171
+ const SetVector<VPIRInstruction *> &ExitUsersToFix,
9172
+ const DataLayout &DL) {
9169
9173
if (ExitUsersToFix.empty ())
9170
9174
return ;
9171
9175
9172
9176
auto *MiddleVPBB = Plan.getMiddleBlock ();
9173
- VPBuilder B (MiddleVPBB, MiddleVPBB->getFirstNonPhi ());
9177
+ VPBuilder B (DL, MiddleVPBB, MiddleVPBB->getFirstNonPhi ());
9174
9178
9175
9179
// Introduce extract for exiting values and update the VPIRInstructions
9176
9180
// modeling the corresponding LCSSA phis.
@@ -9188,12 +9192,13 @@ addUsersInExitBlocks(VPlan &Plan,
9188
9192
// / users in the original exit block using the VPIRInstruction wrapping to the
9189
9193
// / LCSSA phi.
9190
9194
static void addExitUsersForFirstOrderRecurrences (
9191
- VPlan &Plan, SetVector<VPIRInstruction *> &ExitUsersToFix) {
9195
+ VPlan &Plan, SetVector<VPIRInstruction *> &ExitUsersToFix,
9196
+ const DataLayout &DL) {
9192
9197
VPRegionBlock *VectorRegion = Plan.getVectorLoopRegion ();
9193
9198
auto *ScalarPHVPBB = Plan.getScalarPreheader ();
9194
9199
auto *MiddleVPBB = Plan.getMiddleBlock ();
9195
- VPBuilder ScalarPHBuilder (ScalarPHVPBB);
9196
- VPBuilder MiddleBuilder (MiddleVPBB, MiddleVPBB->getFirstNonPhi ());
9200
+ VPBuilder ScalarPHBuilder (DL, ScalarPHVPBB);
9201
+ VPBuilder MiddleBuilder (DL, MiddleVPBB, MiddleVPBB->getFirstNonPhi ());
9197
9202
VPValue *TwoVPV = Plan.getOrAddLiveIn (
9198
9203
ConstantInt::get (Plan.getCanonicalIV ()->getScalarType (), 2 ));
9199
9204
@@ -9336,7 +9341,9 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
9336
9341
// that the canonical induction increment will not overflow as the vector trip
9337
9342
// count is >= increment and a multiple of the increment.
9338
9343
bool HasNUW = !IVUpdateMayOverflow || Style == TailFoldingStyle::None;
9339
- addCanonicalIVRecipes (*Plan, Legal->getWidestInductionType (), HasNUW, DL);
9344
+ const DataLayout &Layout = OrigLoop->getHeader ()->getDataLayout ();
9345
+ addCanonicalIVRecipes (*Plan, Legal->getWidestInductionType (), HasNUW, DL,
9346
+ Layout);
9340
9347
9341
9348
VPRecipeBuilder RecipeBuilder (*Plan, OrigLoop, TLI, &TTI, Legal, CM, PSE,
9342
9349
Builder);
@@ -9523,11 +9530,11 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
9523
9530
RecipeBuilder);
9524
9531
}
9525
9532
DenseMap<VPValue *, VPValue *> IVEndValues;
9526
- addScalarResumePhis (RecipeBuilder, *Plan, IVEndValues);
9533
+ addScalarResumePhis (RecipeBuilder, *Plan, IVEndValues, Layout );
9527
9534
SetVector<VPIRInstruction *> ExitUsersToFix =
9528
9535
collectUsersInExitBlocks (OrigLoop, RecipeBuilder, *Plan);
9529
- addExitUsersForFirstOrderRecurrences (*Plan, ExitUsersToFix);
9530
- addUsersInExitBlocks (*Plan, ExitUsersToFix);
9536
+ addExitUsersForFirstOrderRecurrences (*Plan, ExitUsersToFix, Layout );
9537
+ addUsersInExitBlocks (*Plan, ExitUsersToFix, Layout );
9531
9538
9532
9539
// ---------------------------------------------------------------------------
9533
9540
// Transform initial VPlan: Apply previously taken decisions, in order, to
@@ -9599,7 +9606,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
9599
9606
bool WithoutRuntimeCheck =
9600
9607
Style == TailFoldingStyle::DataAndControlFlowWithoutRuntimeCheck;
9601
9608
VPlanTransforms::addActiveLaneMask (*Plan, ForControlFlow,
9602
- WithoutRuntimeCheck);
9609
+ WithoutRuntimeCheck, Layout );
9603
9610
}
9604
9611
VPlanTransforms::optimizeInductionExitUsers (*Plan, IVEndValues);
9605
9612
@@ -9638,8 +9645,9 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
9638
9645
// Tail folding is not supported for outer loops, so the induction increment
9639
9646
// is guaranteed to not wrap.
9640
9647
bool HasNUW = true ;
9648
+ const DataLayout &DL = OrigLoop->getHeader ()->getDataLayout ();
9641
9649
addCanonicalIVRecipes (*Plan, Legal->getWidestInductionType (), HasNUW,
9642
- DebugLoc ());
9650
+ DebugLoc (), DL );
9643
9651
9644
9652
// Collect mapping of IR header phis to header phi recipes, to be used in
9645
9653
// addScalarResumePhis.
@@ -9654,7 +9662,7 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
9654
9662
DenseMap<VPValue *, VPValue *> IVEndValues;
9655
9663
// TODO: IVEndValues are not used yet in the native path, to optimize exit
9656
9664
// values.
9657
- addScalarResumePhis (RecipeBuilder, *Plan, IVEndValues);
9665
+ addScalarResumePhis (RecipeBuilder, *Plan, IVEndValues, DL );
9658
9666
9659
9667
assert (verifyVPlanIsValid (*Plan) && " VPlan is invalid" );
9660
9668
return Plan;
@@ -10105,7 +10113,7 @@ static bool processLoopInVPlanNativePath(
10105
10113
// TODO: CM is not used at this point inside the planner. Turn CM into an
10106
10114
// optional argument if we don't need it in the future.
10107
10115
LoopVectorizationPlanner LVP (L, LI, DT, TLI, *TTI, LVL, CM, IAI, PSE, Hints,
10108
- ORE);
10116
+ ORE, F-> getDataLayout () );
10109
10117
10110
10118
// Get user vectorization factor.
10111
10119
ElementCount UserVF = Hints.getWidth ();
@@ -10333,7 +10341,8 @@ LoopVectorizePass::LoopVectorizePass(LoopVectorizeOptions Opts)
10333
10341
// / Prepare \p MainPlan for vectorizing the main vector loop during epilogue
10334
10342
// / vectorization. Remove ResumePhis from \p MainPlan for inductions that
10335
10343
// / don't have a corresponding wide induction in \p EpiPlan.
10336
- static void preparePlanForMainVectorLoop (VPlan &MainPlan, VPlan &EpiPlan) {
10344
+ static void preparePlanForMainVectorLoop (VPlan &MainPlan, VPlan &EpiPlan,
10345
+ const DataLayout &DL) {
10337
10346
// Collect PHI nodes of widened phis in the VPlan for the epilogue. Those
10338
10347
// will need their resume-values computed in the main vector loop. Others
10339
10348
// can be removed from the main VPlan.
@@ -10372,7 +10381,7 @@ static void preparePlanForMainVectorLoop(VPlan &MainPlan, VPlan &EpiPlan) {
10372
10381
m_Specific (VectorTC), m_SpecificInt (0 )));
10373
10382
}))
10374
10383
return ;
10375
- VPBuilder ScalarPHBuilder (MainScalarPH, MainScalarPH->begin ());
10384
+ VPBuilder ScalarPHBuilder (DL, MainScalarPH, MainScalarPH->begin ());
10376
10385
ScalarPHBuilder.createNaryOp (
10377
10386
VPInstruction::ResumePhi,
10378
10387
{VectorTC, MainPlan.getCanonicalIV ()->getStartValue ()}, {},
@@ -10694,7 +10703,7 @@ bool LoopVectorizePass::processLoop(Loop *L) {
10694
10703
F, &Hints, IAI, PSI, BFI);
10695
10704
// Use the planner for vectorization.
10696
10705
LoopVectorizationPlanner LVP (L, LI, DT, TLI, *TTI, &LVL, CM, IAI, PSE, Hints,
10697
- ORE);
10706
+ ORE, F-> getDataLayout () );
10698
10707
10699
10708
// Get user vectorization factor and interleave count.
10700
10709
ElementCount UserVF = Hints.getWidth ();
@@ -10877,7 +10886,8 @@ bool LoopVectorizePass::processLoop(Loop *L) {
10877
10886
// factor) again shortly afterwards.
10878
10887
VPlan &BestEpiPlan = LVP.getPlanFor (EpilogueVF.Width );
10879
10888
BestEpiPlan.getMiddleBlock ()->setName (" vec.epilog.middle.block" );
10880
- preparePlanForMainVectorLoop (*BestMainPlan, BestEpiPlan);
10889
+ preparePlanForMainVectorLoop (*BestMainPlan, BestEpiPlan,
10890
+ F->getDataLayout ());
10881
10891
EpilogueLoopVectorizationInfo EPI (VF.Width , IC, EpilogueVF.Width , 1 ,
10882
10892
BestEpiPlan);
10883
10893
EpilogueVectorizerMainLoop MainILV (L, PSE, LI, DT, TLI, TTI, AC, ORE,
0 commit comments