@@ -2090,12 +2090,14 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
20902090 return MemoryDepChecker::Dependence::Unknown;
20912091 }
20922092
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.
20932098 uint64_t ASz = DL.getTypeAllocSize (ATy);
20942099 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 ;
20992101
21002102 uint64_t StrideAScaled = std::abs (StrideAPtrInt) * ASz;
21012103 uint64_t StrideBScaled = std::abs (StrideBPtrInt) * BSz;
@@ -2117,24 +2119,8 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
21172119 return Dependence::Unknown;
21182120 }
21192121
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-
21352122 return DepDistanceStrideAndSizeInfo (Dist, MaxStride, CommonStride,
2136- TypeByteSize, HasSameSize, AIsWrite,
2137- BIsWrite);
2123+ TypeByteSize, AIsWrite, BIsWrite);
21382124}
21392125
21402126MemoryDepChecker::Dependence::DepType
@@ -2166,8 +2152,9 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
21662152 return std::get<Dependence::DepType>(Res);
21672153 }
21682154
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 ;
21712158
21722159 ScalarEvolution &SE = *PSE.getSE ();
21732160 auto &DL = InnermostLoop->getHeader ()->getDataLayout ();
@@ -2193,8 +2180,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
21932180 // If the distance between accesses and their strides are known constants,
21942181 // check whether the accesses interlace each other.
21952182 if (ConstDist > 0 && CommonStride && CommonStride > 1 && HasSameSize &&
2196- areStridedAccessesIndependent (ConstDist, *CommonStride,
2197- TypeByteSize.first )) {
2183+ areStridedAccessesIndependent (ConstDist, *CommonStride, TypeByteSize)) {
21982184 LLVM_DEBUG (dbgs () << " LAA: Strided accesses are independent\n " );
21992185 return Dependence::NoDep;
22002186 }
@@ -2208,9 +2194,13 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
22082194 // Negative distances are not plausible dependencies.
22092195 if (SE.isKnownNonPositive (Dist)) {
22102196 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;
22142204 }
22152205
22162206 bool IsTrueDataDependence = (AIsWrite && !BIsWrite);
@@ -2228,7 +2218,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
22282218 : Dependence::Unknown;
22292219 }
22302220 if (!HasSameSize ||
2231- couldPreventStoreLoadForward (ConstDist, TypeByteSize. first )) {
2221+ couldPreventStoreLoadForward (ConstDist, TypeByteSize)) {
22322222 LLVM_DEBUG (
22332223 dbgs () << " LAA: Forward but may prevent st->ld forwarding\n " );
22342224 return Dependence::ForwardButPreventsForwarding;
@@ -2294,8 +2284,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
22942284 // We know that Dist is positive, but it may not be constant. Use the signed
22952285 // minimum for computations below, as this ensures we compute the closest
22962286 // possible dependence distance.
2297- uint64_t MinDistanceNeeded =
2298- MaxStride * (MinNumIter - 1 ) + TypeByteSize.first ;
2287+ uint64_t MinDistanceNeeded = MaxStride * (MinNumIter - 1 ) + TypeByteSize;
22992288 if (MinDistanceNeeded > static_cast <uint64_t >(MinDistance)) {
23002289 if (!ConstDist) {
23012290 // For non-constant distances, we checked the lower bound of the
@@ -2323,15 +2312,14 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
23232312
23242313 bool IsTrueDataDependence = (!AIsWrite && BIsWrite);
23252314 if (IsTrueDataDependence && EnableForwardingConflictDetection && ConstDist &&
2326- couldPreventStoreLoadForward (MinDistance, TypeByteSize.first ,
2327- *CommonStride))
2315+ couldPreventStoreLoadForward (MinDistance, TypeByteSize, *CommonStride))
23282316 return Dependence::BackwardVectorizableButPreventsForwarding;
23292317
23302318 uint64_t MaxVF = MinDepDistBytes / MaxStride;
23312319 LLVM_DEBUG (dbgs () << " LAA: Positive min distance " << MinDistance
23322320 << " with max VF = " << MaxVF << ' \n ' );
23332321
2334- uint64_t MaxVFInBits = MaxVF * TypeByteSize. first * 8 ;
2322+ uint64_t MaxVFInBits = MaxVF * TypeByteSize * 8 ;
23352323 if (!ConstDist && MaxVFInBits < MaxTargetVectorWidthInBits) {
23362324 // For non-constant distances, we checked the lower bound of the dependence
23372325 // distance and the distance may be larger at runtime (and safe for
0 commit comments