@@ -2090,12 +2090,14 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
2090
2090
return MemoryDepChecker::Dependence::Unknown;
2091
2091
}
2092
2092
2093
+ TypeSize AStoreSz = DL.getTypeStoreSize (ATy);
2094
+ TypeSize BStoreSz = DL.getTypeStoreSize (BTy);
2095
+
2096
+ // If store sizes are not the same, set TypeByteSize to zero, so we can check
2097
+ // it in the caller isDependent.
2093
2098
uint64_t ASz = DL.getTypeAllocSize (ATy);
2094
2099
uint64_t BSz = DL.getTypeAllocSize (BTy);
2095
-
2096
- // Both the source and sink sizes are neeeded in dependence checks, depending
2097
- // on the use.
2098
- std::pair<uint64_t , uint64_t > TypeByteSize (ASz, BSz);
2100
+ uint64_t TypeByteSize = (AStoreSz == BStoreSz) ? BSz : 0 ;
2099
2101
2100
2102
uint64_t StrideAScaled = std::abs (StrideAPtrInt) * ASz;
2101
2103
uint64_t StrideBScaled = std::abs (StrideBPtrInt) * BSz;
@@ -2117,24 +2119,8 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
2117
2119
return Dependence::Unknown;
2118
2120
}
2119
2121
2120
- // When the distance is possibly zero, we're reading/writing the same memory
2121
- // location: if the store sizes are not equal, fail with an unknown
2122
- // dependence.
2123
- TypeSize AStoreSz = DL.getTypeStoreSize (ATy);
2124
- TypeSize BStoreSz = DL.getTypeStoreSize (BTy);
2125
- if (AStoreSz != BStoreSz && SE.isKnownNonPositive (Dist) &&
2126
- SE.isKnownNonNegative (Dist)) {
2127
- LLVM_DEBUG (dbgs () << " LAA: possibly zero dependence distance with "
2128
- " different type sizes\n " );
2129
- return Dependence::Unknown;
2130
- }
2131
-
2132
- // TODO: Remove this.
2133
- bool HasSameSize = AStoreSz == BStoreSz;
2134
-
2135
2122
return DepDistanceStrideAndSizeInfo (Dist, MaxStride, CommonStride,
2136
- TypeByteSize, HasSameSize, AIsWrite,
2137
- BIsWrite);
2123
+ TypeByteSize, AIsWrite, BIsWrite);
2138
2124
}
2139
2125
2140
2126
MemoryDepChecker::Dependence::DepType
@@ -2166,8 +2152,9 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2166
2152
return std::get<Dependence::DepType>(Res);
2167
2153
}
2168
2154
2169
- auto &[Dist, MaxStride, CommonStride, TypeByteSize, HasSameSize, AIsWrite,
2170
- BIsWrite] = std::get<DepDistanceStrideAndSizeInfo>(Res);
2155
+ auto &[Dist, MaxStride, CommonStride, TypeByteSize, AIsWrite, BIsWrite] =
2156
+ std::get<DepDistanceStrideAndSizeInfo>(Res);
2157
+ bool HasSameSize = TypeByteSize > 0 ;
2171
2158
2172
2159
ScalarEvolution &SE = *PSE.getSE ();
2173
2160
auto &DL = InnermostLoop->getHeader ()->getDataLayout ();
@@ -2193,8 +2180,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2193
2180
// If the distance between accesses and their strides are known constants,
2194
2181
// check whether the accesses interlace each other.
2195
2182
if (ConstDist > 0 && CommonStride && CommonStride > 1 && HasSameSize &&
2196
- areStridedAccessesIndependent (ConstDist, *CommonStride,
2197
- TypeByteSize.first )) {
2183
+ areStridedAccessesIndependent (ConstDist, *CommonStride, TypeByteSize)) {
2198
2184
LLVM_DEBUG (dbgs () << " LAA: Strided accesses are independent\n " );
2199
2185
return Dependence::NoDep;
2200
2186
}
@@ -2208,9 +2194,13 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2208
2194
// Negative distances are not plausible dependencies.
2209
2195
if (SE.isKnownNonPositive (Dist)) {
2210
2196
if (SE.isKnownNonNegative (Dist)) {
2211
- // Write to the same location with the same size.
2212
- assert (HasSameSize && " Accesses must have the same size" );
2213
- return Dependence::Forward;
2197
+ if (HasSameSize) {
2198
+ // Write to the same location with the same size.
2199
+ return Dependence::Forward;
2200
+ }
2201
+ LLVM_DEBUG (dbgs () << " LAA: possibly zero dependence difference but "
2202
+ " different type sizes\n " );
2203
+ return Dependence::Unknown;
2214
2204
}
2215
2205
2216
2206
bool IsTrueDataDependence = (AIsWrite && !BIsWrite);
@@ -2228,7 +2218,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2228
2218
: Dependence::Unknown;
2229
2219
}
2230
2220
if (!HasSameSize ||
2231
- couldPreventStoreLoadForward (ConstDist, TypeByteSize. first )) {
2221
+ couldPreventStoreLoadForward (ConstDist, TypeByteSize)) {
2232
2222
LLVM_DEBUG (
2233
2223
dbgs () << " LAA: Forward but may prevent st->ld forwarding\n " );
2234
2224
return Dependence::ForwardButPreventsForwarding;
@@ -2294,8 +2284,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2294
2284
// We know that Dist is positive, but it may not be constant. Use the signed
2295
2285
// minimum for computations below, as this ensures we compute the closest
2296
2286
// possible dependence distance.
2297
- uint64_t MinDistanceNeeded =
2298
- MaxStride * (MinNumIter - 1 ) + TypeByteSize.first ;
2287
+ uint64_t MinDistanceNeeded = MaxStride * (MinNumIter - 1 ) + TypeByteSize;
2299
2288
if (MinDistanceNeeded > static_cast <uint64_t >(MinDistance)) {
2300
2289
if (!ConstDist) {
2301
2290
// For non-constant distances, we checked the lower bound of the
@@ -2323,15 +2312,14 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
2323
2312
2324
2313
bool IsTrueDataDependence = (!AIsWrite && BIsWrite);
2325
2314
if (IsTrueDataDependence && EnableForwardingConflictDetection && ConstDist &&
2326
- couldPreventStoreLoadForward (MinDistance, TypeByteSize.first ,
2327
- *CommonStride))
2315
+ couldPreventStoreLoadForward (MinDistance, TypeByteSize, *CommonStride))
2328
2316
return Dependence::BackwardVectorizableButPreventsForwarding;
2329
2317
2330
2318
uint64_t MaxVF = MinDepDistBytes / MaxStride;
2331
2319
LLVM_DEBUG (dbgs () << " LAA: Positive min distance " << MinDistance
2332
2320
<< " with max VF = " << MaxVF << ' \n ' );
2333
2321
2334
- uint64_t MaxVFInBits = MaxVF * TypeByteSize. first * 8 ;
2322
+ uint64_t MaxVFInBits = MaxVF * TypeByteSize * 8 ;
2335
2323
if (!ConstDist && MaxVFInBits < MaxTargetVectorWidthInBits) {
2336
2324
// For non-constant distances, we checked the lower bound of the dependence
2337
2325
// distance and the distance may be larger at runtime (and safe for
0 commit comments