@@ -2034,6 +2034,10 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
20342034
20352035 ScalarEvolution &SE = *PSE.getSE ();
20362036 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.
20372041 if (!isa<SCEVCouldNotCompute>(Dist) && HasSameSize &&
20382042 isSafeDependenceDistance (DL, SE, *(PSE.getBackedgeTakenCount ()), *Dist,
20392043 Stride, TypeByteSize))
@@ -2049,7 +2053,8 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
20492053 const APInt &Val = C->getAPInt ();
20502054 int64_t Distance = Val.getSExtValue ();
20512055
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.
20532058 if (std::abs (Distance) > 0 && Stride > 1 && HasSameSize &&
20542059 areStridedAccessesIndependent (std::abs (Distance), Stride, TypeByteSize)) {
20552060 LLVM_DEBUG (dbgs () << " LAA: Strided accesses are independent\n " );
@@ -2059,9 +2064,13 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
20592064 // Negative distances are not plausible dependencies.
20602065 if (Val.isNegative ()) {
20612066 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.
20652074 if (IsTrueDataDependence && EnableForwardingConflictDetection &&
20662075 (!HasSameSize || couldPreventStoreLoadForward (Val.abs ().getZExtValue (),
20672076 TypeByteSize))) {
0 commit comments