-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[LV] Check if plan has an early exit via plan's exit blocks. (NFC) #134720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add a dedicated function to check if a plan is for a loop with an early exit. This can easily be determined by checking the exit blocks. This allows removing a use of Legal->hasUncountableEarlyExit() from InnerLoopVectorizer.
|
@llvm/pr-subscribers-vectorizers @llvm/pr-subscribers-llvm-transforms Author: Florian Hahn (fhahn) ChangesAdd a dedicated function to check if a plan is for a loop with an early exit. This can easily be determined by checking the exit blocks. This allows removing a use of Legal->hasUncountableEarlyExit() from InnerLoopVectorizer. Full diff: https://github.com/llvm/llvm-project/pull/134720.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 5df1061691a67..02dc407e6d56b 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -7564,14 +7564,10 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() {
VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(), CM,
CM.CostKind);
precomputeCosts(BestPlan, BestFactor.Width, CostCtx);
- // Set PlanForEarlyExitLoop to true if the BestPlan has been built from a
- // loop with an uncountable early exit. The legacy cost model doesn't
- // properly model costs for such loops.
- bool PlanForEarlyExitLoop =
- BestPlan.getVectorLoopRegion() &&
- BestPlan.getVectorLoopRegion()->getSingleSuccessor() !=
- BestPlan.getMiddleBlock();
- assert((BestFactor.Width == LegacyVF.Width || PlanForEarlyExitLoop ||
+ // Verify that the VPlan-based and legacy cost models agree, except for VPlans
+ // with early exits and plans with additional VPlan simplifications. The
+ // legacy cost model doesn't properly model costs for such loops.
+ assert((BestFactor.Width == LegacyVF.Width || BestPlan.hasEarlyExit() ||
planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width),
CostCtx, OrigLoop) ||
planContainsAdditionalSimplifications(getPlanFor(LegacyVF.Width),
@@ -7782,7 +7778,7 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
// 2.5 When vectorizing the epilogue, fix reduction resume values from the
// additional bypass block.
if (VectorizingEpilogue) {
- assert(!ILV.Legal->hasUncountableEarlyExit() &&
+ assert(!BestVPlan.hasEarlyExit() &&
"Epilogue vectorisation not yet supported with early exits");
BasicBlock *PH = OrigLoop->getLoopPreheader();
BasicBlock *BypassBlock = ILV.getAdditionalBypassBlock();
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index a98d0ecb9a33b..da7aef73f9df3 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -3768,6 +3768,14 @@ class VPlan {
/// successors of the block in VPlan. The returned block is owned by the VPlan
/// and deleted once the VPlan is destroyed.
VPIRBasicBlock *createVPIRBasicBlock(BasicBlock *IRBB);
+
+ /// Returns true if the VPlan is based on a loop with an early exit. That is
+ /// the case if the VPlan has either more than one exit block or a single exit
+ /// block with multiple predecessors (one for the exit via the latch and one
+ /// via the other early exit).
+ bool hasEarlyExit() const {
+ return ExitBlocks.size() > 1 || ExitBlocks[0]->getNumPredecessors() > 1;
+ }
};
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
david-arm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
…s. (NFC) (#134720) Add a dedicated function to check if a plan is for a loop with an early exit. This can easily be determined by checking the exit blocks. This allows removing a use of Legal->hasUncountableEarlyExit() from InnerLoopVectorizer. PR: llvm/llvm-project#134720
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/195/builds/7306 Here is the relevant piece of the build log for the reference |
Add a dedicated function to check if a plan is for a loop with an early exit. This can easily be determined by checking the exit blocks.
This allows removing a use of Legal->hasUncountableEarlyExit() from InnerLoopVectorizer.