diff options
author | Ramkumar Ramachandra <ramkumar.ramachandra@codasip.com> | 2025-07-07 12:02:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-07 12:02:41 +0100 |
commit | fb845f93c003e6696d4741f4825541a2c0867c42 (patch) | |
tree | 9d52ed4af9a4755d621e10fda0858a97ec9dd0cd /llvm/lib/Analysis/LoopAccessAnalysis.cpp | |
parent | e7bcd3f7c743d6e10d26540a8d58648be5a95304 (diff) | |
download | llvm-fb845f93c003e6696d4741f4825541a2c0867c42.zip llvm-fb845f93c003e6696d4741f4825541a2c0867c42.tar.gz llvm-fb845f93c003e6696d4741f4825541a2c0867c42.tar.bz2 |
[LAA] Hoist setting condition for RT-checks (#128045)
Strip ShouldRetyWithRuntimeCheck from the
DepedenceDistanceStrideAndSizeInfo struct, and free isDependent from the
responsibility of setting the condition for when runtime-checks are
needed, transferring this responsibility to
getDependenceDistanceStrideAndSize.
We can have multiple DepType::Unknown dependences that, by themselves,
do not trigger the retrying with runtime memory checks, and therefore
block vectorization. But once a single
FoundNonConstantDistanceDependence is found, the analysis seems to
switch to the "LAA: Retrying with memory checks" path and allows all
these dependences to be handled via runtime checks. There is hence no
rationale for predicating FoundNonConstantDependenceDistance on
DepType::Unknown, and removing this predication is one of the
side-effects of this patch.
Diffstat (limited to 'llvm/lib/Analysis/LoopAccessAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/LoopAccessAnalysis.cpp | 42 |
1 files changed, 9 insertions, 33 deletions
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp index 007ee3c..b6dc5c4 100644 --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -2081,14 +2081,14 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize( if (StrideAScaled == StrideBScaled) CommonStride = StrideAScaled; - // TODO: Historically, we don't retry with runtime checks unless the - // (unscaled) strides are the same. Fix this once the condition for runtime - // checks in isDependent is fixed. - bool ShouldRetryWithRuntimeCheck = StrideAPtrInt == StrideBPtrInt; + // TODO: FoundNonConstantDistanceDependence is used as a necessary condition + // to consider retrying with runtime checks. Historically, we did not set it + // when (unscaled) strides were different but there is no inherent reason to. + if (!isa<SCEVConstant>(Dist)) + FoundNonConstantDistanceDependence |= StrideAPtrInt == StrideBPtrInt; return DepDistanceStrideAndSizeInfo(Dist, MaxStride, CommonStride, - ShouldRetryWithRuntimeCheck, TypeByteSize, - AIsWrite, BIsWrite); + TypeByteSize, AIsWrite, BIsWrite); } MemoryDepChecker::Dependence::DepType @@ -2103,15 +2103,11 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx, if (std::holds_alternative<Dependence::DepType>(Res)) return std::get<Dependence::DepType>(Res); - auto &[Dist, MaxStride, CommonStride, ShouldRetryWithRuntimeCheck, - TypeByteSize, AIsWrite, BIsWrite] = + auto &[Dist, MaxStride, CommonStride, TypeByteSize, AIsWrite, BIsWrite] = std::get<DepDistanceStrideAndSizeInfo>(Res); bool HasSameSize = TypeByteSize > 0; if (isa<SCEVCouldNotCompute>(Dist)) { - // TODO: Relax requirement that there is a common unscaled stride to retry - // with non-constant distance dependencies. - FoundNonConstantDistanceDependence |= ShouldRetryWithRuntimeCheck; LLVM_DEBUG(dbgs() << "LAA: Dependence because of uncomputable distance.\n"); return Dependence::Unknown; } @@ -2173,14 +2169,8 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx, // forward dependency will allow vectorization using any width. if (IsTrueDataDependence && EnableForwardingConflictDetection) { - if (!ConstDist) { - // TODO: FoundNonConstantDistanceDependence is used as a necessary - // condition to consider retrying with runtime checks. Historically, we - // did not set it when strides were different but there is no inherent - // reason to. - FoundNonConstantDistanceDependence |= ShouldRetryWithRuntimeCheck; + if (!ConstDist) return Dependence::Unknown; - } if (!HasSameSize || couldPreventStoreLoadForward(ConstDist, TypeByteSize)) { LLVM_DEBUG( @@ -2195,22 +2185,8 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx, int64_t MinDistance = SE.getSignedRangeMin(Dist).getSExtValue(); // Below we only handle strictly positive distances. - if (MinDistance <= 0) { - FoundNonConstantDistanceDependence |= ShouldRetryWithRuntimeCheck; + if (MinDistance <= 0) return Dependence::Unknown; - } - - if (!ConstDist) { - // Previously this case would be treated as Unknown, possibly setting - // FoundNonConstantDistanceDependence to force re-trying with runtime - // checks. Until the TODO below is addressed, set it here to preserve - // original behavior w.r.t. re-trying with runtime checks. - // TODO: FoundNonConstantDistanceDependence is used as a necessary - // condition to consider retrying with runtime checks. Historically, we - // did not set it when strides were different but there is no inherent - // reason to. - FoundNonConstantDistanceDependence |= ShouldRetryWithRuntimeCheck; - } if (!HasSameSize) { LLVM_DEBUG(dbgs() << "LAA: ReadWrite-Write positive dependency with " |