Skip to content

Commit 2e9a43a

Browse files
committed
[LAA] Document reasoning in multiple places in isDependent (NFC).
As suggested in #88039, add extra documentation for reasoning in isDependent.
1 parent 2e68ba9 commit 2e9a43a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)