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

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 4 08:57:55 PST 2025


================
@@ -768,6 +768,27 @@ void VPInstruction::execute(VPTransformState &State) {
             /*IsScalar*/ GeneratesPerFirstLaneOnly);
 }
 
+InstructionCost VPInstruction::computeCost(ElementCount VF,
+                                           VPCostContext &Ctx) const {
+  if (Instruction::isBinaryOp(getOpcode())) {
+    if (!getUnderlyingValue())
+      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);
+  }
+
+  assert(!getUnderlyingValue() &&
+         "unexpected VPInstruction without underlying value");
----------------
david-arm wrote:

Should this be `unexpected VPInstruction with underlying value`?

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


More information about the llvm-commits mailing list