Skip to content

Commit d2a7fce

Browse files
committed
!fixup address comments, thanks
1 parent 3b51594 commit d2a7fce

File tree

4 files changed

+34
-40
lines changed

4 files changed

+34
-40
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8403,16 +8403,11 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
84038403
LVer.prepareNoAliasMetadata();
84048404
}
84058405

8406-
// Create initial VPlan skeleton, having a basic block for the pre-header
8407-
// which contains SCEV expansions that need to happen before the CFG is
8408-
// modified; a basic block for the vector pre-header, followed by a region for
8409-
// the vector loop, followed by the middle basic block, connecting to the
8410-
// scalar preheader and exit blcoks.
8411-
auto VPlan0 = VPlanTransforms::buildPlainCFG(OrigLoop, *LI);
8412-
VPlanTransforms::addInitialSkeleton(
8413-
*VPlan0, Legal->getWidestInductionType(),
8414-
getDebugLocFromInstOrOperands(Legal->getPrimaryInduction()), PSE,
8415-
OrigLoop);
8406+
// Create initial base VPlan0, to serve as common starting point for all
8407+
// candidates built later for specific VF ranges.
8408+
auto VPlan0 = VPlanTransforms::buildVPlan0(
8409+
OrigLoop, *LI, Legal->getWidestInductionType(),
8410+
getDebugLocFromInstOrOperands(Legal->getPrimaryInduction()), PSE);
84168411

84178412
auto MaxVFTimes2 = MaxVF * 2;
84188413
for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
@@ -8949,12 +8944,9 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
89498944
assert(!OrigLoop->isInnermost());
89508945
assert(EnableVPlanNativePath && "VPlan-native path is not enabled.");
89518946

8952-
auto Plan = VPlanTransforms::buildPlainCFG(OrigLoop, *LI);
8953-
8954-
VPlanTransforms::addInitialSkeleton(
8955-
*Plan, Legal->getWidestInductionType(),
8956-
getDebugLocFromInstOrOperands(Legal->getPrimaryInduction()), PSE,
8957-
OrigLoop);
8947+
auto Plan = VPlanTransforms::buildVPlan0(
8948+
OrigLoop, *LI, Legal->getWidestInductionType(),
8949+
getDebugLocFromInstOrOperands(Legal->getPrimaryInduction()), PSE);
89588950
VPlanTransforms::handleEarlyExitsAndAddMiddleCheck(
89598951
*Plan, /*RequiresScalarEpilogue*/ true, /*TailFolded*/ false,
89608952
/*HasUncountableExit*/ false, Range);

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,6 @@ std::unique_ptr<VPlan> PlainCFGBuilder::buildPlainCFG() {
338338
return std::move(Plan);
339339
}
340340

341-
std::unique_ptr<VPlan> VPlanTransforms::buildPlainCFG(Loop *TheLoop,
342-
LoopInfo &LI) {
343-
PlainCFGBuilder Builder(TheLoop, &LI);
344-
return Builder.buildPlainCFG();
345-
}
346-
347341
/// Checks if \p HeaderVPB is a loop header block in the plain CFG; that is, it
348342
/// has exactly 2 predecessors (preheader and latch), where the block
349343
/// dominates the latch and the preheader dominates the block. If it is a
@@ -459,10 +453,8 @@ static void addCanonicalIVRecipes(VPlan &Plan, VPBasicBlock *HeaderVPBB,
459453
LatchDL);
460454
}
461455

462-
void VPlanTransforms::addInitialSkeleton(VPlan &Plan, Type *InductionTy,
463-
DebugLoc IVDL,
464-
PredicatedScalarEvolution &PSE,
465-
Loop *TheLoop) {
456+
static void addInitialSkeleton(VPlan &Plan, Type *InductionTy, DebugLoc IVDL,
457+
PredicatedScalarEvolution &PSE, Loop *TheLoop) {
466458
VPDominatorTree VPDT;
467459
VPDT.recalculate(Plan);
468460

@@ -513,6 +505,15 @@ void VPlanTransforms::addInitialSkeleton(VPlan &Plan, Type *InductionTy,
513505
Plan.getEntry()->swapSuccessors();
514506
}
515507

508+
std::unique_ptr<VPlan>
509+
VPlanTransforms::buildVPlan0(Loop *TheLoop, LoopInfo &LI, Type *InductionTy,
510+
DebugLoc IVDL, PredicatedScalarEvolution &PSE) {
511+
PlainCFGBuilder Builder(TheLoop, &LI);
512+
std::unique_ptr<VPlan> VPlan0 = Builder.buildPlainCFG();
513+
addInitialSkeleton(*VPlan0, InductionTy, IVDL, PSE, TheLoop);
514+
return VPlan0;
515+
}
516+
516517
void VPlanTransforms::handleEarlyExitsAndAddMiddleCheck(
517518
VPlan &Plan, bool RequiresScalarEpilogueCheck, bool TailFolded,
518519
bool HasUncountableEarlyExit, VFRange &Range) {

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,20 @@ struct VPlanTransforms {
5454
verifyVPlanIsValid(Plan);
5555
}
5656

57-
LLVM_ABI_FOR_TEST static std::unique_ptr<VPlan> buildPlainCFG(Loop *TheLoop,
58-
LoopInfo &LI);
59-
60-
/// Prepare the plan for vectorization. It will introduce a dedicated
61-
/// VPBasicBlock for the vector pre-header, a VPBasicBlock as exit
62-
/// block of the main vector loop (middle.block) and a VPBaiscBlock for the
63-
/// scalar preheader. It also adds a canonical IV and its increment, using \p
57+
/// Create a base VPlan0, serving as the common starting point for all later
58+
/// candidates. It consists of an initial plain CFG loop with loop blocks from
59+
/// \p TheLoop being directly translated to VPBasicBlocks with VPInstruction
60+
/// corresponding to the input IR.
61+
///
62+
/// The created loop is wrapped into an initial skeleton to facilitate
63+
/// vectorization, consisting of a vector pre-header, a exit block for the
64+
/// main vector loop (middle.block) and a new block as preheader of the scalar
65+
/// loop (scalar.ph). It also adds a canonical IV and its increment, using \p
6466
/// InductionTy and \p IVDL, and creates a VPValue expression for the original
6567
/// trip count.
66-
LLVM_ABI_FOR_TEST static void
67-
addInitialSkeleton(VPlan &Plan, Type *InductionTy, DebugLoc IVDL,
68-
PredicatedScalarEvolution &PSE, Loop *TheLoop);
68+
LLVM_ABI_FOR_TEST static std::unique_ptr<VPlan>
69+
buildVPlan0(Loop *TheLoop, LoopInfo &LI, Type *InductionTy, DebugLoc IVDL,
70+
PredicatedScalarEvolution &PSE);
6971

7072
/// Update \p Plan to account for all early exits. If a check is needed to
7173
/// guard executing the scalar epilogue loop, it will be added to the middle

llvm/unittests/Transforms/Vectorize/VPlanTestBase.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@ class VPlanTestIRBase : public testing::Test {
7272

7373
Loop *L = LI->getLoopFor(LoopHeader);
7474
PredicatedScalarEvolution PSE(*SE, *L);
75-
auto Plan = VPlanTransforms::buildPlainCFG(L, *LI);
76-
VFRange R(ElementCount::getFixed(1), ElementCount::getFixed(2));
77-
VPlanTransforms::addInitialSkeleton(*Plan, IntegerType::get(*Ctx, 64), {},
78-
PSE, L);
75+
auto Plan = VPlanTransforms::buildVPlan0(L, *LI, IntegerType::get(*Ctx, 64),
76+
{}, PSE);
7977

78+
VFRange R(ElementCount::getFixed(1), ElementCount::getFixed(2));
8079
VPlanTransforms::handleEarlyExitsAndAddMiddleCheck(*Plan, true, false,
8180
false, R);
8281
VPlanTransforms::createLoopRegions(*Plan);

0 commit comments

Comments
 (0)