-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LV]Split store-load forward distance analysis from other checks, NFC #121156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexey-bataev
merged 11 commits into
main
from
users/alexey-bataev/spr/lvfiximprove-max-safe-distance-analysis
Mar 31, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4a74a77
[𝘀𝗽𝗿] initial version
alexey-bataev 6201773
Fix formatting
alexey-bataev 6a3c6bb
Rebase, rework
alexey-bataev e938e4a
Rebase, address comment
alexey-bataev 1a95648
Rebase
alexey-bataev 85c7122
Fix formatting
alexey-bataev 0cfee98
Rebase
alexey-bataev d7bc6d6
Rebase, address comments
alexey-bataev dc66ca4
Rebase, address comments
alexey-bataev c6f318d
Rebase, address comments
alexey-bataev bcf7b52
Rebase, address comments
alexey-bataev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1741,7 +1741,8 @@ bool MemoryDepChecker::Dependence::isForward() const { | |
} | ||
|
||
bool MemoryDepChecker::couldPreventStoreLoadForward(uint64_t Distance, | ||
uint64_t TypeByteSize) { | ||
uint64_t TypeByteSize, | ||
unsigned CommonStride) { | ||
// If loads occur at a distance that is not a multiple of a feasible vector | ||
// factor store-load forwarding does not take place. | ||
// Positive dependences might cause troubles because vectorizing them might | ||
|
@@ -1756,31 +1757,38 @@ bool MemoryDepChecker::couldPreventStoreLoadForward(uint64_t Distance, | |
// cause any slowdowns. | ||
const uint64_t NumItersForStoreLoadThroughMemory = 8 * TypeByteSize; | ||
// Maximum vector factor. | ||
uint64_t MaxVFWithoutSLForwardIssues = std::min( | ||
VectorizerParams::MaxVectorWidth * TypeByteSize, MinDepDistBytes); | ||
uint64_t MaxVFWithoutSLForwardIssuesPowerOf2 = | ||
std::min(VectorizerParams::MaxVectorWidth * TypeByteSize, | ||
MaxStoreLoadForwardSafeDistanceInBits); | ||
|
||
// Compute the smallest VF at which the store and load would be misaligned. | ||
for (uint64_t VF = 2 * TypeByteSize; VF <= MaxVFWithoutSLForwardIssues; | ||
VF *= 2) { | ||
for (uint64_t VF = 2 * TypeByteSize; | ||
VF <= MaxVFWithoutSLForwardIssuesPowerOf2; VF *= 2) { | ||
// If the number of vector iteration between the store and the load are | ||
// small we could incur conflicts. | ||
if (Distance % VF && Distance / VF < NumItersForStoreLoadThroughMemory) { | ||
MaxVFWithoutSLForwardIssues = (VF >> 1); | ||
MaxVFWithoutSLForwardIssuesPowerOf2 = (VF >> 1); | ||
break; | ||
} | ||
} | ||
|
||
if (MaxVFWithoutSLForwardIssues < 2 * TypeByteSize) { | ||
if (MaxVFWithoutSLForwardIssuesPowerOf2 < 2 * TypeByteSize) { | ||
LLVM_DEBUG( | ||
dbgs() << "LAA: Distance " << Distance | ||
<< " that could cause a store-load forwarding conflict\n"); | ||
return true; | ||
} | ||
|
||
if (MaxVFWithoutSLForwardIssues < MinDepDistBytes && | ||
MaxVFWithoutSLForwardIssues != | ||
VectorizerParams::MaxVectorWidth * TypeByteSize) | ||
MinDepDistBytes = MaxVFWithoutSLForwardIssues; | ||
if (CommonStride && | ||
MaxVFWithoutSLForwardIssuesPowerOf2 < | ||
MaxStoreLoadForwardSafeDistanceInBits && | ||
MaxVFWithoutSLForwardIssuesPowerOf2 != | ||
VectorizerParams::MaxVectorWidth * TypeByteSize) { | ||
uint64_t MaxVF = MaxVFWithoutSLForwardIssuesPowerOf2 / CommonStride; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
uint64_t MaxVFInBits = MaxVF * TypeByteSize * 8; | ||
MaxStoreLoadForwardSafeDistanceInBits = | ||
std::min(MaxStoreLoadForwardSafeDistanceInBits, MaxVFInBits); | ||
} | ||
return false; | ||
} | ||
|
||
|
@@ -2228,20 +2236,10 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx, | |
std::min(static_cast<uint64_t>(MinDistance), MinDepDistBytes); | ||
|
||
bool IsTrueDataDependence = (!AIsWrite && BIsWrite); | ||
uint64_t MinDepDistBytesOld = MinDepDistBytes; | ||
if (IsTrueDataDependence && EnableForwardingConflictDetection && ConstDist && | ||
couldPreventStoreLoadForward(MinDistance, TypeByteSize)) { | ||
// Sanity check that we didn't update MinDepDistBytes when calling | ||
// couldPreventStoreLoadForward | ||
assert(MinDepDistBytes == MinDepDistBytesOld && | ||
"An update to MinDepDistBytes requires an update to " | ||
"MaxSafeVectorWidthInBits"); | ||
(void)MinDepDistBytesOld; | ||
couldPreventStoreLoadForward(MinDistance, TypeByteSize, *CommonStride)) | ||
return Dependence::BackwardVectorizableButPreventsForwarding; | ||
} | ||
|
||
// An update to MinDepDistBytes requires an update to MaxSafeVectorWidthInBits | ||
// since there is a backwards dependency. | ||
uint64_t MaxVF = MinDepDistBytes / *CommonStride; | ||
LLVM_DEBUG(dbgs() << "LAA: Positive min distance " << MinDistance | ||
<< " with max VF = " << MaxVF << '\n'); | ||
|
@@ -3006,6 +3004,11 @@ void LoopAccessInfo::print(raw_ostream &OS, unsigned Depth) const { | |
if (!DC.isSafeForAnyVectorWidth()) | ||
OS << " with a maximum safe vector width of " | ||
<< DC.getMaxSafeVectorWidthInBits() << " bits"; | ||
if (!DC.isSafeForAnyStoreLoadForwardDistances()) { | ||
uint64_t SLDist = DC.getStoreLoadForwardSafeDistanceInBits(); | ||
OS << ", with a maximum safe store-load forward width of " << SLDist | ||
<< " bits"; | ||
} | ||
if (PtrRtChecking->Need) | ||
OS << " with run-time checks"; | ||
OS << "\n"; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.