[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:38 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;
+    return Ctx.TTI.getCFInstrCost(getOpcode() == Instruction::PHI
+                                      ? Instruction::PHI
+                                      : Instruction::CondBr,
+                                  Ctx.CostKind);
   case VPInstruction::ExtractPenultimateElement:
     if (VF == ElementCount::getScalable(1))
       return InstructionCost::getInvalid();
     [[fallthrough]];
   default:
     // TODO: Compute cost other VPInstructions once the legacy cost model has
     // been retired.
-    assert(!getUnderlyingValue() &&
----------------
fhahn wrote:

It is still relevant when VF is not scalar; I am planning on looking into including costs of all VPInstructions in the vector costs, but that is likely going to have a lot more potential fallout.

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


More information about the llvm-commits mailing list