[llvm] e454d31 - [VPlan] Factor out precomputing costs from LVP::cost (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 22 12:41:10 PDT 2024
Author: Florian Hahn
Date: 2024-08-22T20:40:38+01:00
New Revision: e454d3103739c19a863a210701cc03528c96dd68
URL: https://github.com/llvm/llvm-project/commit/e454d3103739c19a863a210701cc03528c96dd68
DIFF: https://github.com/llvm/llvm-project/commit/e454d3103739c19a863a210701cc03528c96dd68.diff
LOG: [VPlan] Factor out precomputing costs from LVP::cost (NFC).
Move the logic for pre-computing costs of certain instructions to a
separate helper function, allowing re-use in a follow-up patch.
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
index 3bb7a8e651a3f6..b5f87e458833d6 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
@@ -344,6 +344,12 @@ class LoopVectorizationPlanner {
/// been retired.
InstructionCost cost(VPlan &Plan, ElementCount VF) const;
+ /// Precompute costs for certain instructions using the legacy cost model. The
+ /// function is used to bring up the VPlan-based cost model to initially avoid
+ /// taking
diff erent decisions due to inaccuracies in the legacy cost model.
+ InstructionCost precomputeCosts(VPlan &Plan, ElementCount VF,
+ VPCostContext &CostCtx) const;
+
public:
LoopVectorizationPlanner(
Loop *L, LoopInfo *LI, DominatorTree *DT, const TargetLibraryInfo *TLI,
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 23d0f39ad93ebe..8e9324ba718b39 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -7072,13 +7072,10 @@ bool VPCostContext::skipCostComputation(Instruction *UI, bool IsVector) const {
SkipCostComputation.contains(UI);
}
-InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan,
- ElementCount VF) const {
- InstructionCost Cost = 0;
- LLVMContext &LLVMCtx = OrigLoop->getHeader()->getContext();
- VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(),
- LLVMCtx, CM);
-
+InstructionCost
+LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
+ VPCostContext &CostCtx) const {
+ InstructionCost Cost;
// Cost modeling for inductions is inaccurate in the legacy cost model
// compared to the recipes that are generated. To match here initially during
// VPlan cost model bring up directly use the induction costs from the legacy
@@ -7224,6 +7221,16 @@ InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan,
auto BranchCost = CostCtx.getLegacyCost(BB->getTerminator(), VF);
Cost += BranchCost;
}
+ return Cost;
+}
+
+InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan,
+ ElementCount VF) const {
+ LLVMContext &LLVMCtx = OrigLoop->getHeader()->getContext();
+ VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(),
+ LLVMCtx, CM);
+ InstructionCost Cost = precomputeCosts(Plan, VF, CostCtx);
+
// Now compute and add the VPlan-based cost.
Cost += Plan.cost(VF, CostCtx);
LLVM_DEBUG(dbgs() << "Cost for VF " << VF << ": " << Cost << "\n");
More information about the llvm-commits
mailing list