[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();
----------------
david-arm wrote:

I guess you're not adding the cost of the stepvector, uitofp, etc. here because these are expected to be loop-invariant and so essentially free? All that should remain is the add of the phi or last unrolled part?

https://github.com/llvm/llvm-project/pull/202232


More information about the llvm-commits mailing list