Skip to content

Commit b7db075

Browse files
committed
[LV] Replace UncountableEdge with UncountableEarlyExitingBlock (NFC).
Only the uncountable exiting BB is used. Store it instead of a piar of Exiting BB and Exit BB.
1 parent ded255e commit b7db075

File tree

2 files changed

+14
-28
lines changed

2 files changed

+14
-28
lines changed

llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -400,19 +400,11 @@ class LoopVectorizationLegality {
400400

401401
/// Returns true if the loop has exactly one uncountable early exit, i.e. an
402402
/// uncountable exit that isn't the latch block.
403-
bool hasUncountableEarlyExit() const {
404-
return getUncountableEdge().has_value();
405-
}
403+
bool hasUncountableEarlyExit() const { return UncountableExitingBB; }
406404

407405
/// Returns the uncountable early exiting block, if there is exactly one.
408406
BasicBlock *getUncountableEarlyExitingBlock() const {
409-
return hasUncountableEarlyExit() ? getUncountableEdge()->first : nullptr;
410-
}
411-
412-
/// Returns the destination of the uncountable early exiting block, if there
413-
/// is exactly one.
414-
BasicBlock *getUncountableEarlyExitBlock() const {
415-
return hasUncountableEarlyExit() ? getUncountableEdge()->second : nullptr;
407+
return UncountableExitingBB;
416408
}
417409

418410
/// Return true if there is store-load forwarding dependencies.
@@ -473,13 +465,6 @@ class LoopVectorizationLegality {
473465
return CountableExitingBlocks;
474466
}
475467

476-
/// Returns the loop edge to an uncountable exit, or std::nullopt if there
477-
/// isn't a single such edge.
478-
std::optional<std::pair<BasicBlock *, BasicBlock *>>
479-
getUncountableEdge() const {
480-
return UncountableEdge;
481-
}
482-
483468
private:
484469
/// Return true if the pre-header, exiting and latch blocks of \p Lp and all
485470
/// its nested loops are considered legal for vectorization. These legal
@@ -659,9 +644,9 @@ class LoopVectorizationLegality {
659644
/// the exact backedge taken count is not computable.
660645
SmallVector<BasicBlock *, 4> CountableExitingBlocks;
661646

662-
/// Keep track of the loop edge to an uncountable exit, comprising a pair
663-
/// of (Exiting, Exit) blocks, if there is exactly one early exit.
664-
std::optional<std::pair<BasicBlock *, BasicBlock *>> UncountableEdge;
647+
/// Keep track of an uncountable exiting block, if there is exactly one early
648+
/// exit.
649+
BasicBlock *UncountableExitingBB = nullptr;
665650
};
666651

667652
} // namespace llvm

llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
16651665

16661666
// Keep a record of all the exiting blocks.
16671667
SmallVector<const SCEVPredicate *, 4> Predicates;
1668-
std::optional<std::pair<BasicBlock *, BasicBlock *>> SingleUncountableEdge;
1668+
BasicBlock *SingleUncountableExitingBlock;
16691669
for (BasicBlock *BB : ExitingBlocks) {
16701670
const SCEV *EC =
16711671
PSE.getSE()->getPredicatedExitCount(TheLoop, BB, &Predicates);
@@ -1687,15 +1687,15 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
16871687
ExitBlock = Succs[1];
16881688
}
16891689

1690-
if (SingleUncountableEdge) {
1690+
if (SingleUncountableExitingBlock) {
16911691
reportVectorizationFailure(
16921692
"Loop has too many uncountable exits",
16931693
"Cannot vectorize early exit loop with more than one early exit",
16941694
"TooManyUncountableEarlyExits", ORE, TheLoop);
16951695
return false;
16961696
}
16971697

1698-
SingleUncountableEdge = {BB, ExitBlock};
1698+
SingleUncountableExitingBlock = BB;
16991699
} else
17001700
CountableExitingBlocks.push_back(BB);
17011701
}
@@ -1705,15 +1705,15 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
17051705
// PSE.getSymbolicMaxBackedgeTakenCount() below.
17061706
Predicates.clear();
17071707

1708-
if (!SingleUncountableEdge) {
1708+
if (!SingleUncountableExitingBlock) {
17091709
LLVM_DEBUG(dbgs() << "LV: Cound not find any uncountable exits");
17101710
return false;
17111711
}
17121712

17131713
// The only supported early exit loops so far are ones where the early
17141714
// exiting block is a unique predecessor of the latch block.
17151715
BasicBlock *LatchPredBB = LatchBB->getUniquePredecessor();
1716-
if (LatchPredBB != SingleUncountableEdge->first) {
1716+
if (LatchPredBB != SingleUncountableExitingBlock) {
17171717
reportVectorizationFailure("Early exit is not the latch predecessor",
17181718
"Cannot vectorize early exit loop",
17191719
"EarlyExitNotLatchPredecessor", ORE, TheLoop);
@@ -1766,7 +1766,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
17661766
}
17671767

17681768
// The vectoriser cannot handle loads that occur after the early exit block.
1769-
assert(LatchBB->getUniquePredecessor() == SingleUncountableEdge->first &&
1769+
assert(LatchBB->getUniquePredecessor() == SingleUncountableExitingBlock &&
17701770
"Expected latch predecessor to be the early exiting block");
17711771

17721772
// TODO: Handle loops that may fault.
@@ -1789,7 +1789,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
17891789
LLVM_DEBUG(dbgs() << "LV: Found an early exit loop with symbolic max "
17901790
"backedge taken count: "
17911791
<< *SymbolicMaxBTC << '\n');
1792-
UncountableEdge = SingleUncountableEdge;
1792+
UncountableExitingBB = SingleUncountableExitingBlock;
17931793
return true;
17941794
}
17951795

@@ -1861,7 +1861,8 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) {
18611861
return false;
18621862
} else {
18631863
if (!isVectorizableEarlyExitLoop()) {
1864-
UncountableEdge = std::nullopt;
1864+
assert(!hasUncountableEarlyExit() &&
1865+
"Must be false without vectorizable early-exit loop");
18651866
if (DoExtraAnalysis)
18661867
Result = false;
18671868
else

0 commit comments

Comments
 (0)