Skip to content

Commit b28bb32

Browse files
committed
!fixup address comments, thanks
1 parent 7a79e1c commit b28bb32

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8690,9 +8690,11 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
86908690
return !CM.requiresScalarEpilogue(VF.isVector());
86918691
},
86928692
Range);
8693-
VPlanTransforms::handleEarlyExitsAndAddMiddleCheck(
8694-
*Plan, RequiresScalarEpilogueCheck, CM.foldTailByMasking(),
8695-
Legal->hasUncountableEarlyExit(), Range);
8693+
VPlanTransforms::handleEarlyExits(*Plan, Legal->hasUncountableEarlyExit(),
8694+
Range);
8695+
VPlanTransforms::addMiddleCheck(*Plan, RequiresScalarEpilogueCheck,
8696+
CM.foldTailByMasking());
8697+
86968698
VPlanTransforms::createLoopRegions(*Plan);
86978699
VPlanTransforms::createExtractsForLiveOuts(*Plan);
86988700

@@ -8981,9 +8983,11 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
89818983
auto Plan = VPlanTransforms::buildVPlan0(
89828984
OrigLoop, *LI, Legal->getWidestInductionType(),
89838985
getDebugLocFromInstOrOperands(Legal->getPrimaryInduction()), PSE);
8984-
VPlanTransforms::handleEarlyExitsAndAddMiddleCheck(
8985-
*Plan, /*RequiresScalarEpilogue*/ true, /*TailFolded*/ false,
8986-
/*HasUncountableExit*/ false, Range);
8986+
VPlanTransforms::handleEarlyExits(*Plan,
8987+
/*HasUncountableExit*/ false, Range);
8988+
VPlanTransforms::addMiddleCheck(*Plan, /*RequiresScalarEpilogue*/ true,
8989+
/*TailFolded*/ false);
8990+
89878991
VPlanTransforms::createLoopRegions(*Plan);
89888992

89898993
for (ElementCount VF : Range)

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,14 +514,13 @@ VPlanTransforms::buildVPlan0(Loop *TheLoop, LoopInfo &LI, Type *InductionTy,
514514
return VPlan0;
515515
}
516516

517-
void VPlanTransforms::handleEarlyExitsAndAddMiddleCheck(
518-
VPlan &Plan, bool RequiresScalarEpilogueCheck, bool TailFolded,
519-
bool HasUncountableEarlyExit, VFRange &Range) {
517+
void VPlanTransforms::handleEarlyExits(VPlan &Plan,
518+
bool HasUncountableEarlyExit,
519+
VFRange &Range) {
520520
auto *MiddleVPBB = cast<VPBasicBlock>(
521521
Plan.getScalarHeader()->getSinglePredecessor()->getPredecessors()[0]);
522-
VPBlockBase *HeaderVPB =
523-
Plan.getEntry()->getSuccessors()[1]->getSingleSuccessor();
524-
auto *LatchVPBB = cast<VPBasicBlock>(HeaderVPB->getPredecessors()[1]);
522+
auto *LatchVPBB = cast<VPBasicBlock>(MiddleVPBB->getSinglePredecessor());
523+
VPBlockBase *HeaderVPB = cast<VPBasicBlock>(LatchVPBB->getSuccessors()[1]);
525524

526525
// Disconnect all early exits from the loop leaving it with a single exit from
527526
// the latch. Early exits that are countable are left for a scalar epilog. The
@@ -551,7 +550,13 @@ void VPlanTransforms::handleEarlyExitsAndAddMiddleCheck(
551550

552551
assert((!HasUncountableEarlyExit || HandledUncountableEarlyExit) &&
553552
"missed an uncountable exit that must be handled");
553+
}
554554

555+
void VPlanTransforms::addMiddleCheck(VPlan &Plan,
556+
bool RequiresScalarEpilogueCheck,
557+
bool TailFolded) {
558+
auto *MiddleVPBB = cast<VPBasicBlock>(
559+
Plan.getScalarHeader()->getSinglePredecessor()->getPredecessors()[0]);
555560
// If MiddleVPBB has a single successor then the original loop does not exit
556561
// via the latch and the single successor must be the scalar preheader.
557562
// There's no need to add a runtime check to MiddleVPBB.
@@ -578,6 +583,7 @@ void VPlanTransforms::handleEarlyExitsAndAddMiddleCheck(
578583
// the corresponding compare because they may have ended up with different
579584
// line numbers and we want to avoid awkward line stepping while debugging.
580585
// E.g., if the compare has got a line number inside the loop.
586+
auto *LatchVPBB = cast<VPBasicBlock>(MiddleVPBB->getSinglePredecessor());
581587
DebugLoc LatchDL = LatchVPBB->getTerminator()->getDebugLoc();
582588
VPBuilder Builder(MiddleVPBB);
583589
VPValue *Cmp;

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ struct VPlanTransforms {
5959
/// \p TheLoop being directly translated to VPBasicBlocks with VPInstruction
6060
/// corresponding to the input IR.
6161
///
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
62+
/// The created loop is wrapped in an initial skeleton to facilitate
63+
/// vectorization, consisting of a vector pre-header, an exit block for the
6464
/// main vector loop (middle.block) and a new block as preheader of the scalar
6565
/// loop (scalar.ph). It also adds a canonical IV and its increment, using \p
6666
/// InductionTy and \p IVDL, and creates a VPValue expression for the original
@@ -69,12 +69,15 @@ struct VPlanTransforms {
6969
buildVPlan0(Loop *TheLoop, LoopInfo &LI, Type *InductionTy, DebugLoc IVDL,
7070
PredicatedScalarEvolution &PSE);
7171

72-
/// Update \p Plan to account for all early exits. If a check is needed to
73-
/// guard executing the scalar epilogue loop, it will be added to the middle
74-
/// block.
75-
LLVM_ABI_FOR_TEST static void handleEarlyExitsAndAddMiddleCheck(
76-
VPlan &Plan, bool RequiresScalarEpilogueCheck, bool TailFolded,
77-
bool HasUncountableExit, VFRange &Range);
72+
/// Update \p Plan to account for all early exits.
73+
LLVM_ABI_FOR_TEST static void
74+
handleEarlyExits(VPlan &Plan, bool HasUncountableExit, VFRange &Range);
75+
76+
/// If a check is needed to guard executing the scalar epilogue loop, it will
77+
/// be added to the middle block.
78+
LLVM_ABI_FOR_TEST static void addMiddleCheck(VPlan &Plan,
79+
bool RequiresScalarEpilogueCheck,
80+
bool TailFolded);
7881

7982
/// Replace loops in \p Plan's flat CFG with VPRegionBlocks, turning \p Plan's
8083
/// flat CFG into a hierarchical CFG.

llvm/unittests/Transforms/Vectorize/VPlanTestBase.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ class VPlanTestIRBase : public testing::Test {
7676
{}, PSE);
7777

7878
VFRange R(ElementCount::getFixed(1), ElementCount::getFixed(2));
79-
VPlanTransforms::handleEarlyExitsAndAddMiddleCheck(*Plan, true, false,
80-
false, R);
79+
VPlanTransforms::handleEarlyExits(*Plan, false, R);
80+
VPlanTransforms::addMiddleCheck(*Plan, true, false);
81+
8182
VPlanTransforms::createLoopRegions(*Plan);
8283
return Plan;
8384
}

0 commit comments

Comments
 (0)