[llvm] 9a9a78e - [VPlan] Handle most bin-ops in VPReplicateRecipe::computeCost. (NFC)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun May 11 05:51:27 PDT 2025
Author: Florian Hahn
Date: 2025-05-11T13:51:14+01:00
New Revision: 9a9a78eacb4c27805acd7ddc8952faf5c22aa5ea
URL: https://github.com/llvm/llvm-project/commit/9a9a78eacb4c27805acd7ddc8952faf5c22aa5ea
DIFF: https://github.com/llvm/llvm-project/commit/9a9a78eacb4c27805acd7ddc8952faf5c22aa5ea.diff
LOG: [VPlan] Handle most bin-ops in VPReplicateRecipe::computeCost. (NFC)
Directly compute costs for binary ops and GEPs in
VPReplicateRecipe::computeCost. This simply ports the legacy cost
computation for uniform/replicating binary ops to the VPlan cost model.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 6a4ffac200b1c..12fd6280c6fb4 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -2711,6 +2711,40 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
// VPReplicateRecipe may be cloned as part of an existing VPlan-to-VPlan
// transform, avoid computing their cost multiple times for now.
Ctx.SkipCostComputation.insert(UI);
+
+ TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
+ Type *ResultTy = Ctx.Types.inferScalarType(this);
+ switch (UI->getOpcode()) {
+ case Instruction::GetElementPtr:
+ // We mark this instruction as zero-cost because the cost of GEPs in
+ // vectorized code depends on whether the corresponding memory instruction
+ // is scalarized or not. Therefore, we handle GEPs with the memory
+ // instruction cost.
+ return 0;
+ case Instruction::Add:
+ case Instruction::Sub:
+ case Instruction::FAdd:
+ case Instruction::FSub:
+ case Instruction::Mul:
+ case Instruction::FMul:
+ case Instruction::FDiv:
+ case Instruction::FRem:
+ case Instruction::Shl:
+ case Instruction::LShr:
+ case Instruction::AShr:
+ case Instruction::And:
+ case Instruction::Or:
+ case Instruction::Xor: {
+ auto Op2Info = Ctx.getOperandInfo(getOperand(1));
+ SmallVector<const Value *, 4> Operands(UI->operand_values());
+ return Ctx.TTI.getArithmeticInstrCost(
+ UI->getOpcode(), ResultTy, CostKind,
+ {TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None},
+ Op2Info, Operands, UI, &Ctx.TLI) *
+ (isUniform() ? 1 : VF.getKnownMinValue());
+ }
+ }
+
return Ctx.getLegacyCost(UI, VF);
}
More information about the llvm-commits
mailing list