[llvm] [CostModel] Handle vector struct results and cost `llvm.sincos` (PR #123210)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 25 03:51:55 PST 2025


================
@@ -42,25 +44,31 @@ static cl::opt<bool> TypeBasedIntrinsicCost("type-based-intrinsic-cost",
     cl::desc("Calculate intrinsics cost based only on argument types"),
     cl::init(false));
 
+static cl::opt<bool> LibCallBasedIntrinsicCost(
+    "libcall-based-intrinsic-cost",
+    cl::desc("Calculate intrinsics cost using target library info"),
+    cl::init(false));
+
 #define CM_NAME "cost-model"
 #define DEBUG_TYPE CM_NAME
 
 PreservedAnalyses CostModelPrinterPass::run(Function &F,
                                             FunctionAnalysisManager &AM) {
   auto &TTI = AM.getResult<TargetIRAnalysis>(F);
+  auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
   OS << "Printing analysis 'Cost Model Analysis' for function '" << F.getName() << "':\n";
   for (BasicBlock &B : F) {
     for (Instruction &Inst : B) {
       // TODO: Use a pass parameter instead of cl::opt CostKind to determine
       // which cost kind to print.
       InstructionCost Cost;
       auto *II = dyn_cast<IntrinsicInst>(&Inst);
-      if (II && TypeBasedIntrinsicCost) {
-        IntrinsicCostAttributes ICA(II->getIntrinsicID(), *II,
-                                    InstructionCost::getInvalid(), true);
+      if (II && (LibCallBasedIntrinsicCost || TypeBasedIntrinsicCost)) {
+        IntrinsicCostAttributes ICA(
+            II->getIntrinsicID(), *II, InstructionCost::getInvalid(),
+            /*TypeBasedOnly=*/TypeBasedIntrinsicCost, &TLI);
----------------
MacDue wrote:

I've renamed the flag `prefer-intrinsic-cost` for this PR. The enum works nicely :+1:, but since it does increase the churn a bit I agree it's best to post that as a small follow-up PR. 

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


More information about the llvm-commits mailing list