Skip to content

Commit ffd0f5f

Browse files
committed
[LV] Remove unneeded ILV::LoopScalarPreHeader (NFC).
Follow-up suggested in #153643. Remove some more global state by directly returning the scalar preheader from createScalarPreheader.
1 parent be2f020 commit ffd0f5f

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,9 @@ class InnerLoopVectorizer {
543543
protected:
544544
friend class LoopVectorizationPlanner;
545545

546-
/// Create a new IR basic block for the scalar preheader whose name is
547-
/// prefixed with \p Prefix.
548-
void createScalarPreheader(StringRef Prefix);
546+
/// Create and return a new IR basic block for the scalar preheader whose name
547+
/// is prefixed with \p Prefix.
548+
BasicBlock *createScalarPreheader(StringRef Prefix);
549549

550550
/// Allow subclasses to override and print debug traces before/after vplan
551551
/// execution, when trace information is requested.
@@ -593,9 +593,6 @@ class InnerLoopVectorizer {
593593
/// The vector-loop preheader.
594594
BasicBlock *LoopVectorPreHeader = nullptr;
595595

596-
/// The scalar-loop preheader.
597-
BasicBlock *LoopScalarPreHeader = nullptr;
598-
599596
/// Trip count of the original loop.
600597
Value *TripCount = nullptr;
601598

@@ -2370,20 +2367,19 @@ static VPIRBasicBlock *replaceVPBBWithIRVPBB(VPBasicBlock *VPBB,
23702367
return IRVPBB;
23712368
}
23722369

2373-
void InnerLoopVectorizer::createScalarPreheader(StringRef Prefix) {
2370+
BasicBlock *InnerLoopVectorizer::createScalarPreheader(StringRef Prefix) {
23742371
LoopVectorPreHeader = OrigLoop->getLoopPreheader();
23752372
assert(LoopVectorPreHeader && "Invalid loop structure");
23762373
assert((OrigLoop->getUniqueLatchExitBlock() ||
23772374
Cost->requiresScalarEpilogue(VF.isVector())) &&
23782375
"loops not exiting via the latch without required epilogue?");
23792376

2380-
LoopScalarPreHeader =
2381-
SplitBlock(LoopVectorPreHeader, LoopVectorPreHeader->getTerminator(), DT,
2382-
LI, nullptr, Twine(Prefix) + "scalar.ph");
23832377
// NOTE: The Plan's scalar preheader VPBB isn't replaced with a VPIRBasicBlock
2384-
// wrapping LoopScalarPreHeader here at the moment, because the Plan's scalar
2385-
// preheader may be unreachable at this point. Instead it is replaced in
2386-
// executePlan.
2378+
// wrapping the newly created scalar preheader here at the moment, because the
2379+
// Plan's scalar preheader may be unreachable at this point. Instead it is
2380+
// replaced in executePlan.
2381+
return SplitBlock(LoopVectorPreHeader, LoopVectorPreHeader->getTerminator(),
2382+
DT, LI, nullptr, Twine(Prefix) + "scalar.ph");
23872383
}
23882384

23892385
/// Return the expanded step for \p ID using \p ExpandedSCEVs to look up SCEV
@@ -2425,8 +2421,8 @@ static void addFullyUnrolledInstructionsToIgnore(
24252421

24262422
BasicBlock *InnerLoopVectorizer::createVectorizedLoopSkeleton() {
24272423
// Create a new IR basic block for the scalar preheader.
2428-
createScalarPreheader("");
2429-
return LoopVectorPreHeader;
2424+
BasicBlock *ScalarPH = createScalarPreheader("");
2425+
return ScalarPH->getSinglePredecessor();
24302426
}
24312427

24322428
namespace {
@@ -7396,12 +7392,11 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
73967392
/// This function is partially responsible for generating the control flow
73977393
/// depicted in https://llvm.org/docs/Vectorizers.html#epilogue-vectorization.
73987394
BasicBlock *EpilogueVectorizerMainLoop::createVectorizedLoopSkeleton() {
7399-
createScalarPreheader("");
7395+
BasicBlock *ScalarPH = createScalarPreheader("");
74007396

74017397
// Generate the code to check the minimum iteration count of the vector
74027398
// epilogue (see below).
7403-
EPI.EpilogueIterationCountCheck =
7404-
emitIterationCountCheck(LoopScalarPreHeader, true);
7399+
EPI.EpilogueIterationCountCheck = emitIterationCountCheck(ScalarPH, true);
74057400
EPI.EpilogueIterationCountCheck->setName("iter.check");
74067401

74077402
// Generate the iteration count check for the main loop, *after* the check
@@ -7410,8 +7405,7 @@ BasicBlock *EpilogueVectorizerMainLoop::createVectorizedLoopSkeleton() {
74107405
// the main loop is compensated for, by the gain from vectorizing the larger
74117406
// trip count. Note: the branch will get updated later on when we vectorize
74127407
// the epilogue.
7413-
EPI.MainLoopIterationCountCheck =
7414-
emitIterationCountCheck(LoopScalarPreHeader, false);
7408+
EPI.MainLoopIterationCountCheck = emitIterationCountCheck(ScalarPH, false);
74157409

74167410
return LoopVectorPreHeader;
74177411
}
@@ -7482,7 +7476,7 @@ EpilogueVectorizerMainLoop::emitIterationCountCheck(BasicBlock *Bypass,
74827476
/// This function is partially responsible for generating the control flow
74837477
/// depicted in https://llvm.org/docs/Vectorizers.html#epilogue-vectorization.
74847478
BasicBlock *EpilogueVectorizerEpilogueLoop::createVectorizedLoopSkeleton() {
7485-
createScalarPreheader("vec.epilog.");
7479+
BasicBlock *ScalarPH = createScalarPreheader("vec.epilog.");
74867480

74877481
// Now, compare the remaining count and if there aren't enough iterations to
74887482
// execute the vectorized epilogue skip to the scalar part.
@@ -7492,7 +7486,7 @@ BasicBlock *EpilogueVectorizerEpilogueLoop::createVectorizedLoopSkeleton() {
74927486
nullptr, "vec.epilog.iter.check", true);
74937487
VectorPHVPBB = replaceVPBBWithIRVPBB(VectorPHVPBB, LoopVectorPreHeader);
74947488

7495-
emitMinimumVectorEpilogueIterCountCheck(LoopScalarPreHeader,
7489+
emitMinimumVectorEpilogueIterCountCheck(ScalarPH,
74967490
VecEpilogueIterationCountCheck);
74977491
AdditionalBypassBlock = VecEpilogueIterationCountCheck;
74987492

@@ -7504,20 +7498,19 @@ BasicBlock *EpilogueVectorizerEpilogueLoop::createVectorizedLoopSkeleton() {
75047498
VecEpilogueIterationCountCheck, LoopVectorPreHeader);
75057499

75067500
EPI.EpilogueIterationCountCheck->getTerminator()->replaceUsesOfWith(
7507-
VecEpilogueIterationCountCheck, LoopScalarPreHeader);
7501+
VecEpilogueIterationCountCheck, ScalarPH);
75087502

75097503
// Adjust the terminators of runtime check blocks and phis using them.
75107504
BasicBlock *SCEVCheckBlock = RTChecks.getSCEVChecks().second;
75117505
BasicBlock *MemCheckBlock = RTChecks.getMemRuntimeChecks().second;
75127506
if (SCEVCheckBlock)
75137507
SCEVCheckBlock->getTerminator()->replaceUsesOfWith(
7514-
VecEpilogueIterationCountCheck, LoopScalarPreHeader);
7508+
VecEpilogueIterationCountCheck, ScalarPH);
75157509
if (MemCheckBlock)
75167510
MemCheckBlock->getTerminator()->replaceUsesOfWith(
7517-
VecEpilogueIterationCountCheck, LoopScalarPreHeader);
7511+
VecEpilogueIterationCountCheck, ScalarPH);
75187512

7519-
DT->changeImmediateDominator(LoopScalarPreHeader,
7520-
EPI.EpilogueIterationCountCheck);
7513+
DT->changeImmediateDominator(ScalarPH, EPI.EpilogueIterationCountCheck);
75217514

75227515
// The vec.epilog.iter.check block may contain Phi nodes from inductions or
75237516
// reductions which merge control-flow from the latch block and the middle

0 commit comments

Comments
 (0)