@@ -2034,6 +2034,10 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
2034
2034
2035
2035
ScalarEvolution &SE = *PSE.getSE ();
2036
2036
auto &DL = InnermostLoop->getHeader ()->getModule ()->getDataLayout ();
2037
+ // If the distance between the acecsses is larger than their absolute stride
2038
+ // multiplied by the backedge taken count, 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.
2037
2041
if (!isa<SCEVCouldNotCompute>(Dist) && HasSameSize &&
2038
2042
isSafeDependenceDistance (DL, SE, *(PSE.getBackedgeTakenCount ()), *Dist,
2039
2043
Stride, TypeByteSize))
@@ -2049,7 +2053,8 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
2049
2053
const APInt &Val = C->getAPInt ();
2050
2054
int64_t Distance = Val.getSExtValue ();
2051
2055
2052
- // Attempt to prove strided accesses independent.
2056
+ // If the distance between accesses and their strides are known constants,
2057
+ // check whether the accesses interlace each other.
2053
2058
if (std::abs (Distance) > 0 && Stride > 1 && HasSameSize &&
2054
2059
areStridedAccessesIndependent (std::abs (Distance), Stride, TypeByteSize)) {
2055
2060
LLVM_DEBUG (dbgs () << " LAA: Strided accesses are independent\n " );
@@ -2059,9 +2064,13 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
2059
2064
// Negative distances are not plausible dependencies.
2060
2065
if (Val.isNegative ()) {
2061
2066
bool IsTrueDataDependence = (AIsWrite && !BIsWrite);
2062
- // There is no need to update MaxSafeVectorWidthInBits after call to
2063
- // couldPreventStoreLoadForward, even if it changed MinDepDistBytes,
2064
- // since a forward dependency will allow vectorization using any width.
2067
+ // Check if the first access writes to a location that is read in a later
2068
+ // iteration, where the distance between them is not a multiple of a vector
2069
+ // factor and relatively small.
2070
+ //
2071
+ // NOTE: There is no need to update MaxSafeVectorWidthInBits after call to
2072
+ // couldPreventStoreLoadForward, even if it changed MinDepDistBytes, since a
2073
+ // forward dependency will allow vectorization using any width.
2065
2074
if (IsTrueDataDependence && EnableForwardingConflictDetection &&
2066
2075
(!HasSameSize || couldPreventStoreLoadForward (Val.abs ().getZExtValue (),
2067
2076
TypeByteSize))) {
0 commit comments