diff options
author | Ramkumar Ramachandra <ramkumar.ramachandra@codasip.com> | 2024-11-28 16:15:45 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-28 16:15:45 +0000 |
commit | aa5cdcea3950b26a6b755201706bb1961e65eaa5 (patch) | |
tree | a48c8e3cb537b06d2087f79f58607e560db4b55b /llvm/lib/Analysis/LoopAccessAnalysis.cpp | |
parent | 26fd693b979f17c83cbd5a3313fdea950ce3d356 (diff) | |
download | llvm-aa5cdcea3950b26a6b755201706bb1961e65eaa5.zip llvm-aa5cdcea3950b26a6b755201706bb1961e65eaa5.tar.gz llvm-aa5cdcea3950b26a6b755201706bb1961e65eaa5.tar.bz2 |
LAA: improve code in a couple of routines (NFC) (#108092)
Diffstat (limited to 'llvm/lib/Analysis/LoopAccessAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/LoopAccessAnalysis.cpp | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp index 907bb78..71582d5 100644 --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -1978,13 +1978,12 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize( << " Sink induction step: " << StrideBPtrInt << "\n"); // At least Src or Sink are loop invariant and the other is strided or // invariant. We can generate a runtime check to disambiguate the accesses. - if (StrideAPtrInt == 0 || StrideBPtrInt == 0) + if (!StrideAPtrInt || !StrideBPtrInt) return MemoryDepChecker::Dependence::Unknown; // Both Src and Sink have a constant stride, check if they are in the same // direction. - if ((StrideAPtrInt > 0 && StrideBPtrInt < 0) || - (StrideAPtrInt < 0 && StrideBPtrInt > 0)) { + if ((StrideAPtrInt > 0) != (StrideBPtrInt > 0)) { LLVM_DEBUG( dbgs() << "Pointer access with strides in different directions\n"); return MemoryDepChecker::Dependence::Unknown; @@ -2040,19 +2039,16 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx, *Dist, MaxStride, TypeByteSize)) return Dependence::NoDep; - const SCEVConstant *C = dyn_cast<SCEVConstant>(Dist); + const SCEVConstant *ConstDist = dyn_cast<SCEVConstant>(Dist); // Attempt to prove strided accesses independent. - if (C) { - const APInt &Val = C->getAPInt(); - int64_t Distance = Val.getSExtValue(); + if (ConstDist) { + uint64_t Distance = ConstDist->getAPInt().abs().getZExtValue(); // If the distance between accesses and their strides are known constants, // check whether the accesses interlace each other. - if (std::abs(Distance) > 0 && CommonStride && *CommonStride > 1 && - HasSameSize && - areStridedAccessesIndependent(std::abs(Distance), *CommonStride, - TypeByteSize)) { + if (Distance > 0 && CommonStride && CommonStride > 1 && HasSameSize && + areStridedAccessesIndependent(Distance, *CommonStride, TypeByteSize)) { LLVM_DEBUG(dbgs() << "LAA: Strided accesses are independent\n"); return Dependence::NoDep; } @@ -2085,7 +2081,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx, // forward dependency will allow vectorization using any width. if (IsTrueDataDependence && EnableForwardingConflictDetection) { - if (!C) { + 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 @@ -2094,8 +2090,8 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx, return Dependence::Unknown; } if (!HasSameSize || - couldPreventStoreLoadForward(C->getAPInt().abs().getZExtValue(), - TypeByteSize)) { + couldPreventStoreLoadForward( + ConstDist->getAPInt().abs().getZExtValue(), TypeByteSize)) { LLVM_DEBUG( dbgs() << "LAA: Forward but may prevent st->ld forwarding\n"); return Dependence::ForwardButPreventsForwarding; @@ -2113,7 +2109,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx, return Dependence::Unknown; } - if (!isa<SCEVConstant>(Dist)) { + 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 @@ -2175,7 +2171,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx, uint64_t MinDistanceNeeded = TypeByteSize * *CommonStride * (MinNumIter - 1) + TypeByteSize; if (MinDistanceNeeded > static_cast<uint64_t>(MinDistance)) { - if (!isa<SCEVConstant>(Dist)) { + if (!ConstDist) { // For non-constant distances, we checked the lower bound of the // dependence distance and the distance may be larger at runtime (and safe // for vectorization). Classify it as Unknown, so we re-try with runtime @@ -2216,8 +2212,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx, bool IsTrueDataDependence = (!AIsWrite && BIsWrite); uint64_t MinDepDistBytesOld = MinDepDistBytes; - if (IsTrueDataDependence && EnableForwardingConflictDetection && - isa<SCEVConstant>(Dist) && + if (IsTrueDataDependence && EnableForwardingConflictDetection && ConstDist && couldPreventStoreLoadForward(MinDistance, TypeByteSize)) { // Sanity check that we didn't update MinDepDistBytes when calling // couldPreventStoreLoadForward @@ -2235,7 +2230,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx, << " with max VF = " << MaxVF << '\n'); uint64_t MaxVFInBits = MaxVF * TypeByteSize * 8; - if (!isa<SCEVConstant>(Dist) && MaxVFInBits < MaxTargetVectorWidthInBits) { + if (!ConstDist && MaxVFInBits < MaxTargetVectorWidthInBits) { // For non-constant distances, we checked the lower bound of the dependence // distance and the distance may be larger at runtime (and safe for // vectorization). Classify it as Unknown, so we re-try with runtime checks. |