[llvm] [VPlan] Compute cost of some VPWidenIntOrFpInductions in VPlan (PR #202232)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 10 08:25:58 PDT 2026
================
@@ -2838,6 +2838,28 @@ bool VPWidenIntOrFpInductionRecipe::isCanonical() const {
getScalarType() == getRegion()->getCanonicalIVType();
}
+InstructionCost
+VPWidenIntOrFpInductionRecipe::computeCost(ElementCount VF,
+ VPCostContext &Ctx) const {
+ // A widened induction generates a vector phi and increments it by the
+ // splatted step each iteration.
+ // TODO: Also handle truncated inductions.
+ assert(!getTruncInst() &&
+ "truncated inductions should be costed by the legacy model");
+ const InductionDescriptor &ID = getInductionDescriptor();
+
+ InstructionCost Cost = Ctx.TTI.getCFInstrCost(Instruction::PHI, Ctx.CostKind);
+
+ Type *StepTy = getScalarType();
+ unsigned IncOpc = ID.getKind() == InductionDescriptor::IK_IntInduction
+ ? Instruction::Add
+ : ID.getInductionOpcode();
+ assert(IncOpc != Instruction::BinaryOpsEnd &&
+ "induction must have a valid increment opcode");
+ return Cost + Ctx.TTI.getArithmeticInstrCost(IncOpc, toVectorTy(StepTy, VF),
----------------
david-arm wrote:
It might be worth adding at least one cost test for non integer inductions, i.e. to test the case where we use `ID.getInductionOpcode()` as the increment opcode. In theory, the induction opcode could Sub, FAdd, FSub, etc., although in practice it's probably just FAdd.
https://github.com/llvm/llvm-project/pull/202232
More information about the llvm-commits
mailing list