@@ -214,7 +214,7 @@ getStartAndEndForAccess(const Loop *Lp, const SCEV *PtrExpr, Type *AccessTy,
214
214
if (SE->isLoopInvariant (PtrExpr, Lp)) {
215
215
ScStart = ScEnd = PtrExpr;
216
216
} else if (auto *AR = dyn_cast<SCEVAddRecExpr>(PtrExpr)) {
217
- const SCEV *Ex = PSE.getBackedgeTakenCount ();
217
+ const SCEV *Ex = PSE.getSymbolicMaxBackedgeTakenCount ();
218
218
219
219
ScStart = AR->getStart ();
220
220
ScEnd = AR->evaluateAtIteration (Ex, *SE);
@@ -1796,28 +1796,28 @@ void MemoryDepChecker::mergeInStatus(VectorizationSafetyStatus S) {
1796
1796
// / Given a dependence-distance \p Dist between two
1797
1797
// / memory accesses, that have strides in the same direction whose absolute
1798
1798
// / value of the maximum stride is given in \p MaxStride, and that have the same
1799
- // / type size \p TypeByteSize, in a loop whose takenCount is \p
1800
- // / BackedgeTakenCount , check if it is possible to prove statically that the
1801
- // / dependence distance is larger than the range that the accesses will travel
1802
- // / through the execution of the loop. If so, return true; false otherwise. This
1803
- // / is useful for example in loops such as the following (PR31098):
1799
+ // / type size \p TypeByteSize, in a loop whose maximum backedge taken count is
1800
+ // / \p MaxBTC , check if it is possible to prove statically that the dependence
1801
+ // / distance is larger than the range that the accesses will travel through the
1802
+ // / execution of the loop. If so, return true; false otherwise. This is useful
1803
+ // / for example in loops such as the following (PR31098):
1804
1804
// / for (i = 0; i < D; ++i) {
1805
1805
// / = out[i];
1806
1806
// / out[i+D] =
1807
1807
// / }
1808
1808
static bool isSafeDependenceDistance (const DataLayout &DL, ScalarEvolution &SE,
1809
- const SCEV &BackedgeTakenCount ,
1810
- const SCEV &Dist, uint64_t MaxStride,
1809
+ const SCEV &MaxBTC, const SCEV &Dist ,
1810
+ uint64_t MaxStride,
1811
1811
uint64_t TypeByteSize) {
1812
1812
1813
1813
// If we can prove that
1814
- // (**) |Dist| > BackedgeTakenCount * Step
1814
+ // (**) |Dist| > MaxBTC * Step
1815
1815
// where Step is the absolute stride of the memory accesses in bytes,
1816
1816
// then there is no dependence.
1817
1817
//
1818
1818
// Rationale:
1819
1819
// We basically want to check if the absolute distance (|Dist/Step|)
1820
- // is >= the loop iteration count (or > BackedgeTakenCount ).
1820
+ // is >= the loop iteration count (or > MaxBTC ).
1821
1821
// This is equivalent to the Strong SIV Test (Practical Dependence Testing,
1822
1822
// Section 4.2.1); Note, that for vectorization it is sufficient to prove
1823
1823
// that the dependence distance is >= VF; This is checked elsewhere.
@@ -1828,8 +1828,8 @@ static bool isSafeDependenceDistance(const DataLayout &DL, ScalarEvolution &SE,
1828
1828
// also guarantees that distance >= VF.
1829
1829
//
1830
1830
const uint64_t ByteStride = MaxStride * TypeByteSize;
1831
- const SCEV *Step = SE.getConstant (BackedgeTakenCount .getType (), ByteStride);
1832
- const SCEV *Product = SE.getMulExpr (&BackedgeTakenCount , Step);
1831
+ const SCEV *Step = SE.getConstant (MaxBTC .getType (), ByteStride);
1832
+ const SCEV *Product = SE.getMulExpr (&MaxBTC , Step);
1833
1833
1834
1834
const SCEV *CastedDist = &Dist;
1835
1835
const SCEV *CastedProduct = Product;
@@ -1844,13 +1844,13 @@ static bool isSafeDependenceDistance(const DataLayout &DL, ScalarEvolution &SE,
1844
1844
else
1845
1845
CastedDist = SE.getNoopOrSignExtend (&Dist, Product->getType ());
1846
1846
1847
- // Is Dist - (BackedgeTakenCount * Step) > 0 ?
1847
+ // Is Dist - (MaxBTC * Step) > 0 ?
1848
1848
// (If so, then we have proven (**) because |Dist| >= Dist)
1849
1849
const SCEV *Minus = SE.getMinusSCEV (CastedDist, CastedProduct);
1850
1850
if (SE.isKnownPositive (Minus))
1851
1851
return true ;
1852
1852
1853
- // Second try: Is -Dist - (BackedgeTakenCount * Step) > 0 ?
1853
+ // Second try: Is -Dist - (MaxBTC * Step) > 0 ?
1854
1854
// (If so, then we have proven (**) because |Dist| >= -1*Dist)
1855
1855
const SCEV *NegDist = SE.getNegativeSCEV (CastedDist);
1856
1856
Minus = SE.getMinusSCEV (NegDist, CastedProduct);
@@ -2034,12 +2034,13 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
2034
2034
uint64_t MaxStride = std::max (StrideA, StrideB);
2035
2035
2036
2036
// If the distance between the acecsses is larger than their maximum absolute
2037
- // stride multiplied by the backedge taken count, the accesses are independet,
2038
- // i.e. they are far enough appart that accesses won't access the same
2039
- // location across all loop ierations.
2040
- if (HasSameSize &&
2041
- isSafeDependenceDistance (DL, SE, *(PSE.getBackedgeTakenCount ()), *Dist,
2042
- MaxStride, TypeByteSize))
2037
+ // stride multiplied by the symbolic maximum backedge taken count (which is an
2038
+ // upper bound of the number of iterations), the accesses are independet, i.e.
2039
+ // they are far enough appart that accesses won't access the same location
2040
+ // across all loop ierations.
2041
+ if (HasSameSize && isSafeDependenceDistance (
2042
+ DL, SE, *(PSE.getSymbolicMaxBackedgeTakenCount ()),
2043
+ *Dist, MaxStride, TypeByteSize))
2043
2044
return Dependence::NoDep;
2044
2045
2045
2046
const SCEVConstant *C = dyn_cast<SCEVConstant>(Dist);
@@ -2374,8 +2375,10 @@ bool LoopAccessInfo::canAnalyzeLoop() {
2374
2375
return false ;
2375
2376
}
2376
2377
2377
- // ScalarEvolution needs to be able to find the exit count.
2378
- const SCEV *ExitCount = PSE->getBackedgeTakenCount ();
2378
+ // ScalarEvolution needs to be able to find the symbolic max backedge taken
2379
+ // count, which is an upper bound on the number of loop iterations. The loop
2380
+ // may execute fewer iterations, if it exits via an uncountable exit.
2381
+ const SCEV *ExitCount = PSE->getSymbolicMaxBackedgeTakenCount ();
2379
2382
if (isa<SCEVCouldNotCompute>(ExitCount)) {
2380
2383
recordAnalysis (" CantComputeNumberOfIterations" )
2381
2384
<< " could not determine number of loop iterations" ;
@@ -2984,25 +2987,25 @@ void LoopAccessInfo::collectStridedAccess(Value *MemAccess) {
2984
2987
// of various possible stride specializations, considering the alternatives
2985
2988
// of using gather/scatters (if available).
2986
2989
2987
- const SCEV *BETakenCount = PSE->getBackedgeTakenCount ();
2990
+ const SCEV *MaxBTC = PSE->getSymbolicMaxBackedgeTakenCount ();
2988
2991
2989
- // Match the types so we can compare the stride and the BETakenCount .
2992
+ // Match the types so we can compare the stride and the MaxBTC .
2990
2993
// The Stride can be positive/negative, so we sign extend Stride;
2991
- // The backedgeTakenCount is non-negative, so we zero extend BETakenCount .
2994
+ // The backedgeTakenCount is non-negative, so we zero extend MaxBTC .
2992
2995
const DataLayout &DL = TheLoop->getHeader ()->getModule ()->getDataLayout ();
2993
2996
uint64_t StrideTypeSizeBits = DL.getTypeSizeInBits (StrideExpr->getType ());
2994
- uint64_t BETypeSizeBits = DL.getTypeSizeInBits (BETakenCount ->getType ());
2997
+ uint64_t BETypeSizeBits = DL.getTypeSizeInBits (MaxBTC ->getType ());
2995
2998
const SCEV *CastedStride = StrideExpr;
2996
- const SCEV *CastedBECount = BETakenCount ;
2999
+ const SCEV *CastedBECount = MaxBTC ;
2997
3000
ScalarEvolution *SE = PSE->getSE ();
2998
3001
if (BETypeSizeBits >= StrideTypeSizeBits)
2999
- CastedStride = SE->getNoopOrSignExtend (StrideExpr, BETakenCount ->getType ());
3002
+ CastedStride = SE->getNoopOrSignExtend (StrideExpr, MaxBTC ->getType ());
3000
3003
else
3001
- CastedBECount = SE->getZeroExtendExpr (BETakenCount , StrideExpr->getType ());
3004
+ CastedBECount = SE->getZeroExtendExpr (MaxBTC , StrideExpr->getType ());
3002
3005
const SCEV *StrideMinusBETaken = SE->getMinusSCEV (CastedStride, CastedBECount);
3003
3006
// Since TripCount == BackEdgeTakenCount + 1, checking:
3004
3007
// "Stride >= TripCount" is equivalent to checking:
3005
- // Stride - BETakenCount > 0
3008
+ // Stride - MaxBTC > 0
3006
3009
if (SE->isKnownPositive (StrideMinusBETaken)) {
3007
3010
LLVM_DEBUG (
3008
3011
dbgs () << " LAA: Stride>=TripCount; No point in versioning as the "
0 commit comments