@@ -1846,8 +1846,6 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
18461846
18471847bool LoopVectorizationLegality::canUncountableExitConditionLoadBeMoved (
18481848 BasicBlock *ExitingBlock) {
1849- LoadInst *CriticalUncountableExitConditionLoad = nullptr ;
1850-
18511849 // Try to find a load in the critical path for the uncountable exit condition.
18521850 // This is currently matching about the simplest form we can, expecting
18531851 // only one in-loop load, the result of which is directly compared against
@@ -1858,10 +1856,12 @@ bool LoopVectorizationLegality::canUncountableExitConditionLoadBeMoved(
18581856 auto *Br = cast<BranchInst>(ExitingBlock->getTerminator ());
18591857
18601858 using namespace llvm ::PatternMatch;
1861- Value *L = nullptr ;
1859+ Instruction *L = nullptr ;
1860+ Value *Ptr = nullptr ;
18621861 Value *R = nullptr ;
18631862 if (!match (Br->getCondition (),
1864- m_OneUse (m_ICmp (m_OneUse (m_Value (L)), (m_Value (R)))))) {
1863+ m_OneUse (m_ICmp (m_OneUse (m_Instruction (L, m_Load (m_Value (Ptr)))),
1864+ m_Value (R))))) {
18651865 reportVectorizationFailure (
18661866 " Early exit loop with store but no supported condition load" ,
18671867 " NoConditionLoadForEarlyExitLoop" , ORE, TheLoop);
@@ -1876,59 +1876,45 @@ bool LoopVectorizationLegality::canUncountableExitConditionLoadBeMoved(
18761876 return false ;
18771877 }
18781878
1879- if (auto *Load = dyn_cast<LoadInst>(L)) {
1880- // Make sure that the load address is not loop invariant; we want an
1881- // address calculation that we can rotate to the next vector iteration.
1882- const SCEV *PtrScev = PSE.getSE ()->getSCEV (Load->getPointerOperand ());
1883- if (PSE.getSE ()->isLoopInvariant (PtrScev, TheLoop)) {
1884- reportVectorizationFailure (
1885- " Uncountable exit condition depends on load from invariant address" ,
1886- " EarlyExitLoadInvariantAddress" , ORE, TheLoop);
1887- return false ;
1888- }
1889-
1890- // The following call also checks that the load address is either
1891- // invariant (which we've just ruled out) or is an affine SCEVAddRecExpr
1892- // with a constant step. In either case, we're not relying on another
1893- // load within the loop.
1894- // FIXME: Support gathers after first-faulting load support lands.
1895- SmallVector<const SCEVPredicate *, 4 > Predicates;
1896- if (!isDereferenceableAndAlignedInLoop (Load, TheLoop, *PSE.getSE (), *DT, AC,
1897- &Predicates)) {
1898- reportVectorizationFailure (
1899- " Loop may fault" ,
1900- " Cannot vectorize potentially faulting early exit loop" ,
1901- " PotentiallyFaultingEarlyExitLoop" , ORE, TheLoop);
1902- return false ;
1903- }
1904-
1905- ICFLoopSafetyInfo SafetyInfo;
1906- SafetyInfo.computeLoopSafetyInfo (TheLoop);
1907- // We need to know that load will be executed before we can hoist a
1908- // copy out to run just before the first iteration.
1909- // FIXME: Currently, other restrictions prevent us from reaching this point
1910- // with a loop where the uncountable exit condition is determined
1911- // by a conditional load.
1912- assert (SafetyInfo.isGuaranteedToExecute (*Load, DT, TheLoop) &&
1913- " Unhandled control flow in uncountable exit loop with side effects" );
1914-
1915- CriticalUncountableExitConditionLoad = Load;
1879+ // Make sure that the load address is not loop invariant; we want an
1880+ // address calculation that we can rotate to the next vector iteration.
1881+ const SCEV *PtrScev = PSE.getSE ()->getSCEV (Ptr);
1882+ if (!isa<SCEVAddRecExpr>(PtrScev)) {
1883+ reportVectorizationFailure (
1884+ " Uncountable exit condition depends on load with an address that is "
1885+ " not an add recurrence" ,
1886+ " EarlyExitLoadInvariantAddress" , ORE, TheLoop);
1887+ return false ;
19161888 }
19171889
1918- if (!CriticalUncountableExitConditionLoad) {
1890+ // FIXME: Support gathers after first-faulting load support lands.
1891+ SmallVector<const SCEVPredicate *, 4 > Predicates;
1892+ LoadInst *Load = cast<LoadInst>(L);
1893+ if (!isDereferenceableAndAlignedInLoop (Load, TheLoop, *PSE.getSE (), *DT, AC,
1894+ &Predicates)) {
19191895 reportVectorizationFailure (
1920- " Early exit loop with store but no supported condition load" ,
1921- " NoConditionLoadForEarlyExitLoop" , ORE, TheLoop);
1896+ " Loop may fault" ,
1897+ " Cannot vectorize potentially faulting early exit loop" ,
1898+ " PotentiallyFaultingEarlyExitLoop" , ORE, TheLoop);
19221899 return false ;
19231900 }
19241901
1902+ ICFLoopSafetyInfo SafetyInfo;
1903+ SafetyInfo.computeLoopSafetyInfo (TheLoop);
1904+ // We need to know that load will be executed before we can hoist a
1905+ // copy out to run just before the first iteration.
1906+ // FIXME: Currently, other restrictions prevent us from reaching this point
1907+ // with a loop where the uncountable exit condition is determined
1908+ // by a conditional load.
1909+ assert (SafetyInfo.isGuaranteedToExecute (*Load, DT, TheLoop) &&
1910+ " Unhandled control flow in uncountable exit loop with side effects" );
1911+
19251912 // Prohibit any potential aliasing with any instruction in the loop which
19261913 // might store to memory.
19271914 // FIXME: Relax this constraint where possible.
1928- Value *Ptr = CriticalUncountableExitConditionLoad->getPointerOperand ();
19291915 for (auto *BB : TheLoop->blocks ()) {
19301916 for (auto &I : *BB) {
1931- if (&I == CriticalUncountableExitConditionLoad )
1917+ if (&I == Load )
19321918 continue ;
19331919
19341920 if (I.mayWriteToMemory ()) {
0 commit comments