@@ -1978,13 +1978,12 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
1978
1978
<< " Sink induction step: " << StrideBPtrInt << " \n " );
1979
1979
// At least Src or Sink are loop invariant and the other is strided or
1980
1980
// invariant. We can generate a runtime check to disambiguate the accesses.
1981
- if (StrideAPtrInt == 0 || StrideBPtrInt == 0 )
1981
+ if (! StrideAPtrInt || ! StrideBPtrInt)
1982
1982
return MemoryDepChecker::Dependence::Unknown;
1983
1983
1984
1984
// Both Src and Sink have a constant stride, check if they are in the same
1985
1985
// direction.
1986
- if ((StrideAPtrInt > 0 && StrideBPtrInt < 0 ) ||
1987
- (StrideAPtrInt < 0 && StrideBPtrInt > 0 )) {
1986
+ if ((StrideAPtrInt > 0 ) != (StrideBPtrInt > 0 )) {
1988
1987
LLVM_DEBUG (
1989
1988
dbgs () << " Pointer access with strides in different directions\n " );
1990
1989
return MemoryDepChecker::Dependence::Unknown;
@@ -2040,19 +2039,16 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2040
2039
*Dist, MaxStride, TypeByteSize))
2041
2040
return Dependence::NoDep;
2042
2041
2043
- const SCEVConstant *C = dyn_cast<SCEVConstant>(Dist);
2042
+ const SCEVConstant *ConstDist = dyn_cast<SCEVConstant>(Dist);
2044
2043
2045
2044
// 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 ();
2049
2047
2050
2048
// If the distance between accesses and their strides are known constants,
2051
2049
// 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)) {
2056
2052
LLVM_DEBUG (dbgs () << " LAA: Strided accesses are independent\n " );
2057
2053
return Dependence::NoDep;
2058
2054
}
@@ -2085,7 +2081,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2085
2081
// forward dependency will allow vectorization using any width.
2086
2082
2087
2083
if (IsTrueDataDependence && EnableForwardingConflictDetection) {
2088
- if (!C ) {
2084
+ if (!ConstDist ) {
2089
2085
// TODO: FoundNonConstantDistanceDependence is used as a necessary
2090
2086
// condition to consider retrying with runtime checks. Historically, we
2091
2087
// did not set it when strides were different but there is no inherent
@@ -2094,8 +2090,8 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2094
2090
return Dependence::Unknown;
2095
2091
}
2096
2092
if (!HasSameSize ||
2097
- couldPreventStoreLoadForward (C-> getAPInt (). abs (). getZExtValue (),
2098
- TypeByteSize)) {
2093
+ couldPreventStoreLoadForward (
2094
+ ConstDist-> getAPInt (). abs (). getZExtValue (), TypeByteSize)) {
2099
2095
LLVM_DEBUG (
2100
2096
dbgs () << " LAA: Forward but may prevent st->ld forwarding\n " );
2101
2097
return Dependence::ForwardButPreventsForwarding;
@@ -2113,7 +2109,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2113
2109
return Dependence::Unknown;
2114
2110
}
2115
2111
2116
- if (!isa<SCEVConstant>(Dist) ) {
2112
+ if (!ConstDist ) {
2117
2113
// Previously this case would be treated as Unknown, possibly setting
2118
2114
// FoundNonConstantDistanceDependence to force re-trying with runtime
2119
2115
// checks. Until the TODO below is addressed, set it here to preserve
@@ -2175,7 +2171,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2175
2171
uint64_t MinDistanceNeeded =
2176
2172
TypeByteSize * *CommonStride * (MinNumIter - 1 ) + TypeByteSize;
2177
2173
if (MinDistanceNeeded > static_cast <uint64_t >(MinDistance)) {
2178
- if (!isa<SCEVConstant>(Dist) ) {
2174
+ if (!ConstDist ) {
2179
2175
// For non-constant distances, we checked the lower bound of the
2180
2176
// dependence distance and the distance may be larger at runtime (and safe
2181
2177
// for vectorization). Classify it as Unknown, so we re-try with runtime
@@ -2216,8 +2212,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2216
2212
2217
2213
bool IsTrueDataDependence = (!AIsWrite && BIsWrite);
2218
2214
uint64_t MinDepDistBytesOld = MinDepDistBytes;
2219
- if (IsTrueDataDependence && EnableForwardingConflictDetection &&
2220
- isa<SCEVConstant>(Dist) &&
2215
+ if (IsTrueDataDependence && EnableForwardingConflictDetection && ConstDist &&
2221
2216
couldPreventStoreLoadForward (MinDistance, TypeByteSize)) {
2222
2217
// Sanity check that we didn't update MinDepDistBytes when calling
2223
2218
// couldPreventStoreLoadForward
@@ -2235,7 +2230,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2235
2230
<< " with max VF = " << MaxVF << ' \n ' );
2236
2231
2237
2232
uint64_t MaxVFInBits = MaxVF * TypeByteSize * 8 ;
2238
- if (!isa<SCEVConstant>(Dist) && MaxVFInBits < MaxTargetVectorWidthInBits) {
2233
+ if (!ConstDist && MaxVFInBits < MaxTargetVectorWidthInBits) {
2239
2234
// For non-constant distances, we checked the lower bound of the dependence
2240
2235
// distance and the distance may be larger at runtime (and safe for
2241
2236
// vectorization). Classify it as Unknown, so we re-try with runtime checks.
0 commit comments