@@ -1740,7 +1740,8 @@ bool MemoryDepChecker::Dependence::isForward() const {
17401740}
17411741
17421742bool MemoryDepChecker::couldPreventStoreLoadForward (uint64_t Distance,
1743- uint64_t TypeByteSize) {
1743+ uint64_t TypeByteSize,
1744+ unsigned CommonStride) {
17441745 // If loads occur at a distance that is not a multiple of a feasible vector
17451746 // factor store-load forwarding does not take place.
17461747 // Positive dependences might cause troubles because vectorizing them might
@@ -1755,31 +1756,38 @@ bool MemoryDepChecker::couldPreventStoreLoadForward(uint64_t Distance,
17551756 // cause any slowdowns.
17561757 const uint64_t NumItersForStoreLoadThroughMemory = 8 * TypeByteSize;
17571758 // Maximum vector factor.
1758- uint64_t MaxVFWithoutSLForwardIssues = std::min (
1759- VectorizerParams::MaxVectorWidth * TypeByteSize, MinDepDistBytes);
1759+ uint64_t MaxVFWithoutSLForwardIssuesPowerOf2 =
1760+ std::min (VectorizerParams::MaxVectorWidth * TypeByteSize,
1761+ MaxStoreLoadForwardSafeDistanceInBits);
17601762
17611763 // Compute the smallest VF at which the store and load would be misaligned.
1762- for (uint64_t VF = 2 * TypeByteSize; VF <= MaxVFWithoutSLForwardIssues;
1763- VF *= 2 ) {
1764+ for (uint64_t VF = 2 * TypeByteSize;
1765+ VF <= MaxVFWithoutSLForwardIssuesPowerOf2; VF *= 2 ) {
17641766 // If the number of vector iteration between the store and the load are
17651767 // small we could incur conflicts.
17661768 if (Distance % VF && Distance / VF < NumItersForStoreLoadThroughMemory) {
1767- MaxVFWithoutSLForwardIssues = (VF >> 1 );
1769+ MaxVFWithoutSLForwardIssuesPowerOf2 = (VF >> 1 );
17681770 break ;
17691771 }
17701772 }
17711773
1772- if (MaxVFWithoutSLForwardIssues < 2 * TypeByteSize) {
1774+ if (MaxVFWithoutSLForwardIssuesPowerOf2 < 2 * TypeByteSize) {
17731775 LLVM_DEBUG (
17741776 dbgs () << " LAA: Distance " << Distance
17751777 << " that could cause a store-load forwarding conflict\n " );
17761778 return true ;
17771779 }
17781780
1779- if (MaxVFWithoutSLForwardIssues < MinDepDistBytes &&
1780- MaxVFWithoutSLForwardIssues !=
1781- VectorizerParams::MaxVectorWidth * TypeByteSize)
1782- MinDepDistBytes = MaxVFWithoutSLForwardIssues;
1781+ if (CommonStride &&
1782+ MaxVFWithoutSLForwardIssuesPowerOf2 <
1783+ MaxStoreLoadForwardSafeDistanceInBits &&
1784+ MaxVFWithoutSLForwardIssuesPowerOf2 !=
1785+ VectorizerParams::MaxVectorWidth * TypeByteSize) {
1786+ uint64_t MaxVF = MaxVFWithoutSLForwardIssuesPowerOf2 / CommonStride;
1787+ uint64_t MaxVFInBits = MaxVF * TypeByteSize * 8 ;
1788+ MaxStoreLoadForwardSafeDistanceInBits =
1789+ std::min (MaxStoreLoadForwardSafeDistanceInBits, MaxVFInBits);
1790+ }
17831791 return false ;
17841792}
17851793
@@ -2227,20 +2235,10 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
22272235 std::min (static_cast <uint64_t >(MinDistance), MinDepDistBytes);
22282236
22292237 bool IsTrueDataDependence = (!AIsWrite && BIsWrite);
2230- uint64_t MinDepDistBytesOld = MinDepDistBytes;
22312238 if (IsTrueDataDependence && EnableForwardingConflictDetection && ConstDist &&
2232- couldPreventStoreLoadForward (MinDistance, TypeByteSize)) {
2233- // Sanity check that we didn't update MinDepDistBytes when calling
2234- // couldPreventStoreLoadForward
2235- assert (MinDepDistBytes == MinDepDistBytesOld &&
2236- " An update to MinDepDistBytes requires an update to "
2237- " MaxSafeVectorWidthInBits" );
2238- (void )MinDepDistBytesOld;
2239+ couldPreventStoreLoadForward (MinDistance, TypeByteSize, *CommonStride))
22392240 return Dependence::BackwardVectorizableButPreventsForwarding;
2240- }
22412241
2242- // An update to MinDepDistBytes requires an update to MaxSafeVectorWidthInBits
2243- // since there is a backwards dependency.
22442242 uint64_t MaxVF = MinDepDistBytes / *CommonStride;
22452243 LLVM_DEBUG (dbgs () << " LAA: Positive min distance " << MinDistance
22462244 << " with max VF = " << MaxVF << ' \n ' );
@@ -3005,6 +3003,11 @@ void LoopAccessInfo::print(raw_ostream &OS, unsigned Depth) const {
30053003 if (!DC.isSafeForAnyVectorWidth ())
30063004 OS << " with a maximum safe vector width of "
30073005 << DC.getMaxSafeVectorWidthInBits () << " bits" ;
3006+ if (!DC.isSafeForAnyStoreLoadForwardDistances ()) {
3007+ uint64_t SLDist = DC.getStoreLoadForwardSafeDistanceInBits ();
3008+ OS << " , with a maximum safe store-load forward width of " << SLDist
3009+ << " bits" ;
3010+ }
30083011 if (PtrRtChecking->Need )
30093012 OS << " with run-time checks" ;
30103013 OS << " \n " ;
0 commit comments