-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[LV] Replace UncountableEdge with UncountableEarlyExitingBlock (NFC). #151311
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
@llvm/pr-subscribers-vectorizers @llvm/pr-subscribers-llvm-transforms Author: Florian Hahn (fhahn) ChangesOnly the uncountable exiting BB is used. Store it instead of a piar of Exiting BB and Exit BB. Full diff: https://github.com/llvm/llvm-project/pull/151311.diff 2 Files Affected:
diff --git a/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h b/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
index cba37363d0474..43ff084816d18 100644
--- a/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
+++ b/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
@@ -400,19 +400,11 @@ class LoopVectorizationLegality {
/// Returns true if the loop has exactly one uncountable early exit, i.e. an
/// uncountable exit that isn't the latch block.
- bool hasUncountableEarlyExit() const {
- return getUncountableEdge().has_value();
- }
+ bool hasUncountableEarlyExit() const { return UncountableExitingBB; }
/// Returns the uncountable early exiting block, if there is exactly one.
BasicBlock *getUncountableEarlyExitingBlock() const {
- return hasUncountableEarlyExit() ? getUncountableEdge()->first : nullptr;
- }
-
- /// Returns the destination of the uncountable early exiting block, if there
- /// is exactly one.
- BasicBlock *getUncountableEarlyExitBlock() const {
- return hasUncountableEarlyExit() ? getUncountableEdge()->second : nullptr;
+ return UncountableExitingBB;
}
/// Return true if there is store-load forwarding dependencies.
@@ -473,13 +465,6 @@ class LoopVectorizationLegality {
return CountableExitingBlocks;
}
- /// Returns the loop edge to an uncountable exit, or std::nullopt if there
- /// isn't a single such edge.
- std::optional<std::pair<BasicBlock *, BasicBlock *>>
- getUncountableEdge() const {
- return UncountableEdge;
- }
-
private:
/// Return true if the pre-header, exiting and latch blocks of \p Lp and all
/// its nested loops are considered legal for vectorization. These legal
@@ -659,9 +644,9 @@ class LoopVectorizationLegality {
/// the exact backedge taken count is not computable.
SmallVector<BasicBlock *, 4> CountableExitingBlocks;
- /// Keep track of the loop edge to an uncountable exit, comprising a pair
- /// of (Exiting, Exit) blocks, if there is exactly one early exit.
- std::optional<std::pair<BasicBlock *, BasicBlock *>> UncountableEdge;
+ /// Keep track of an uncountable exiting block, if there is exactly one early
+ /// exit.
+ BasicBlock *UncountableExitingBB = nullptr;
};
} // namespace llvm
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index 969d225c6ef2e..1e9581c427c68 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -1665,7 +1665,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
// Keep a record of all the exiting blocks.
SmallVector<const SCEVPredicate *, 4> Predicates;
- std::optional<std::pair<BasicBlock *, BasicBlock *>> SingleUncountableEdge;
+ BasicBlock *SingleUncountableExitingBlock;
for (BasicBlock *BB : ExitingBlocks) {
const SCEV *EC =
PSE.getSE()->getPredicatedExitCount(TheLoop, BB, &Predicates);
@@ -1687,7 +1687,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
ExitBlock = Succs[1];
}
- if (SingleUncountableEdge) {
+ if (SingleUncountableExitingBlock) {
reportVectorizationFailure(
"Loop has too many uncountable exits",
"Cannot vectorize early exit loop with more than one early exit",
@@ -1695,7 +1695,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
return false;
}
- SingleUncountableEdge = {BB, ExitBlock};
+ SingleUncountableExitingBlock = BB;
} else
CountableExitingBlocks.push_back(BB);
}
@@ -1705,7 +1705,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
// PSE.getSymbolicMaxBackedgeTakenCount() below.
Predicates.clear();
- if (!SingleUncountableEdge) {
+ if (!SingleUncountableExitingBlock) {
LLVM_DEBUG(dbgs() << "LV: Cound not find any uncountable exits");
return false;
}
@@ -1713,7 +1713,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
// The only supported early exit loops so far are ones where the early
// exiting block is a unique predecessor of the latch block.
BasicBlock *LatchPredBB = LatchBB->getUniquePredecessor();
- if (LatchPredBB != SingleUncountableEdge->first) {
+ if (LatchPredBB != SingleUncountableExitingBlock) {
reportVectorizationFailure("Early exit is not the latch predecessor",
"Cannot vectorize early exit loop",
"EarlyExitNotLatchPredecessor", ORE, TheLoop);
@@ -1766,7 +1766,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
}
// The vectoriser cannot handle loads that occur after the early exit block.
- assert(LatchBB->getUniquePredecessor() == SingleUncountableEdge->first &&
+ assert(LatchBB->getUniquePredecessor() == SingleUncountableExitingBlock &&
"Expected latch predecessor to be the early exiting block");
// TODO: Handle loops that may fault.
@@ -1789,7 +1789,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
LLVM_DEBUG(dbgs() << "LV: Found an early exit loop with symbolic max "
"backedge taken count: "
<< *SymbolicMaxBTC << '\n');
- UncountableEdge = SingleUncountableEdge;
+ UncountableExitingBB = SingleUncountableExitingBlock;
return true;
}
@@ -1861,7 +1861,8 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) {
return false;
} else {
if (!isVectorizableEarlyExitLoop()) {
- UncountableEdge = std::nullopt;
+ assert(!hasUncountableEarlyExit() &&
+ "Must be false without vectorizable early-exit loop");
if (DoExtraAnalysis)
Result = false;
else
|
b7db075
to
1527adb
Compare
Looks like there are some failures on Linux/Windows, which I cannot reproduce on macOS. Will need to check what the issue is |
@@ -1665,7 +1665,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() { | |||
|
|||
// Keep a record of all the exiting blocks. | |||
SmallVector<const SCEVPredicate *, 4> Predicates; | |||
std::optional<std::pair<BasicBlock *, BasicBlock *>> SingleUncountableEdge; | |||
BasicBlock *SingleUncountableExitingBlock; |
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.
Could the build issue be due to this uninitialised variable?
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.
Ah yes, thanks, fixed. Looks like my local compiler was zero-initializing local variables...
Only the uncountable exiting BB is used. Store it instead of a piar of Exiting BB and Exit BB.
1527adb
to
c59d55c
Compare
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!
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/51/builds/20800 Here is the relevant piece of the build log for the reference
|
…lock (NFC). (#151311) Only the uncountable exiting BB is used. Store it instead of a piar of Exiting BB and Exit BB. PR: llvm/llvm-project#151311
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/168/builds/14806 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/72/builds/13716 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/66/builds/17331 Here is the relevant piece of the build log for the reference
|
Clean up unused/dead variables after 965231c (llvm/llvm-project#151311)
Only the uncountable exiting BB is used. Store it instead of a piar of Exiting BB and Exit BB.