-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[LV][NFC] Refactor structures used to maintain uncountable exit info #123219
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -391,25 +391,22 @@ class LoopVectorizationLegality { | |||||
|
|
||||||
| /// Returns true if the loop has an uncountable early exit, i.e. an | ||||||
| /// uncountable exit that isn't the latch block. | ||||||
| bool hasUncountableEarlyExit() const { return HasUncountableEarlyExit; } | ||||||
| bool hasUncountableEarlyExit() const { | ||||||
| return getUncountableEdge().has_value(); | ||||||
| } | ||||||
|
|
||||||
| /// Returns the uncountable early exiting block. | ||||||
|
||||||
| /// Returns the uncountable early exiting block. | |
| /// Returns the uncountable early exiting block, if there is a single one. |
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.
Done
Outdated
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.
nit: may be more compact
| if (!hasUncountableEarlyExit()) | |
| return hasUncountableEarlyExit() ? getUncountableEdge()->first : nullptr;` |
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.
Done
Outdated
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.
| /// Returns the destination of an uncountable early exiting block. | |
| /// Returns the destination of the uncountable early exiting block, there is a single one. |
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.
Done
Outdated
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.
can this and other places just use ->?
| return (*getUncountableEdge()).second; | |
| return getUncountableEdge()->second; |
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.
Done
Outdated
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.
Would be good to cover also the empty case, perhaps something like
| /// Returns the loop edge with an uncountable exit. | |
| /// Returns the loop edge with an uncountable exit or std::nullopt if there isn't a single such edge. |
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.
Done
Outdated
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.
| /// Keep track of the loop edge with an uncountable exit, comprising a pair | |
| /// Keep track of the loop edge to an uncountable exit, comprising a pair |
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.
Done
Outdated
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.
| /// of (Exiting, Exit) blocks. | |
| /// of (Exiting, Exit) blocks, if there is exactly one early exit. |
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.
Done
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1631,12 +1631,11 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() { | |
|
|
||
| // Keep a record of all the exiting blocks. | ||
| SmallVector<const SCEVPredicate *, 4> Predicates; | ||
| SmallVector<std::pair<BasicBlock *, BasicBlock *>, 4> UncountableEdges; | ||
| for (BasicBlock *BB : ExitingBlocks) { | ||
| const SCEV *EC = | ||
| PSE.getSE()->getPredicatedExitCount(TheLoop, BB, &Predicates); | ||
| if (isa<SCEVCouldNotCompute>(EC)) { | ||
| UncountableExitingBlocks.push_back(BB); | ||
|
|
||
| SmallVector<BasicBlock *, 2> Succs(successors(BB)); | ||
| if (Succs.size() != 2) { | ||
| reportVectorizationFailure( | ||
|
|
@@ -1653,7 +1652,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() { | |
| assert(!TheLoop->contains(Succs[1])); | ||
| ExitBlock = Succs[1]; | ||
| } | ||
| UncountableExitBlocks.push_back(ExitBlock); | ||
| UncountableEdges.push_back({BB, ExitBlock}); | ||
|
||
| } else | ||
| CountableExitingBlocks.push_back(BB); | ||
| } | ||
|
|
@@ -1664,7 +1663,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() { | |
| Predicates.clear(); | ||
|
|
||
| // We only support one uncountable early exit. | ||
| if (getUncountableExitingBlocks().size() != 1) { | ||
| if (UncountableEdges.size() != 1) { | ||
| reportVectorizationFailure( | ||
| "Loop has too many uncountable exits", | ||
| "Cannot vectorize early exit loop with more than one early exit", | ||
|
|
@@ -1675,7 +1674,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 != getUncountableEarlyExitingBlock()) { | ||
| if (LatchPredBB != UncountableEdges[0].first) { | ||
| reportVectorizationFailure("Early exit is not the latch predecessor", | ||
| "Cannot vectorize early exit loop", | ||
| "EarlyExitNotLatchPredecessor", ORE, TheLoop); | ||
|
|
@@ -1728,7 +1727,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() { | |
| } | ||
|
|
||
| // The vectoriser cannot handle loads that occur after the early exit block. | ||
| assert(LatchBB->getUniquePredecessor() == getUncountableEarlyExitingBlock() && | ||
| assert(LatchBB->getUniquePredecessor() == UncountableEdges[0].first && | ||
| "Expected latch predecessor to be the early exiting block"); | ||
|
|
||
| // TODO: Handle loops that may fault. | ||
|
|
@@ -1751,6 +1750,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() { | |
| LLVM_DEBUG(dbgs() << "LV: Found an early exit loop with symbolic max " | ||
| "backedge taken count: " | ||
| << *SymbolicMaxBTC << '\n'); | ||
| UncountableEdge = UncountableEdges[0]; | ||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -1812,7 +1812,6 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) { | |
| return false; | ||
| } | ||
|
|
||
| HasUncountableEarlyExit = false; | ||
| if (isa<SCEVCouldNotCompute>(PSE.getBackedgeTakenCount())) { | ||
| if (TheLoop->getExitingBlock()) { | ||
| reportVectorizationFailure("Cannot vectorize uncountable loop", | ||
|
|
@@ -1822,10 +1821,8 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) { | |
| else | ||
| return false; | ||
| } else { | ||
| HasUncountableEarlyExit = true; | ||
| if (!isVectorizableEarlyExitLoop()) { | ||
| UncountableExitingBlocks.clear(); | ||
| HasUncountableEarlyExit = false; | ||
| UncountableEdge = std::nullopt; | ||
| if (DoExtraAnalysis) | ||
| Result = false; | ||
| else | ||
|
|
||
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.
Might be good to clarify there must be single edge
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.
Done