Skip to content

Commit 3c80644

Browse files
committed
[VPlan] Only compute reg pressure if considered. NFCI
In #149056 VF pruning was changed so that it only pruned VFs that stemmed from MaxBandwidth being enabled. However we always compute register pressure regardless of whether or not max bandwidth produced any new VFs. This skips the computation if not needed and renames the method for clarity. The diff in reg-usage.ll is due to the scalable VPlan not actually having any maxbandwidth VFs, so I've changed it to check the fixed-length VF instead, which is affected by maxbandwidth.
1 parent f831463 commit 3c80644

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,8 @@ class LoopVectorizationCostModel {
937937
/// user options, for the given register kind.
938938
bool useMaxBandwidth(TargetTransformInfo::RegisterKind RegKind);
939939

940-
/// \return True if register pressure should be calculated for the given VF.
941-
bool shouldCalculateRegPressureForVF(ElementCount VF);
940+
/// \return True if register pressure should be considered for the given VF.
941+
bool shouldConsiderRegPressureForVF(ElementCount VF);
942942

943943
/// \return The size (in bits) of the smallest and widest types in the code
944944
/// that needs to be vectorized. We ignore values that remain scalar such as
@@ -3727,7 +3727,7 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) {
37273727
return FixedScalableVFPair::getNone();
37283728
}
37293729

3730-
bool LoopVectorizationCostModel::shouldCalculateRegPressureForVF(
3730+
bool LoopVectorizationCostModel::shouldConsiderRegPressureForVF(
37313731
ElementCount VF) {
37323732
if (!useMaxBandwidth(VF.isScalable()
37333733
? TargetTransformInfo::RGK_ScalableVector
@@ -4172,8 +4172,9 @@ VectorizationFactor LoopVectorizationPlanner::selectVectorizationFactor() {
41724172
P->vectorFactors().end());
41734173

41744174
SmallVector<VPRegisterUsage, 8> RUs;
4175-
if (CM.useMaxBandwidth(TargetTransformInfo::RGK_ScalableVector) ||
4176-
CM.useMaxBandwidth(TargetTransformInfo::RGK_FixedWidthVector))
4175+
if (any_of(VFs, [this](ElementCount VF) {
4176+
return CM.shouldConsiderRegPressureForVF(VF);
4177+
}))
41774178
RUs = calculateRegisterUsageForPlan(*P, VFs, TTI, CM.ValuesToIgnore);
41784179

41794180
for (unsigned I = 0; I < VFs.size(); I++) {
@@ -4185,7 +4186,7 @@ VectorizationFactor LoopVectorizationPlanner::selectVectorizationFactor() {
41854186
/// If the register pressure needs to be considered for VF,
41864187
/// don't consider the VF as valid if it exceeds the number
41874188
/// of registers for the target.
4188-
if (CM.shouldCalculateRegPressureForVF(VF) &&
4189+
if (CM.shouldConsiderRegPressureForVF(VF) &&
41894190
RUs[I].exceedsMaxNumRegs(TTI, ForceTargetNumVectorRegs))
41904191
continue;
41914192

@@ -7020,8 +7021,9 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() {
70207021
P->vectorFactors().end());
70217022

70227023
SmallVector<VPRegisterUsage, 8> RUs;
7023-
if (CM.useMaxBandwidth(TargetTransformInfo::RGK_ScalableVector) ||
7024-
CM.useMaxBandwidth(TargetTransformInfo::RGK_FixedWidthVector))
7024+
if (any_of(VFs, [this](ElementCount VF) {
7025+
return CM.shouldConsiderRegPressureForVF(VF);
7026+
}))
70257027
RUs = calculateRegisterUsageForPlan(*P, VFs, TTI, CM.ValuesToIgnore);
70267028

70277029
for (unsigned I = 0; I < VFs.size(); I++) {
@@ -7047,7 +7049,7 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() {
70477049
InstructionCost Cost = cost(*P, VF);
70487050
VectorizationFactor CurrentFactor(VF, Cost, ScalarCost);
70497051

7050-
if (CM.shouldCalculateRegPressureForVF(VF) &&
7052+
if (CM.shouldConsiderRegPressureForVF(VF) &&
70517053
RUs[I].exceedsMaxNumRegs(TTI, ForceTargetNumVectorRegs)) {
70527054
LLVM_DEBUG(dbgs() << "LV(REG): Not considering vector loop of width "
70537055
<< VF << " because it uses too many registers\n");

llvm/test/Transforms/LoopVectorize/AArch64/reg-usage.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
define void @get_invariant_reg_usage(ptr %z) {
1616
; CHECK-LABEL: LV: Checking a loop in 'get_invariant_reg_usage'
17-
; CHECK: LV(REG): VF = vscale x 16
17+
; CHECK: LV(REG): VF = 16
1818
; CHECK-NEXT: LV(REG): Found max usage: 2 item
1919
; CHECK-NEXT: LV(REG): RegisterClass: Generic::ScalarRC, 2 registers
2020
; CHECK-NEXT: LV(REG): RegisterClass: Generic::VectorRC, 1 registers

0 commit comments

Comments
 (0)