@@ -1994,8 +1994,23 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
1994
1994
DL.getTypeStoreSizeInBits (ATy) == DL.getTypeStoreSizeInBits (BTy);
1995
1995
if (!HasSameSize)
1996
1996
TypeByteSize = 0 ;
1997
- return DepDistanceStrideAndSizeInfo (Dist, std::abs (StrideAPtrInt),
1998
- std::abs (StrideBPtrInt), TypeByteSize,
1997
+
1998
+ StrideAPtrInt = std::abs (StrideAPtrInt);
1999
+ StrideBPtrInt = std::abs (StrideBPtrInt);
2000
+
2001
+ uint64_t MaxStride = std::max (StrideAPtrInt, StrideBPtrInt);
2002
+
2003
+ std::optional<uint64_t > CommonStride;
2004
+ if (StrideAPtrInt == StrideBPtrInt)
2005
+ CommonStride = StrideAPtrInt;
2006
+
2007
+ // TODO: Historically, we don't retry with runtime checks unless the
2008
+ // (unscaled) strides are the same. Fix this once the condition for runtime
2009
+ // checks in isDependent is fixed.
2010
+ bool ShouldRetryWithRuntimeCheck = CommonStride.has_value ();
2011
+
2012
+ return DepDistanceStrideAndSizeInfo (Dist, MaxStride, CommonStride,
2013
+ ShouldRetryWithRuntimeCheck, TypeByteSize,
1999
2014
AIsWrite, BIsWrite);
2000
2015
}
2001
2016
@@ -2011,23 +2026,21 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2011
2026
if (std::holds_alternative<Dependence::DepType>(Res))
2012
2027
return std::get<Dependence::DepType>(Res);
2013
2028
2014
- auto &[Dist, StrideA, StrideB, TypeByteSize, AIsWrite, BIsWrite] =
2029
+ auto &[Dist, MaxStride, CommonStride, ShouldRetryWithRuntimeCheck,
2030
+ TypeByteSize, AIsWrite, BIsWrite] =
2015
2031
std::get<DepDistanceStrideAndSizeInfo>(Res);
2016
2032
bool HasSameSize = TypeByteSize > 0 ;
2017
2033
2018
- std::optional<uint64_t > CommonStride =
2019
- StrideA == StrideB ? std::make_optional (StrideA) : std::nullopt;
2020
2034
if (isa<SCEVCouldNotCompute>(Dist)) {
2021
- // TODO: Relax requirement that there is a common stride to retry with
2022
- // non-constant distance dependencies.
2023
- FoundNonConstantDistanceDependence |= CommonStride. has_value () ;
2035
+ // TODO: Relax requirement that there is a common unscaled stride to retry
2036
+ // with non-constant distance dependencies.
2037
+ FoundNonConstantDistanceDependence |= ShouldRetryWithRuntimeCheck ;
2024
2038
LLVM_DEBUG (dbgs () << " LAA: Dependence because of uncomputable distance.\n " );
2025
2039
return Dependence::Unknown;
2026
2040
}
2027
2041
2028
2042
ScalarEvolution &SE = *PSE.getSE ();
2029
2043
auto &DL = InnermostLoop->getHeader ()->getDataLayout ();
2030
- uint64_t MaxStride = std::max (StrideA, StrideB);
2031
2044
2032
2045
// If the distance between the acecsses is larger than their maximum absolute
2033
2046
// stride multiplied by the symbolic maximum backedge taken count (which is an
@@ -2086,7 +2099,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2086
2099
// condition to consider retrying with runtime checks. Historically, we
2087
2100
// did not set it when strides were different but there is no inherent
2088
2101
// reason to.
2089
- FoundNonConstantDistanceDependence |= CommonStride. has_value () ;
2102
+ FoundNonConstantDistanceDependence |= ShouldRetryWithRuntimeCheck ;
2090
2103
return Dependence::Unknown;
2091
2104
}
2092
2105
if (!HasSameSize ||
@@ -2105,7 +2118,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2105
2118
int64_t MinDistance = SE.getSignedRangeMin (Dist).getSExtValue ();
2106
2119
// Below we only handle strictly positive distances.
2107
2120
if (MinDistance <= 0 ) {
2108
- FoundNonConstantDistanceDependence |= CommonStride. has_value () ;
2121
+ FoundNonConstantDistanceDependence |= ShouldRetryWithRuntimeCheck ;
2109
2122
return Dependence::Unknown;
2110
2123
}
2111
2124
@@ -2118,7 +2131,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2118
2131
// condition to consider retrying with runtime checks. Historically, we
2119
2132
// did not set it when strides were different but there is no inherent
2120
2133
// reason to.
2121
- FoundNonConstantDistanceDependence |= CommonStride. has_value () ;
2134
+ FoundNonConstantDistanceDependence |= ShouldRetryWithRuntimeCheck ;
2122
2135
}
2123
2136
2124
2137
if (!HasSameSize) {
0 commit comments