[llvm] [LV] Add initial cost model for VPScalarIVSteps (PR #203347)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 12 03:04:52 PDT 2026


================
@@ -2960,6 +2960,39 @@ void VPDerivedIVRecipe::printRecipe(raw_ostream &O, const Twine &Indent,
 }
 #endif
 
+InstructionCost VPScalarIVStepsRecipe::computeCost(ElementCount VF,
+                                                   VPCostContext &Ctx) const {
+  // TODO: Add costs for floating point.
+  Type *BaseIVTy = getOperand(0)->getScalarType();
+  if (!BaseIVTy->isIntegerTy())
+    return 0;
+
+  // TODO: Add support for predicated regions. Requires scaling the cost by the
+  // probability of entering the block.
+  if (getRegion() && getRegion()->isReplicator())
+    return 0;
+
+  // Typically the operations are:
+  //   1. Add the start index to each lane value.
+  //   2. Multiply the start index by the step.
+  //   3. Add the scaled start index to base IV.
+  // Any code generated for 1 and 2 should be loop invariant and therefore
+  // hoisted out of the loop. We only need to add on the cost of 3.
+
+  // Determine the number of scalar adds we need to generate.
+  const unsigned NumLanes =
+      vputils::onlyFirstLaneUsed(this) ? 1 : VF.getKnownMinValue();
----------------
paulwalker-arm wrote:

This is a scalarisation cost? If so then presumably scalable vectors aren't allowed? Does that mean you can use `getFixedValue()` here?

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


More information about the llvm-commits mailing list