[llvm] ffd0f5f - [LV] Remove unneeded ILV::LoopScalarPreHeader (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 26 13:46:43 PDT 2025
Author: Florian Hahn
Date: 2025-08-26T21:44:48+01:00
New Revision: ffd0f5fd217e66b6843bc420f7c37042e562810d
URL: https://github.com/llvm/llvm-project/commit/ffd0f5fd217e66b6843bc420f7c37042e562810d
DIFF: https://github.com/llvm/llvm-project/commit/ffd0f5fd217e66b6843bc420f7c37042e562810d.diff
LOG: [LV] Remove unneeded ILV::LoopScalarPreHeader (NFC).
Follow-up suggested in https://github.com/llvm/llvm-project/pull/153643.
Remove some more global state by directly returning the scalar
preheader from createScalarPreheader.
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 179c13c1c9fd8..6317bc3c20e25 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -543,9 +543,9 @@ class InnerLoopVectorizer {
protected:
friend class LoopVectorizationPlanner;
- /// Create a new IR basic block for the scalar preheader whose name is
- /// prefixed with \p Prefix.
- void createScalarPreheader(StringRef Prefix);
+ /// Create and return a new IR basic block for the scalar preheader whose name
+ /// is prefixed with \p Prefix.
+ BasicBlock *createScalarPreheader(StringRef Prefix);
/// Allow subclasses to override and print debug traces before/after vplan
/// execution, when trace information is requested.
@@ -593,9 +593,6 @@ class InnerLoopVectorizer {
/// The vector-loop preheader.
BasicBlock *LoopVectorPreHeader = nullptr;
- /// The scalar-loop preheader.
- BasicBlock *LoopScalarPreHeader = nullptr;
-
/// Trip count of the original loop.
Value *TripCount = nullptr;
@@ -2370,20 +2367,19 @@ static VPIRBasicBlock *replaceVPBBWithIRVPBB(VPBasicBlock *VPBB,
return IRVPBB;
}
-void InnerLoopVectorizer::createScalarPreheader(StringRef Prefix) {
+BasicBlock *InnerLoopVectorizer::createScalarPreheader(StringRef Prefix) {
LoopVectorPreHeader = OrigLoop->getLoopPreheader();
assert(LoopVectorPreHeader && "Invalid loop structure");
assert((OrigLoop->getUniqueLatchExitBlock() ||
Cost->requiresScalarEpilogue(VF.isVector())) &&
"loops not exiting via the latch without required epilogue?");
- LoopScalarPreHeader =
- SplitBlock(LoopVectorPreHeader, LoopVectorPreHeader->getTerminator(), DT,
- LI, nullptr, Twine(Prefix) + "scalar.ph");
// NOTE: The Plan's scalar preheader VPBB isn't replaced with a VPIRBasicBlock
- // wrapping LoopScalarPreHeader here at the moment, because the Plan's scalar
- // preheader may be unreachable at this point. Instead it is replaced in
- // executePlan.
+ // wrapping the newly created scalar preheader here at the moment, because the
+ // Plan's scalar preheader may be unreachable at this point. Instead it is
+ // replaced in executePlan.
+ return SplitBlock(LoopVectorPreHeader, LoopVectorPreHeader->getTerminator(),
+ DT, LI, nullptr, Twine(Prefix) + "scalar.ph");
}
/// Return the expanded step for \p ID using \p ExpandedSCEVs to look up SCEV
@@ -2425,8 +2421,8 @@ static void addFullyUnrolledInstructionsToIgnore(
BasicBlock *InnerLoopVectorizer::createVectorizedLoopSkeleton() {
// Create a new IR basic block for the scalar preheader.
- createScalarPreheader("");
- return LoopVectorPreHeader;
+ BasicBlock *ScalarPH = createScalarPreheader("");
+ return ScalarPH->getSinglePredecessor();
}
namespace {
@@ -7396,12 +7392,11 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
/// This function is partially responsible for generating the control flow
/// depicted in https://llvm.org/docs/Vectorizers.html#epilogue-vectorization.
BasicBlock *EpilogueVectorizerMainLoop::createVectorizedLoopSkeleton() {
- createScalarPreheader("");
+ BasicBlock *ScalarPH = createScalarPreheader("");
// Generate the code to check the minimum iteration count of the vector
// epilogue (see below).
- EPI.EpilogueIterationCountCheck =
- emitIterationCountCheck(LoopScalarPreHeader, true);
+ EPI.EpilogueIterationCountCheck = emitIterationCountCheck(ScalarPH, true);
EPI.EpilogueIterationCountCheck->setName("iter.check");
// Generate the iteration count check for the main loop, *after* the check
@@ -7410,8 +7405,7 @@ BasicBlock *EpilogueVectorizerMainLoop::createVectorizedLoopSkeleton() {
// the main loop is compensated for, by the gain from vectorizing the larger
// trip count. Note: the branch will get updated later on when we vectorize
// the epilogue.
- EPI.MainLoopIterationCountCheck =
- emitIterationCountCheck(LoopScalarPreHeader, false);
+ EPI.MainLoopIterationCountCheck = emitIterationCountCheck(ScalarPH, false);
return LoopVectorPreHeader;
}
@@ -7482,7 +7476,7 @@ EpilogueVectorizerMainLoop::emitIterationCountCheck(BasicBlock *Bypass,
/// This function is partially responsible for generating the control flow
/// depicted in https://llvm.org/docs/Vectorizers.html#epilogue-vectorization.
BasicBlock *EpilogueVectorizerEpilogueLoop::createVectorizedLoopSkeleton() {
- createScalarPreheader("vec.epilog.");
+ BasicBlock *ScalarPH = createScalarPreheader("vec.epilog.");
// Now, compare the remaining count and if there aren't enough iterations to
// execute the vectorized epilogue skip to the scalar part.
@@ -7492,7 +7486,7 @@ BasicBlock *EpilogueVectorizerEpilogueLoop::createVectorizedLoopSkeleton() {
nullptr, "vec.epilog.iter.check", true);
VectorPHVPBB = replaceVPBBWithIRVPBB(VectorPHVPBB, LoopVectorPreHeader);
- emitMinimumVectorEpilogueIterCountCheck(LoopScalarPreHeader,
+ emitMinimumVectorEpilogueIterCountCheck(ScalarPH,
VecEpilogueIterationCountCheck);
AdditionalBypassBlock = VecEpilogueIterationCountCheck;
@@ -7504,20 +7498,19 @@ BasicBlock *EpilogueVectorizerEpilogueLoop::createVectorizedLoopSkeleton() {
VecEpilogueIterationCountCheck, LoopVectorPreHeader);
EPI.EpilogueIterationCountCheck->getTerminator()->replaceUsesOfWith(
- VecEpilogueIterationCountCheck, LoopScalarPreHeader);
+ VecEpilogueIterationCountCheck, ScalarPH);
// Adjust the terminators of runtime check blocks and phis using them.
BasicBlock *SCEVCheckBlock = RTChecks.getSCEVChecks().second;
BasicBlock *MemCheckBlock = RTChecks.getMemRuntimeChecks().second;
if (SCEVCheckBlock)
SCEVCheckBlock->getTerminator()->replaceUsesOfWith(
- VecEpilogueIterationCountCheck, LoopScalarPreHeader);
+ VecEpilogueIterationCountCheck, ScalarPH);
if (MemCheckBlock)
MemCheckBlock->getTerminator()->replaceUsesOfWith(
- VecEpilogueIterationCountCheck, LoopScalarPreHeader);
+ VecEpilogueIterationCountCheck, ScalarPH);
- DT->changeImmediateDominator(LoopScalarPreHeader,
- EPI.EpilogueIterationCountCheck);
+ DT->changeImmediateDominator(ScalarPH, EPI.EpilogueIterationCountCheck);
// The vec.epilog.iter.check block may contain Phi nodes from inductions or
// reductions which merge control-flow from the latch block and the middle
More information about the llvm-commits
mailing list