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

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Mon May 18 06:50:02 PDT 2026


================
@@ -4559,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
----------------
david-arm wrote:

I have a PR for this (see https://github.com/llvm/llvm-project/pull/198291), however there isn't currently a way to write a test for the StepVector case as it always ends up in the preheader.

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


More information about the llvm-commits mailing list