Skip to content

Commit c05eb70

Browse files
committed
LAA: improve code in a couple of routines (NFC)
1 parent 725fab9 commit c05eb70

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
@@ -1976,13 +1976,12 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
19761976
<< " Sink induction step: " << StrideBPtrInt << "\n");
19771977
// At least Src or Sink are loop invariant and the other is strided or
19781978
// invariant. We can generate a runtime check to disambiguate the accesses.
1979-
if (StrideAPtrInt == 0 || StrideBPtrInt == 0)
1979+
if (!StrideAPtrInt || !StrideBPtrInt)
19801980
return MemoryDepChecker::Dependence::Unknown;
19811981

19821982
// Both Src and Sink have a constant stride, check if they are in the same
19831983
// direction.
1984-
if ((StrideAPtrInt > 0 && StrideBPtrInt < 0) ||
1985-
(StrideAPtrInt < 0 && StrideBPtrInt > 0)) {
1984+
if (StrideAPtrInt > 0 != StrideBPtrInt > 0) {
19861985
LLVM_DEBUG(
19871986
dbgs() << "Pointer access with strides in different directions\n");
19881987
return MemoryDepChecker::Dependence::Unknown;
@@ -2038,19 +2037,16 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
20382037
*Dist, MaxStride, TypeByteSize))
20392038
return Dependence::NoDep;
20402039

2041-
const SCEVConstant *C = dyn_cast<SCEVConstant>(Dist);
2040+
const SCEVConstant *ConstDist = dyn_cast<SCEVConstant>(Dist);
20422041

20432042
// Attempt to prove strided accesses independent.
2044-
if (C) {
2045-
const APInt &Val = C->getAPInt();
2046-
int64_t Distance = Val.getSExtValue();
2043+
if (ConstDist) {
2044+
int64_t Distance = std::abs(ConstDist->getAPInt().getSExtValue());
20472045

20482046
// If the distance between accesses and their strides are known constants,
20492047
// check whether the accesses interlace each other.
2050-
if (std::abs(Distance) > 0 && CommonStride && *CommonStride > 1 &&
2051-
HasSameSize &&
2052-
areStridedAccessesIndependent(std::abs(Distance), *CommonStride,
2053-
TypeByteSize)) {
2048+
if (Distance > 0 && CommonStride && CommonStride > 1 && HasSameSize &&
2049+
areStridedAccessesIndependent(Distance, *CommonStride, TypeByteSize)) {
20542050
LLVM_DEBUG(dbgs() << "LAA: Strided accesses are independent\n");
20552051
return Dependence::NoDep;
20562052
}
@@ -2083,7 +2079,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
20832079
// forward dependency will allow vectorization using any width.
20842080

20852081
if (IsTrueDataDependence && EnableForwardingConflictDetection) {
2086-
if (!C) {
2082+
if (!ConstDist) {
20872083
// TODO: FoundNonConstantDistanceDependence is used as a necessary
20882084
// condition to consider retrying with runtime checks. Historically, we
20892085
// did not set it when strides were different but there is no inherent
@@ -2092,8 +2088,8 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
20922088
return Dependence::Unknown;
20932089
}
20942090
if (!HasSameSize ||
2095-
couldPreventStoreLoadForward(C->getAPInt().abs().getZExtValue(),
2096-
TypeByteSize)) {
2091+
couldPreventStoreLoadForward(
2092+
ConstDist->getAPInt().abs().getZExtValue(), TypeByteSize)) {
20972093
LLVM_DEBUG(
20982094
dbgs() << "LAA: Forward but may prevent st->ld forwarding\n");
20992095
return Dependence::ForwardButPreventsForwarding;
@@ -2111,7 +2107,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
21112107
return Dependence::Unknown;
21122108
}
21132109

2114-
if (!isa<SCEVConstant>(Dist)) {
2110+
if (!ConstDist) {
21152111
// Previously this case would be treated as Unknown, possibly setting
21162112
// FoundNonConstantDistanceDependence to force re-trying with runtime
21172113
// checks. Until the TODO below is addressed, set it here to preserve
@@ -2173,7 +2169,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
21732169
uint64_t MinDistanceNeeded =
21742170
TypeByteSize * *CommonStride * (MinNumIter - 1) + TypeByteSize;
21752171
if (MinDistanceNeeded > static_cast<uint64_t>(MinDistance)) {
2176-
if (!isa<SCEVConstant>(Dist)) {
2172+
if (!ConstDist) {
21772173
// For non-constant distances, we checked the lower bound of the
21782174
// dependence distance and the distance may be larger at runtime (and safe
21792175
// for vectorization). Classify it as Unknown, so we re-try with runtime
@@ -2214,8 +2210,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
22142210

22152211
bool IsTrueDataDependence = (!AIsWrite && BIsWrite);
22162212
uint64_t MinDepDistBytesOld = MinDepDistBytes;
2217-
if (IsTrueDataDependence && EnableForwardingConflictDetection &&
2218-
isa<SCEVConstant>(Dist) &&
2213+
if (IsTrueDataDependence && EnableForwardingConflictDetection && ConstDist &&
22192214
couldPreventStoreLoadForward(MinDistance, TypeByteSize)) {
22202215
// Sanity check that we didn't update MinDepDistBytes when calling
22212216
// couldPreventStoreLoadForward
@@ -2233,7 +2228,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
22332228
<< " with max VF = " << MaxVF << '\n');
22342229

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

0 commit comments

Comments
 (0)