@@ -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);
@@ -2057,9 +2057,10 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
2057
2057
uint64_t MaxStride = std::max (StrideA, StrideB);
2058
2058
2059
2059
// If the distance between the acecsses is larger than their maximum absolute
2060
- // stride multiplied by the backedge taken count, the accesses are independet,
2061
- // i.e. they are far enough appart that accesses won't access the same
2062
- // location across all loop ierations.
2060
+ // stride multiplied by the symbolic maximum backedge taken count (which is an
2061
+ // upper bound of the number of iterations), the accesses are independet, i.e.
2062
+ // they are far enough appart that accesses won't access the same location
2063
+ // across all loop ierations.
2063
2064
if (HasSameSize && isSafeDependenceDistance (
2064
2065
DL, SE, *(PSE.getSymbolicMaxBackedgeTakenCount ()),
2065
2066
*Dist, MaxStride, TypeByteSize))
@@ -2399,7 +2400,9 @@ bool LoopAccessInfo::canAnalyzeLoop() {
2399
2400
return false ;
2400
2401
}
2401
2402
2402
- // ScalarEvolution needs to be able to find the exit count.
2403
+ // ScalarEvolution needs to be able to find the symbolic max backedge taken
2404
+ // count, which is an upper bound on the number of loop iterations. The loop
2405
+ // may execute fewer iterations, if it exits via an uncountable exit.
2403
2406
const SCEV *ExitCount = PSE->getSymbolicMaxBackedgeTakenCount ();
2404
2407
if (isa<SCEVCouldNotCompute>(ExitCount)) {
2405
2408
recordAnalysis (" CantComputeNumberOfIterations" )
@@ -3009,25 +3012,25 @@ void LoopAccessInfo::collectStridedAccess(Value *MemAccess) {
3009
3012
// of various possible stride specializations, considering the alternatives
3010
3013
// of using gather/scatters (if available).
3011
3014
3012
- const SCEV *BETakenCount = PSE->getSymbolicMaxBackedgeTakenCount ();
3015
+ const SCEV *MaxBTC = PSE->getSymbolicMaxBackedgeTakenCount ();
3013
3016
3014
- // Match the types so we can compare the stride and the BETakenCount .
3017
+ // Match the types so we can compare the stride and the MaxBTC .
3015
3018
// The Stride can be positive/negative, so we sign extend Stride;
3016
- // The backedgeTakenCount is non-negative, so we zero extend BETakenCount .
3019
+ // The backedgeTakenCount is non-negative, so we zero extend MaxBTC .
3017
3020
const DataLayout &DL = TheLoop->getHeader ()->getModule ()->getDataLayout ();
3018
3021
uint64_t StrideTypeSizeBits = DL.getTypeSizeInBits (StrideExpr->getType ());
3019
- uint64_t BETypeSizeBits = DL.getTypeSizeInBits (BETakenCount ->getType ());
3022
+ uint64_t BETypeSizeBits = DL.getTypeSizeInBits (MaxBTC ->getType ());
3020
3023
const SCEV *CastedStride = StrideExpr;
3021
- const SCEV *CastedBECount = BETakenCount ;
3024
+ const SCEV *CastedBECount = MaxBTC ;
3022
3025
ScalarEvolution *SE = PSE->getSE ();
3023
3026
if (BETypeSizeBits >= StrideTypeSizeBits)
3024
- CastedStride = SE->getNoopOrSignExtend (StrideExpr, BETakenCount ->getType ());
3027
+ CastedStride = SE->getNoopOrSignExtend (StrideExpr, MaxBTC ->getType ());
3025
3028
else
3026
- CastedBECount = SE->getZeroExtendExpr (BETakenCount , StrideExpr->getType ());
3029
+ CastedBECount = SE->getZeroExtendExpr (MaxBTC , StrideExpr->getType ());
3027
3030
const SCEV *StrideMinusBETaken = SE->getMinusSCEV (CastedStride, CastedBECount);
3028
3031
// Since TripCount == BackEdgeTakenCount + 1, checking:
3029
3032
// "Stride >= TripCount" is equivalent to checking:
3030
- // Stride - BETakenCount > 0
3033
+ // Stride - MaxBTC > 0
3031
3034
if (SE->isKnownPositive (StrideMinusBETaken)) {
3032
3035
LLVM_DEBUG (
3033
3036
dbgs () << " LAA: Stride>=TripCount; No point in versioning as the "
0 commit comments