Skip to content

Commit aa5cdce

Browse files
authored
LAA: improve code in a couple of routines (NFC) (llvm#108092)
1 parent 26fd693 commit aa5cdce

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,13 +1978,12 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
19781978
<< " Sink induction step: " << StrideBPtrInt << "\n");
19791979
// At least Src or Sink are loop invariant and the other is strided or
19801980
// invariant. We can generate a runtime check to disambiguate the accesses.
1981-
if (StrideAPtrInt == 0 || StrideBPtrInt == 0)
1981+
if (!StrideAPtrInt || !StrideBPtrInt)
19821982
return MemoryDepChecker::Dependence::Unknown;
19831983

19841984
// Both Src and Sink have a constant stride, check if they are in the same
19851985
// direction.
1986-
if ((StrideAPtrInt > 0 && StrideBPtrInt < 0) ||
1987-
(StrideAPtrInt < 0 && StrideBPtrInt > 0)) {
1986+
if ((StrideAPtrInt > 0) != (StrideBPtrInt > 0)) {
19881987
LLVM_DEBUG(
19891988
dbgs() << "Pointer access with strides in different directions\n");
19901989
return MemoryDepChecker::Dependence::Unknown;
@@ -2040,19 +2039,16 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
20402039
*Dist, MaxStride, TypeByteSize))
20412040
return Dependence::NoDep;
20422041

2043-
const SCEVConstant *C = dyn_cast<SCEVConstant>(Dist);
2042+
const SCEVConstant *ConstDist = dyn_cast<SCEVConstant>(Dist);
20442043

20452044
// Attempt to prove strided accesses independent.
2046-
if (C) {
2047-
const APInt &Val = C->getAPInt();
2048-
int64_t Distance = Val.getSExtValue();
2045+
if (ConstDist) {
2046+
uint64_t Distance = ConstDist->getAPInt().abs().getZExtValue();
20492047

20502048
// If the distance between accesses and their strides are known constants,
20512049
// check whether the accesses interlace each other.
2052-
if (std::abs(Distance) > 0 && CommonStride && *CommonStride > 1 &&
2053-
HasSameSize &&
2054-
areStridedAccessesIndependent(std::abs(Distance), *CommonStride,
2055-
TypeByteSize)) {
2050+
if (Distance > 0 && CommonStride && CommonStride > 1 && HasSameSize &&
2051+
areStridedAccessesIndependent(Distance, *CommonStride, TypeByteSize)) {
20562052
LLVM_DEBUG(dbgs() << "LAA: Strided accesses are independent\n");
20572053
return Dependence::NoDep;
20582054
}
@@ -2085,7 +2081,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
20852081
// forward dependency will allow vectorization using any width.
20862082

20872083
if (IsTrueDataDependence && EnableForwardingConflictDetection) {
2088-
if (!C) {
2084+
if (!ConstDist) {
20892085
// TODO: FoundNonConstantDistanceDependence is used as a necessary
20902086
// condition to consider retrying with runtime checks. Historically, we
20912087
// did not set it when strides were different but there is no inherent
@@ -2094,8 +2090,8 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
20942090
return Dependence::Unknown;
20952091
}
20962092
if (!HasSameSize ||
2097-
couldPreventStoreLoadForward(C->getAPInt().abs().getZExtValue(),
2098-
TypeByteSize)) {
2093+
couldPreventStoreLoadForward(
2094+
ConstDist->getAPInt().abs().getZExtValue(), TypeByteSize)) {
20992095
LLVM_DEBUG(
21002096
dbgs() << "LAA: Forward but may prevent st->ld forwarding\n");
21012097
return Dependence::ForwardButPreventsForwarding;
@@ -2113,7 +2109,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
21132109
return Dependence::Unknown;
21142110
}
21152111

2116-
if (!isa<SCEVConstant>(Dist)) {
2112+
if (!ConstDist) {
21172113
// Previously this case would be treated as Unknown, possibly setting
21182114
// FoundNonConstantDistanceDependence to force re-trying with runtime
21192115
// checks. Until the TODO below is addressed, set it here to preserve
@@ -2175,7 +2171,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
21752171
uint64_t MinDistanceNeeded =
21762172
TypeByteSize * *CommonStride * (MinNumIter - 1) + TypeByteSize;
21772173
if (MinDistanceNeeded > static_cast<uint64_t>(MinDistance)) {
2178-
if (!isa<SCEVConstant>(Dist)) {
2174+
if (!ConstDist) {
21792175
// For non-constant distances, we checked the lower bound of the
21802176
// dependence distance and the distance may be larger at runtime (and safe
21812177
// for vectorization). Classify it as Unknown, so we re-try with runtime
@@ -2216,8 +2212,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
22162212

22172213
bool IsTrueDataDependence = (!AIsWrite && BIsWrite);
22182214
uint64_t MinDepDistBytesOld = MinDepDistBytes;
2219-
if (IsTrueDataDependence && EnableForwardingConflictDetection &&
2220-
isa<SCEVConstant>(Dist) &&
2215+
if (IsTrueDataDependence && EnableForwardingConflictDetection && ConstDist &&
22212216
couldPreventStoreLoadForward(MinDistance, TypeByteSize)) {
22222217
// Sanity check that we didn't update MinDepDistBytes when calling
22232218
// couldPreventStoreLoadForward
@@ -2235,7 +2230,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
22352230
<< " with max VF = " << MaxVF << '\n');
22362231

22372232
uint64_t MaxVFInBits = MaxVF * TypeByteSize * 8;
2238-
if (!isa<SCEVConstant>(Dist) && MaxVFInBits < MaxTargetVectorWidthInBits) {
2233+
if (!ConstDist && MaxVFInBits < MaxTargetVectorWidthInBits) {
22392234
// For non-constant distances, we checked the lower bound of the dependence
22402235
// distance and the distance may be larger at runtime (and safe for
22412236
// vectorization). Classify it as Unknown, so we re-try with runtime checks.

0 commit comments

Comments
 (0)