[llvm] [VPlan] Compute accurate cost for WideCanIV (PR #195017)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 30 02:11:14 PDT 2026


================
@@ -4542,6 +4559,24 @@ void VPWidenCanonicalIVRecipe::execute(VPTransformState &State) {
   State.set(this, CanonicalVectorIV);
 }
 
+InstructionCost
+VPWidenCanonicalIVRecipe::computeCost(ElementCount VF,
+                                      VPCostContext &Ctx) const {
+  if (VF.isScalar())
+    return 0;
+  // execute() emits: broadcast of the scalar IV, a step vector and a vector
+  // add. Charge the broadcast and the add directly. The step vector is
+  // emitted as a VPInstruction::StepVector whose own cost migration is
+  // pending (see VPInstructionWithType::computeCost), so it is not charged
+  // here to avoid front-running that work.
----------------
artagnon wrote:

```suggestion
```

This would get outdated: could also avoid mentioning execute() if you want to keep the comment?

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


More information about the llvm-commits mailing list