[llvm] 4790b21 - [VPlan] Add more generic VPCostContext::getCostDivisor (NFC). (#225413)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 22 08:48:53 PDT 2026
Author: Florian Hahn
Date: 2026-09-22T16:48:47+01:00
New Revision: 4790b21292d10b2cab1037ebef100e7f595e4209
URL: https://github.com/llvm/llvm-project/commit/4790b21292d10b2cab1037ebef100e7f595e4209
DIFF: https://github.com/llvm/llvm-project/commit/4790b21292d10b2cab1037ebef100e7f595e4209.diff
LOG: [VPlan] Add more generic VPCostContext::getCostDivisor (NFC). (#225413)
Replace getReplicateRegionCostDivisor with more general getCostDivisor,
which takes a frequency directly.
The frequency lookup is now done at the 3 call sites, which all have the
region at hand.
Will also be used in https://github.com/llvm/llvm-project/pull/196845.
PR: https://github.com/llvm/llvm-project/pull/225413
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.cpp
llvm/lib/Transforms/Vectorize/VPlanHelpers.h
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index fd6e77fffde7b..8071075701401 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -1950,13 +1950,9 @@ bool VPCostContext::isFreeScalarIntrinsic(Intrinsic::ID ID) {
ID);
}
-uint64_t VPCostContext::getReplicateRegionCostDivisor(
- const VPRegionBlock *Region) const {
- if (CostKind == TTI::TCK_CodeSize)
- return 1;
- std::optional<VPExecutionFrequency> Freq =
- Region->getEntryBranchOnMask()->getExecutionFrequency();
- if (!Freq)
+uint64_t
+VPCostContext::getCostDivisor(std::optional<VPExecutionFrequency> Freq) const {
+ if (CostKind == TTI::TCK_CodeSize || !Freq)
return 1;
// A recorded frequency is neither zero nor always-executing, so the
// probability is non-zero and the division below is safe.
diff --git a/llvm/lib/Transforms/Vectorize/VPlanHelpers.h b/llvm/lib/Transforms/Vectorize/VPlanHelpers.h
index 3b7218ff1f908..b991dd12d3e34 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanHelpers.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanHelpers.h
@@ -352,9 +352,9 @@ struct VPCostContext {
/// transform replaced the original recipe.
void invalidateWideningDecision(Instruction *I, ElementCount VF);
- /// \returns how much the cost of the block predicated by replicate region
- /// \p Region should be divided by.
- uint64_t getReplicateRegionCostDivisor(const VPRegionBlock *Region) const;
+ /// \returns how much the cost of a block executing with recorded frequency
+ /// \p Freq should be divided by.
+ uint64_t getCostDivisor(std::optional<VPExecutionFrequency> Freq) const;
/// Returns true if \p I is known to be scalarized at \p VF.
bool willBeScalarized(Instruction *I, ElementCount VF) const;
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 602aff8090bf8..38c94512f0546 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -3236,7 +3236,8 @@ InstructionCost VPScalarIVStepsRecipe::computeCost(ElementCount VF,
// probability.
const VPRegionBlock *Region = getRegion();
if (Region && Region->isReplicator())
- Cost /= Ctx.getReplicateRegionCostDivisor(Region);
+ Cost /= Ctx.getCostDivisor(
+ Region->getEntryBranchOnMask()->getExecutionFrequency());
return Cost;
}
@@ -4067,7 +4068,8 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
// Scale the cost by the probability of executing the predicated blocks.
// This assumes the predicated block for each vector lane is equally
// likely.
- ScalarCost /= Ctx.getReplicateRegionCostDivisor(getRegion());
+ ScalarCost /= Ctx.getCostDivisor(
+ getRegion()->getEntryBranchOnMask()->getExecutionFrequency());
return ScalarCost;
}
case Instruction::Load:
@@ -4126,7 +4128,8 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
if (ParentRegion && ParentRegion->isReplicator()) {
if (!PtrSCEV)
break;
- Cost /= Ctx.getReplicateRegionCostDivisor(ParentRegion);
+ Cost /= Ctx.getCostDivisor(
+ ParentRegion->getEntryBranchOnMask()->getExecutionFrequency());
Cost += Ctx.TTI.getCFInstrCost(Instruction::CondBr, Ctx.CostKind);
auto *VecI1Ty = VectorType::get(
More information about the llvm-commits
mailing list