-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[LV] Fix MVE regression from #132190 #141736
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
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 |
---|---|---|
|
@@ -959,6 +959,10 @@ class LoopVectorizationCostModel { | |
return expectedCost(UserVF).isValid(); | ||
} | ||
|
||
/// \return True if maximizing vector bandwidth is enabled by the target or | ||
/// user options. | ||
bool useMaxBandwidth(TargetTransformInfo::RegisterKind RegKind); | ||
|
||
/// \return The size (in bits) of the smallest and widest types in the code | ||
/// that needs to be vectorized. We ignore values that remain scalar such as | ||
/// 64 bit loop indices. | ||
|
@@ -3944,6 +3948,14 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) { | |
return FixedScalableVFPair::getNone(); | ||
} | ||
|
||
bool LoopVectorizationCostModel::useMaxBandwidth( | ||
TargetTransformInfo::RegisterKind RegKind) { | ||
return MaximizeBandwidth || (MaximizeBandwidth.getNumOccurrences() == 0 && | ||
(TTI.shouldMaximizeVectorBandwidth(RegKind) || | ||
(UseWiderVFIfCallVariantsPresent && | ||
Legal->hasVectorCallVariants()))); | ||
} | ||
|
||
ElementCount LoopVectorizationCostModel::getMaximizedVFForTarget( | ||
unsigned MaxTripCount, unsigned SmallestType, unsigned WidestType, | ||
ElementCount MaxSafeVF, bool FoldTailByMasking) { | ||
|
@@ -4009,10 +4021,7 @@ ElementCount LoopVectorizationCostModel::getMaximizedVFForTarget( | |
ComputeScalableMaxVF ? TargetTransformInfo::RGK_ScalableVector | ||
: TargetTransformInfo::RGK_FixedWidthVector; | ||
ElementCount MaxVF = MaxVectorElementCount; | ||
if (MaximizeBandwidth || | ||
(MaximizeBandwidth.getNumOccurrences() == 0 && | ||
(TTI.shouldMaximizeVectorBandwidth(RegKind) || | ||
(UseWiderVFIfCallVariantsPresent && Legal->hasVectorCallVariants())))) { | ||
if (useMaxBandwidth(RegKind)) { | ||
auto MaxVectorElementCountMaxBW = ElementCount::get( | ||
llvm::bit_floor(WidestRegister.getKnownMinValue() / SmallestType), | ||
ComputeScalableMaxVF); | ||
|
@@ -4384,7 +4393,10 @@ VectorizationFactor LoopVectorizationPlanner::selectVectorizationFactor() { | |
|
||
/// Don't consider the VF if it exceeds the number of registers for the | ||
/// target. | ||
if (RU.exceedsMaxNumRegs(TTI)) | ||
if (CM.useMaxBandwidth(VF.isScalable() | ||
? TargetTransformInfo::RGK_ScalableVector | ||
: TargetTransformInfo::RGK_FixedWidthVector) && | ||
RU.exceedsMaxNumRegs(TTI)) | ||
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. I think this is the only use of RU, would be good to skip the register pressure computation when it's not needed Same below 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. Good idea, done! This has also gotten the riscv tests back to what they were before merging #132190. |
||
continue; | ||
|
||
InstructionCost C = CM.expectedCost(VF); | ||
|
@@ -7458,7 +7470,10 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() { | |
InstructionCost Cost = cost(*P, VF); | ||
VectorizationFactor CurrentFactor(VF, Cost, ScalarCost); | ||
|
||
if (RU.exceedsMaxNumRegs(TTI)) { | ||
if (CM.useMaxBandwidth(VF.isScalable() | ||
? TargetTransformInfo::RGK_ScalableVector | ||
: TargetTransformInfo::RGK_FixedWidthVector) && | ||
RU.exceedsMaxNumRegs(TTI)) { | ||
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. Could you explain this logic briefly? Maybe I'm misunderstanding the goal here, but if we exceed the number of registers but don't have maxBandwidth enabled, then we'd try to vectorize anyway? Does the call to In other words; Why are we only considering whether we exceed the number of registers when maxBandwidth is enabled? 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. That understanding is correct. This was the behaviour before my previous PR accidentally changed it. I'll be looking into another sensible solution for this specific reproducer but this fixes the regression. |
||
LLVM_DEBUG(dbgs() << "LV(REG): Not considering vector loop of width " | ||
<< VF << " because it uses too many registers\n"); | ||
continue; | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@preames @wangpc-pp @topperc Making a note here that after this patch we'll likely regress cases like this on RVV unless we opt into shouldMaximizeVectorBandwidth https://godbolt.org/z/WcbWGooa4