-
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
Changes from 10 commits
4a74a77
6201773
6a3c6bb
e938e4a
1a95648
85c7122
0cfee98
d7bc6d6
dc66ca4
c6f318d
bcf7b52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 && | ||
alexey-bataev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3870,13 +3870,18 @@ FixedScalableVFPair LoopVectorizationCostModel::computeFeasibleMaxVF( | |
// It is computed by MaxVF * sizeOf(type) * 8, where type is taken from | ||
// the memory accesses that is most restrictive (involved in the smallest | ||
// dependence distance). | ||
unsigned MaxSafeElements = | ||
llvm::bit_floor(Legal->getMaxSafeVectorWidthInBits() / WidestType); | ||
unsigned MaxSafeElementsPowerOf2 = | ||
bit_floor(Legal->getMaxSafeVectorWidthInBits() / WidestType); | ||
if (!Legal->isSafeForAnyStoreLoadForwardDistances()) { | ||
unsigned SLDist = Legal->getMaxStoreLoadForwardSafeDistanceInBits(); | ||
MaxSafeElementsPowerOf2 = | ||
std::min(MaxSafeElementsPowerOf2, SLDist / WidestType); | ||
} | ||
auto MaxSafeFixedVF = ElementCount::getFixed(MaxSafeElementsPowerOf2); | ||
auto MaxSafeScalableVF = getMaxLegalScalableVF(MaxSafeElementsPowerOf2); | ||
|
||
auto MaxSafeFixedVF = ElementCount::getFixed(MaxSafeElements); | ||
auto MaxSafeScalableVF = getMaxLegalScalableVF(MaxSafeElements); | ||
if (!Legal->isSafeForAnyVectorWidth()) | ||
this->MaxSafeElements = MaxSafeElements; | ||
this->MaxSafeElements = MaxSafeElementsPowerOf2; | ||
|
||
LLVM_DEBUG(dbgs() << "LV: The max safe fixed VF is: " << MaxSafeFixedVF | ||
<< ".\n"); | ||
|
@@ -4104,6 +4109,7 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) { | |
LLVM_DEBUG(dbgs() << "LV: No tail will remain for any chosen VF.\n"); | ||
return MaxFactors; | ||
} | ||
MaxPowerOf2RuntimeVF.reset(); | ||
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. Related to the PR? 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. Yes, without it the test are failed 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. But is this only due to the code below added by the patch?
It is not clear to me why |
||
} | ||
|
||
// If we don't know the precise trip count, or if the trip count that we | ||
|
@@ -4129,6 +4135,12 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) { | |
return MaxFactors; | ||
} | ||
|
||
if (MaxPowerOf2RuntimeVF) { | ||
// Accept MaxFixedVF if we do not have a tail. | ||
LLVM_DEBUG(dbgs() << "LV: No tail will remain for any chosen VF.\n"); | ||
return MaxFactors; | ||
} | ||
|
||
// If there was a tail-folding hint/switch, but we can't fold the tail by | ||
// masking, fallback to a vectorization with a scalar epilogue. | ||
if (ScalarEpilogueStatus == CM_ScalarEpilogueNotNeededUsePredicate) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.