[llvm] [VPlan] Compute scalar cost based on VPlan0 instead of legacy CM. (PR #196845)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 07:26:40 PDT 2026


================
@@ -1480,15 +1505,39 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
     return getCostForRecipeWithOpcode(
         getOpcode(),
         vputils::onlyFirstLaneUsed(this) ? ElementCount::getFixed(1) : VF, Ctx);
+  case Instruction::ExtractValue:
+  case Instruction::FNeg:
+  case Instruction::Freeze:
+    if (!VF.isScalar() || !getUnderlyingValue())
+      return 0;
+    return getCostForRecipeWithOpcode(getOpcode(), VF, Ctx);
+
+  case Instruction::Store:
+    assert(VF.isScalar() && "only scalar VF expected");
+    return getCostForRecipeWithOpcode(getOpcode(), VF, Ctx);
+  case Instruction::Call: {
+    assert(VF.isScalar() && "only scalar VF expected");
+    auto *CalledFn =
+        cast<Function>(getOperand(getNumOperands() - 1)->getLiveInIRValue());
+    SmallVector<const VPValue *> ArgOps(drop_end(operands()));
+    return VPReplicateRecipe::computeCallCost(CalledFn, getScalarType(), ArgOps,
+                                              /*IsSingleScalar=*/true, VF, Ctx);
+  }
+  case VPInstruction::BranchOnCond:
+  case Instruction::PHI:
+    if (!getUnderlyingValue())
+      return 0;
----------------
fhahn wrote:

Updated to break and moved the assert outside the switch, so it should still be covered.

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


More information about the llvm-commits mailing list