@@ -1994,8 +1994,23 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
19941994 DL.getTypeStoreSizeInBits (ATy) == DL.getTypeStoreSizeInBits (BTy);
19951995 if (!HasSameSize)
19961996 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,
19992014 AIsWrite, BIsWrite);
20002015}
20012016
@@ -2011,23 +2026,21 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
20112026 if (std::holds_alternative<Dependence::DepType>(Res))
20122027 return std::get<Dependence::DepType>(Res);
20132028
2014- auto &[Dist, StrideA, StrideB, TypeByteSize, AIsWrite, BIsWrite] =
2029+ auto &[Dist, MaxStride, CommonStride, ShouldRetryWithRuntimeCheck,
2030+ TypeByteSize, AIsWrite, BIsWrite] =
20152031 std::get<DepDistanceStrideAndSizeInfo>(Res);
20162032 bool HasSameSize = TypeByteSize > 0 ;
20172033
2018- std::optional<uint64_t > CommonStride =
2019- StrideA == StrideB ? std::make_optional (StrideA) : std::nullopt ;
20202034 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 ;
20242038 LLVM_DEBUG (dbgs () << " LAA: Dependence because of uncomputable distance.\n " );
20252039 return Dependence::Unknown;
20262040 }
20272041
20282042 ScalarEvolution &SE = *PSE.getSE ();
20292043 auto &DL = InnermostLoop->getHeader ()->getDataLayout ();
2030- uint64_t MaxStride = std::max (StrideA, StrideB);
20312044
20322045 // If the distance between the acecsses is larger than their maximum absolute
20332046 // stride multiplied by the symbolic maximum backedge taken count (which is an
@@ -2086,7 +2099,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
20862099 // condition to consider retrying with runtime checks. Historically, we
20872100 // did not set it when strides were different but there is no inherent
20882101 // reason to.
2089- FoundNonConstantDistanceDependence |= CommonStride. has_value () ;
2102+ FoundNonConstantDistanceDependence |= ShouldRetryWithRuntimeCheck ;
20902103 return Dependence::Unknown;
20912104 }
20922105 if (!HasSameSize ||
@@ -2105,7 +2118,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
21052118 int64_t MinDistance = SE.getSignedRangeMin (Dist).getSExtValue ();
21062119 // Below we only handle strictly positive distances.
21072120 if (MinDistance <= 0 ) {
2108- FoundNonConstantDistanceDependence |= CommonStride. has_value () ;
2121+ FoundNonConstantDistanceDependence |= ShouldRetryWithRuntimeCheck ;
21092122 return Dependence::Unknown;
21102123 }
21112124
@@ -2118,7 +2131,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
21182131 // condition to consider retrying with runtime checks. Historically, we
21192132 // did not set it when strides were different but there is no inherent
21202133 // reason to.
2121- FoundNonConstantDistanceDependence |= CommonStride. has_value () ;
2134+ FoundNonConstantDistanceDependence |= ShouldRetryWithRuntimeCheck ;
21222135 }
21232136
21242137 if (!HasSameSize) {
0 commit comments