-
Notifications
You must be signed in to change notification settings - Fork 14.4k
LAA: improve code in a couple of routines (NFC) #108092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-analysis Author: Ramkumar Ramachandra (artagnon) ChangesFull diff: https://github.com/llvm/llvm-project/pull/108092.diff 1 Files Affected:
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 980f142f113265..9db979b542dfde 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -1976,13 +1976,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;
@@ -2038,19 +2037,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) {
+ int64_t Distance = std::abs(ConstDist->getAPInt().getSExtValue());
// 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;
}
@@ -2083,7 +2079,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
@@ -2092,8 +2088,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;
@@ -2111,7 +2107,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
@@ -2173,7 +2169,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
@@ -2214,8 +2210,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
@@ -2233,7 +2228,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.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I added one minor suggestion, but I don't feel too strongly about it.
c05eb70
to
9db56bd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
No description provided.