Skip to content

Commit 4e5e65e

Browse files
authored
[VPlan] Only compute reg pressure if considered. NFCI (#156923)
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 is permitted for any VFs (via `MaxPermissibleVFWithoutMaxBW`). 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 53efe0a commit 4e5e65e

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
@@ -928,8 +928,8 @@ class LoopVectorizationCostModel {
928928
/// user options, for the given register kind.
929929
bool useMaxBandwidth(TargetTransformInfo::RegisterKind RegKind);
930930

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

934934
/// \return The size (in bits) of the smallest and widest types in the code
935935
/// that needs to be vectorized. We ignore values that remain scalar such as
@@ -3700,7 +3700,7 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) {
37003700
return FixedScalableVFPair::getNone();
37013701
}
37023702

3703-
bool LoopVectorizationCostModel::shouldCalculateRegPressureForVF(
3703+
bool LoopVectorizationCostModel::shouldConsiderRegPressureForVF(
37043704
ElementCount VF) {
37053705
if (!useMaxBandwidth(VF.isScalable()
37063706
? TargetTransformInfo::RGK_ScalableVector
@@ -4147,8 +4147,9 @@ VectorizationFactor LoopVectorizationPlanner::selectVectorizationFactor() {
41474147
P->vectorFactors().end());
41484148

41494149
SmallVector<VPRegisterUsage, 8> RUs;
4150-
if (CM.useMaxBandwidth(TargetTransformInfo::RGK_ScalableVector) ||
4151-
CM.useMaxBandwidth(TargetTransformInfo::RGK_FixedWidthVector))
4150+
if (any_of(VFs, [this](ElementCount VF) {
4151+
return CM.shouldConsiderRegPressureForVF(VF);
4152+
}))
41524153
RUs = calculateRegisterUsageForPlan(*P, VFs, TTI, CM.ValuesToIgnore);
41534154

41544155
for (unsigned I = 0; I < VFs.size(); I++) {
@@ -4160,7 +4161,7 @@ VectorizationFactor LoopVectorizationPlanner::selectVectorizationFactor() {
41604161
/// If the register pressure needs to be considered for VF,
41614162
/// don't consider the VF as valid if it exceeds the number
41624163
/// of registers for the target.
4163-
if (CM.shouldCalculateRegPressureForVF(VF) &&
4164+
if (CM.shouldConsiderRegPressureForVF(VF) &&
41644165
RUs[I].exceedsMaxNumRegs(TTI, ForceTargetNumVectorRegs))
41654166
continue;
41664167

@@ -6996,8 +6997,9 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() {
69966997
P->vectorFactors().end());
69976998

69986999
SmallVector<VPRegisterUsage, 8> RUs;
6999-
if (CM.useMaxBandwidth(TargetTransformInfo::RGK_ScalableVector) ||
7000-
CM.useMaxBandwidth(TargetTransformInfo::RGK_FixedWidthVector))
7000+
if (any_of(VFs, [this](ElementCount VF) {
7001+
return CM.shouldConsiderRegPressureForVF(VF);
7002+
}))
70017003
RUs = calculateRegisterUsageForPlan(*P, VFs, TTI, CM.ValuesToIgnore);
70027004

70037005
for (unsigned I = 0; I < VFs.size(); I++) {
@@ -7023,7 +7025,7 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() {
70237025
InstructionCost Cost = cost(*P, VF);
70247026
VectorizationFactor CurrentFactor(VF, Cost, ScalarCost);
70257027

7026-
if (CM.shouldCalculateRegPressureForVF(VF) &&
7028+
if (CM.shouldConsiderRegPressureForVF(VF) &&
70277029
RUs[I].exceedsMaxNumRegs(TTI, ForceTargetNumVectorRegs)) {
70287030
LLVM_DEBUG(dbgs() << "LV(REG): Not considering vector loop of width "
70297031
<< 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)