[llvm] [VPlan] Compute cost for binary op VPInstruction with underlying values. (PR #125434)

Hassnaa Hamdi via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 5 04:01:54 PST 2025


================
@@ -768,6 +768,32 @@ void VPInstruction::execute(VPTransformState &State) {
             /*IsScalar*/ GeneratesPerFirstLaneOnly);
 }
 
+InstructionCost VPInstruction::computeCost(ElementCount VF,
+                                           VPCostContext &Ctx) const {
+  if (Instruction::isBinaryOp(getOpcode())) {
+    if (!getUnderlyingValue()) {
+      // TODO: Compute cost for VPInstructions without underlying values once
+      // the legacy cost model has been retired.
+      return 0;
+    }
+
+    assert(!doesGeneratePerAllLanes() &&
+           "Should only generate a vector value or single scalar, not scalars "
+           "for all lanes.");
+    Type *ResTy = Ctx.Types.inferScalarType(this);
+    if (!vputils::onlyFirstLaneUsed(this))
+      ResTy = toVectorTy(ResTy, VF);
+
+    return Ctx.TTI.getArithmeticInstrCost(getOpcode(), ResTy, Ctx.CostKind);
+  }
+
+  // TODO: Compute cost other VPInstructions once the legacy cost model has
+  // been retired.
----------------
hassnaaHamdi wrote:

Thanks Florian for the patch.
I don't understand the reason behind this TODO, it was in the original function also.
If the missing cost computation may cause assert, why it's pending on the retirement of the legacy model ?
That TODO made me confused when I found the related bug.

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


More information about the llvm-commits mailing list