[llvm] [VPlan] Implement VPWidenCallRecipe::computeCost (NFCI). (PR #106047)

Shih-Po Hung via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 27 20:00:42 PDT 2024


================
@@ -924,6 +924,46 @@ void VPWidenCallRecipe::execute(VPTransformState &State) {
   }
 }
 
+InstructionCost VPWidenCallRecipe::computeCost(ElementCount VF,
+                                               VPCostContext &Ctx) const {
+  TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
+  if (Variant) {
+    return Ctx.TTI.getCallInstrCost(nullptr, Variant->getReturnType(),
+                                    Variant->getFunctionType()->params(),
+                                    CostKind);
+  }
+
+  FastMathFlags FMF;
+  // TODO: Manage flags via VPRecipeWithIRFlags.
+  if (auto *FPMO = dyn_cast_or_null<FPMathOperator>(getUnderlyingValue()))
+    FMF = FPMO->getFastMathFlags();
+
+  // Some backends analyze intrinsic arguments to determine cost. If all
+  // operands are VPValues with an underlying IR value, use the original IR
+  // values for cost computations.
+  SmallVector<const Value *> Arguments;
+  for (VPValue *Op : operands()) {
+    auto *V = Op->getUnderlyingValue();
+    if (!V) {
+      Arguments.clear();
+      break;
+    }
+    Arguments.push_back(V);
+  }
+
+  Type *RetTy =
+      ToVectorTy(Ctx.Types.inferScalarType(this->getVPSingleValue()), VF);
+  SmallVector<Type *> ParamTys;
+  for (unsigned I = 0; I != getNumOperands(); ++I)
+    ParamTys.push_back(
+        ToVectorTy(Ctx.Types.inferScalarType(getOperand(I)), VF));
+
+  IntrinsicCostAttributes CostAttrs(VectorIntrinsicID, RetTy, Arguments,
+                                    ParamTys, FMF);
+  return Ctx.TTI.getIntrinsicInstrCost(
+      CostAttrs, TargetTransformInfo::TCK_RecipThroughput);
----------------
arcbbb wrote:

nit: we can just use `CostKind` here

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


More information about the llvm-commits mailing list