@@ -1631,12 +1631,11 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
1631
1631
1632
1632
// Keep a record of all the exiting blocks.
1633
1633
SmallVector<const SCEVPredicate *, 4 > Predicates;
1634
+ std::optional<std::pair<BasicBlock *, BasicBlock *>> SingleUncountableEdge;
1634
1635
for (BasicBlock *BB : ExitingBlocks) {
1635
1636
const SCEV *EC =
1636
1637
PSE.getSE ()->getPredicatedExitCount (TheLoop, BB, &Predicates);
1637
1638
if (isa<SCEVCouldNotCompute>(EC)) {
1638
- UncountableExitingBlocks.push_back (BB);
1639
-
1640
1639
SmallVector<BasicBlock *, 2 > Succs (successors (BB));
1641
1640
if (Succs.size () != 2 ) {
1642
1641
reportVectorizationFailure (
@@ -1653,7 +1652,16 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
1653
1652
assert (!TheLoop->contains (Succs[1 ]));
1654
1653
ExitBlock = Succs[1 ];
1655
1654
}
1656
- UncountableExitBlocks.push_back (ExitBlock);
1655
+
1656
+ if (SingleUncountableEdge) {
1657
+ reportVectorizationFailure (
1658
+ " Loop has too many uncountable exits" ,
1659
+ " Cannot vectorize early exit loop with more than one early exit" ,
1660
+ " TooManyUncountableEarlyExits" , ORE, TheLoop);
1661
+ return false ;
1662
+ }
1663
+
1664
+ SingleUncountableEdge = {BB, ExitBlock};
1657
1665
} else
1658
1666
CountableExitingBlocks.push_back (BB);
1659
1667
}
@@ -1663,19 +1671,15 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
1663
1671
// PSE.getSymbolicMaxBackedgeTakenCount() below.
1664
1672
Predicates.clear ();
1665
1673
1666
- // We only support one uncountable early exit.
1667
- if (getUncountableExitingBlocks ().size () != 1 ) {
1668
- reportVectorizationFailure (
1669
- " Loop has too many uncountable exits" ,
1670
- " Cannot vectorize early exit loop with more than one early exit" ,
1671
- " TooManyUncountableEarlyExits" , ORE, TheLoop);
1674
+ if (!SingleUncountableEdge) {
1675
+ LLVM_DEBUG (dbgs () << " LV: Cound not find any uncountable exits" );
1672
1676
return false ;
1673
1677
}
1674
1678
1675
1679
// The only supported early exit loops so far are ones where the early
1676
1680
// exiting block is a unique predecessor of the latch block.
1677
1681
BasicBlock *LatchPredBB = LatchBB->getUniquePredecessor ();
1678
- if (LatchPredBB != getUncountableEarlyExitingBlock () ) {
1682
+ if (LatchPredBB != SingleUncountableEdge-> first ) {
1679
1683
reportVectorizationFailure (" Early exit is not the latch predecessor" ,
1680
1684
" Cannot vectorize early exit loop" ,
1681
1685
" EarlyExitNotLatchPredecessor" , ORE, TheLoop);
@@ -1728,7 +1732,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
1728
1732
}
1729
1733
1730
1734
// The vectoriser cannot handle loads that occur after the early exit block.
1731
- assert (LatchBB->getUniquePredecessor () == getUncountableEarlyExitingBlock () &&
1735
+ assert (LatchBB->getUniquePredecessor () == SingleUncountableEdge-> first &&
1732
1736
" Expected latch predecessor to be the early exiting block" );
1733
1737
1734
1738
// TODO: Handle loops that may fault.
@@ -1751,6 +1755,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
1751
1755
LLVM_DEBUG (dbgs () << " LV: Found an early exit loop with symbolic max "
1752
1756
" backedge taken count: "
1753
1757
<< *SymbolicMaxBTC << ' \n ' );
1758
+ UncountableEdge = SingleUncountableEdge;
1754
1759
return true ;
1755
1760
}
1756
1761
@@ -1812,7 +1817,6 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) {
1812
1817
return false ;
1813
1818
}
1814
1819
1815
- HasUncountableEarlyExit = false ;
1816
1820
if (isa<SCEVCouldNotCompute>(PSE.getBackedgeTakenCount ())) {
1817
1821
if (TheLoop->getExitingBlock ()) {
1818
1822
reportVectorizationFailure (" Cannot vectorize uncountable loop" ,
@@ -1822,10 +1826,8 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) {
1822
1826
else
1823
1827
return false ;
1824
1828
} else {
1825
- HasUncountableEarlyExit = true ;
1826
1829
if (!isVectorizableEarlyExitLoop ()) {
1827
- UncountableExitingBlocks.clear ();
1828
- HasUncountableEarlyExit = false ;
1830
+ UncountableEdge = std::nullopt;
1829
1831
if (DoExtraAnalysis)
1830
1832
Result = false ;
1831
1833
else
0 commit comments