[llvm] [CostModel] Handle vector struct results and cost `llvm.sincos` (PR #123210)
Benjamin Maxwell via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 20 23:50:05 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 only use the `getIntrinsicInstrCost` code path if one of the flags (`type-based-intrinsic-cost` or `libcall-based-intrinsic-cost`) is set as I discovered some targets return a different cost depending on if you call `getIntrinsicInstrCost` directly or via `getInstructionCost`. This seemed to be due to them modifying the cost returned from `getIntrinsicInstrCost` within their implementation of `getInstructionCost`. I didn't want to change tests that depend on this (and it's not relevant for AArch64), so I added a flag.
https://github.com/llvm/llvm-project/pull/123210
More information about the llvm-commits
mailing list