Skip to content

Commit 9a9a78e

Browse files
committed
[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.
1 parent acd6294 commit 9a9a78e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,6 +2711,40 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
27112711
// VPReplicateRecipe may be cloned as part of an existing VPlan-to-VPlan
27122712
// transform, avoid computing their cost multiple times for now.
27132713
Ctx.SkipCostComputation.insert(UI);
2714+
2715+
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
2716+
Type *ResultTy = Ctx.Types.inferScalarType(this);
2717+
switch (UI->getOpcode()) {
2718+
case Instruction::GetElementPtr:
2719+
// We mark this instruction as zero-cost because the cost of GEPs in
2720+
// vectorized code depends on whether the corresponding memory instruction
2721+
// is scalarized or not. Therefore, we handle GEPs with the memory
2722+
// instruction cost.
2723+
return 0;
2724+
case Instruction::Add:
2725+
case Instruction::Sub:
2726+
case Instruction::FAdd:
2727+
case Instruction::FSub:
2728+
case Instruction::Mul:
2729+
case Instruction::FMul:
2730+
case Instruction::FDiv:
2731+
case Instruction::FRem:
2732+
case Instruction::Shl:
2733+
case Instruction::LShr:
2734+
case Instruction::AShr:
2735+
case Instruction::And:
2736+
case Instruction::Or:
2737+
case Instruction::Xor: {
2738+
auto Op2Info = Ctx.getOperandInfo(getOperand(1));
2739+
SmallVector<const Value *, 4> Operands(UI->operand_values());
2740+
return Ctx.TTI.getArithmeticInstrCost(
2741+
UI->getOpcode(), ResultTy, CostKind,
2742+
{TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None},
2743+
Op2Info, Operands, UI, &Ctx.TLI) *
2744+
(isUniform() ? 1 : VF.getKnownMinValue());
2745+
}
2746+
}
2747+
27142748
return Ctx.getLegacyCost(UI, VF);
27152749
}
27162750

0 commit comments

Comments
 (0)