[llvm] [CostModel][Test] Replace multiple flags with `-intrinsic-cost-strategy` (PR #128885)
Benjamin Maxwell via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 26 08:29:23 PST 2025
https://github.com/MacDue updated https://github.com/llvm/llvm-project/pull/128885
>From 598f2ebb664abca7742492ede031db4a946c1f42 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell <benjamin.maxwell at arm.com>
Date: Wed, 26 Feb 2025 14:28:53 +0000
Subject: [PATCH 1/2] [CostModel][Test] Replace multiple flags with
`-intrinsic-cost-strategy`
This replaces the `-prefer-intrinsic-cost` and `type-based-intrinsic-cost`
flags with a single `-intrinsic-cost-strategy=<strategy>` flag.
The possible strategies are:
* `instruction-cost`
- Use TargetTransformInfo::getInstructionCost()
* `intrinsic-cost`
- Use TargetTransformInfo::getIntrinsicInstrCost()
* `type-based-intrinsic-cost`
- Calculate intrinsics cost based only on argument types
---
llvm/lib/Analysis/CostModel.cpp | 30 +++++++++++++------
.../test/Analysis/CostModel/AArch64/sincos.ll | 2 +-
.../CostModel/AArch64/sve-intrinsics.ll | 2 +-
llvm/test/Analysis/CostModel/RISCV/cast.ll | 4 +--
llvm/test/Analysis/CostModel/RISCV/cmp.ll | 4 +--
.../RISCV/rvv-expandload-compressstore.ll | 2 +-
.../Analysis/CostModel/RISCV/rvv-select.ll | 2 +-
.../Analysis/CostModel/RISCV/vp-intrinsics.ll | 2 +-
8 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/llvm/lib/Analysis/CostModel.cpp b/llvm/lib/Analysis/CostModel.cpp
index 68cb536bf7891..59904fa4bf40e 100644
--- a/llvm/lib/Analysis/CostModel.cpp
+++ b/llvm/lib/Analysis/CostModel.cpp
@@ -40,14 +40,24 @@ static cl::opt<TargetTransformInfo::TargetCostKind> CostKind(
clEnumValN(TargetTransformInfo::TCK_SizeAndLatency,
"size-latency", "Code size and latency")));
-static cl::opt<bool> TypeBasedIntrinsicCost("type-based-intrinsic-cost",
- cl::desc("Calculate intrinsics cost based only on argument types"),
- cl::init(false));
+enum class IntrinsicCostStrategy {
+ InstructionCost,
+ IntrinsicCost,
+ TypeBasedIntrinsicCost,
+};
-static cl::opt<bool> PreferIntrinsicCost(
- "prefer-intrinsic-cost",
- cl::desc("Prefer using getIntrinsicInstrCost over getInstructionCost"),
- cl::init(false));
+static cl::opt<IntrinsicCostStrategy> IntrinsicCost(
+ "intrinsic-cost-strategy",
+ cl::desc("Costing strategy for intrinsic instructions"),
+ cl::init(IntrinsicCostStrategy::InstructionCost),
+ cl::values(
+ clEnumValN(IntrinsicCostStrategy::InstructionCost, "instruction-cost",
+ "Use TargetTransformInfo::getInstructionCost"),
+ clEnumValN(IntrinsicCostStrategy::IntrinsicCost, "intrinsic-cost",
+ "Use TargetTransformInfo::getIntrinsicInstrCost"),
+ clEnumValN(IntrinsicCostStrategy::TypeBasedIntrinsicCost,
+ "type-based-intrinsic-cost",
+ "Calculate intrinsics cost based only on argument types")));
#define CM_NAME "cost-model"
#define DEBUG_TYPE CM_NAME
@@ -63,10 +73,12 @@ PreservedAnalyses CostModelPrinterPass::run(Function &F,
// which cost kind to print.
InstructionCost Cost;
auto *II = dyn_cast<IntrinsicInst>(&Inst);
- if (II && (PreferIntrinsicCost || TypeBasedIntrinsicCost)) {
+ if (II && IntrinsicCost != IntrinsicCostStrategy::InstructionCost) {
IntrinsicCostAttributes ICA(
II->getIntrinsicID(), *II, InstructionCost::getInvalid(),
- /*TypeBasedOnly=*/TypeBasedIntrinsicCost, &TLI);
+ /*TypeBasedOnly=*/IntrinsicCost ==
+ IntrinsicCostStrategy::TypeBasedIntrinsicCost,
+ &TLI);
Cost = TTI.getIntrinsicInstrCost(ICA, CostKind);
} else {
Cost = TTI.getInstructionCost(&Inst, CostKind);
diff --git a/llvm/test/Analysis/CostModel/AArch64/sincos.ll b/llvm/test/Analysis/CostModel/AArch64/sincos.ll
index e32c51667e0ad..32408acb582d0 100644
--- a/llvm/test/Analysis/CostModel/AArch64/sincos.ll
+++ b/llvm/test/Analysis/CostModel/AArch64/sincos.ll
@@ -1,6 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --filter "sincos"
; RUN: opt < %s -mtriple=aarch64-gnu-linux -mattr=+neon,+sve -passes="print<cost-model>" -cost-kind=throughput 2>&1 -disable-output | FileCheck %s
-; RUN: opt < %s -mtriple=aarch64-gnu-linux -mattr=+neon,+sve -vector-library=ArmPL -passes="print<cost-model>" -prefer-intrinsic-cost -cost-kind=throughput 2>&1 -disable-output | FileCheck %s -check-prefix=CHECK-VECLIB
+; RUN: opt < %s -mtriple=aarch64-gnu-linux -mattr=+neon,+sve -vector-library=ArmPL -passes="print<cost-model>" -intrinsic-cost-strategy=intrinsic-cost -cost-kind=throughput 2>&1 -disable-output | FileCheck %s -check-prefix=CHECK-VECLIB
define void @sincos() {
; CHECK-LABEL: 'sincos'
diff --git a/llvm/test/Analysis/CostModel/AArch64/sve-intrinsics.ll b/llvm/test/Analysis/CostModel/AArch64/sve-intrinsics.ll
index 0bf776b5c97e3..d707d71bbd734 100644
--- a/llvm/test/Analysis/CostModel/AArch64/sve-intrinsics.ll
+++ b/llvm/test/Analysis/CostModel/AArch64/sve-intrinsics.ll
@@ -1,7 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -S -mtriple=aarch64--linux-gnu -mattr=+sve | FileCheck %s --check-prefix=CHECK-VSCALE-1
; RUN: opt < %s -passes="print<cost-model>" 2>&1 -mcpu=neoverse-v1 -disable-output -S -mtriple=aarch64--linux-gnu -mattr=+sve | FileCheck %s --check-prefix=CHECK-VSCALE-2
-; RUN: opt < %s -passes="print<cost-model>" 2>&1 -type-based-intrinsic-cost -disable-output -S -mtriple=aarch64--linux-gnu -mattr=+sve | FileCheck %s --check-prefix=TYPE_BASED_ONLY
+; RUN: opt < %s -passes="print<cost-model>" 2>&1 -intrinsic-cost-strategy=type-based-intrinsic-cost -disable-output -S -mtriple=aarch64--linux-gnu -mattr=+sve | FileCheck %s --check-prefix=TYPE_BASED_ONLY
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
diff --git a/llvm/test/Analysis/CostModel/RISCV/cast.ll b/llvm/test/Analysis/CostModel/RISCV/cast.ll
index 04048b8ba17f1..e498ccc733040 100644
--- a/llvm/test/Analysis/CostModel/RISCV/cast.ll
+++ b/llvm/test/Analysis/CostModel/RISCV/cast.ll
@@ -1,6 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
-; RUN: opt < %s -mtriple=riscv32 -mattr=+v,+zfh,+zvfh -passes="print<cost-model>" -cost-kind=throughput --type-based-intrinsic-cost=true 2>&1 -disable-output | FileCheck %s --check-prefixes=CHECK,RV32
-; RUN: opt < %s -mtriple=riscv64 -mattr=+v,+zfh,+zvfh -passes="print<cost-model>" -cost-kind=throughput --type-based-intrinsic-cost=true 2>&1 -disable-output | FileCheck %s --check-prefixes=CHECK,RV64
+; RUN: opt < %s -mtriple=riscv32 -mattr=+v,+zfh,+zvfh -passes="print<cost-model>" -cost-kind=throughput -intrinsic-cost-strategy=type-based-intrinsic-cost 2>&1 -disable-output | FileCheck %s --check-prefixes=CHECK,RV32
+; RUN: opt < %s -mtriple=riscv64 -mattr=+v,+zfh,+zvfh -passes="print<cost-model>" -cost-kind=throughput -intrinsic-cost-strategy=type-based-intrinsic-cost 2>&1 -disable-output | FileCheck %s --check-prefixes=CHECK,RV64
define void @sext() {
; RV32-LABEL: 'sext'
diff --git a/llvm/test/Analysis/CostModel/RISCV/cmp.ll b/llvm/test/Analysis/CostModel/RISCV/cmp.ll
index b820baf5acf85..69d4f27ac41be 100644
--- a/llvm/test/Analysis/CostModel/RISCV/cmp.ll
+++ b/llvm/test/Analysis/CostModel/RISCV/cmp.ll
@@ -1,6 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
-; RUN: opt < %s -mtriple=riscv32 -mattr=+v,+f -passes="print<cost-model>" -cost-kind=throughput --type-based-intrinsic-cost=true 2>&1 -disable-output | FileCheck %s --check-prefixes=CHECK,RV32
-; RUN: opt < %s -mtriple=riscv64 -mattr=+v,+f -passes="print<cost-model>" -cost-kind=throughput --type-based-intrinsic-cost=true 2>&1 -disable-output | FileCheck %s --check-prefixes=CHECK,RV64
+; RUN: opt < %s -mtriple=riscv32 -mattr=+v,+f -passes="print<cost-model>" -cost-kind=throughput -intrinsic-cost-strategy=type-based-intrinsic-cost 2>&1 -disable-output | FileCheck %s --check-prefixes=CHECK,RV32
+; RUN: opt < %s -mtriple=riscv64 -mattr=+v,+f -passes="print<cost-model>" -cost-kind=throughput -intrinsic-cost-strategy=type-based-intrinsic-cost 2>&1 -disable-output | FileCheck %s --check-prefixes=CHECK,RV64
define void @icmp() {
; RV32-LABEL: 'icmp'
diff --git a/llvm/test/Analysis/CostModel/RISCV/rvv-expandload-compressstore.ll b/llvm/test/Analysis/CostModel/RISCV/rvv-expandload-compressstore.ll
index ea5f3444fa248..e0f80f541bc19 100644
--- a/llvm/test/Analysis/CostModel/RISCV/rvv-expandload-compressstore.ll
+++ b/llvm/test/Analysis/CostModel/RISCV/rvv-expandload-compressstore.ll
@@ -1,6 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -S -mtriple=riscv64 -mattr=+v,+zvfhmin,+zvfbfmin | FileCheck %s
-; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -S -mtriple=riscv64 -mattr=+v,+zvfhmin,+zvfbfmin --type-based-intrinsic-cost=true | FileCheck %s --check-prefixes=TYPEBASED
+; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -S -mtriple=riscv64 -mattr=+v,+zvfhmin,+zvfbfmin -intrinsic-cost-strategy=type-based-intrinsic-cost | FileCheck %s --check-prefixes=TYPEBASED
define void @expand_load() {
; CHECK-LABEL: 'expand_load'
diff --git a/llvm/test/Analysis/CostModel/RISCV/rvv-select.ll b/llvm/test/Analysis/CostModel/RISCV/rvv-select.ll
index 6ab8ac64d64e4..748492c32630e 100644
--- a/llvm/test/Analysis/CostModel/RISCV/rvv-select.ll
+++ b/llvm/test/Analysis/CostModel/RISCV/rvv-select.ll
@@ -1,6 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
; RUN: opt -passes="print<cost-model>" 2>&1 -disable-output -mtriple=riscv64 -mattr=+v,+f,+d,+zfh,+zvfh -riscv-v-fixed-length-vector-lmul-max=1 < %s | FileCheck %s
-; RUN: opt -passes="print<cost-model>" 2>&1 -disable-output -mtriple=riscv64 -mattr=+v,+f,+d,+zfh,+zvfh -riscv-v-fixed-length-vector-lmul-max=1 --type-based-intrinsic-cost=true < %s | FileCheck %s
+; RUN: opt -passes="print<cost-model>" 2>&1 -disable-output -mtriple=riscv64 -mattr=+v,+f,+d,+zfh,+zvfh -riscv-v-fixed-length-vector-lmul-max=1 -intrinsic-cost-strategy=type-based-intrinsic-cost < %s | FileCheck %s
; Check that we don't crash querying costs when vectors are not enabled.
; RUN: opt -passes="print<cost-model>" 2>&1 -disable-output -mtriple=riscv64
diff --git a/llvm/test/Analysis/CostModel/RISCV/vp-intrinsics.ll b/llvm/test/Analysis/CostModel/RISCV/vp-intrinsics.ll
index 7fc91e7049aa3..04b1d18fca8ee 100644
--- a/llvm/test/Analysis/CostModel/RISCV/vp-intrinsics.ll
+++ b/llvm/test/Analysis/CostModel/RISCV/vp-intrinsics.ll
@@ -1,6 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -S -mtriple=riscv64 -mattr=+v,+zvfhmin,+zvfbfmin | FileCheck %s --check-prefixes=CHECK,ARGBASED
-; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -S -mtriple=riscv64 -mattr=+v,+zvfhmin,+zvfbfmin --type-based-intrinsic-cost=true | FileCheck %s --check-prefixes=CHECK,TYPEBASED
+; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -S -mtriple=riscv64 -mattr=+v,+zvfhmin,+zvfbfmin -intrinsic-cost-strategy=type-based-intrinsic-cost | FileCheck %s --check-prefixes=CHECK,TYPEBASED
define void @unsupported_fp_ops(<vscale x 4 x float> %vec, i32 %extraarg) {
; CHECK-LABEL: 'unsupported_fp_ops'
>From a5bdbae39d37816b4729d4fe96c22e0395d70740 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell <benjamin.maxwell at arm.com>
Date: Wed, 26 Feb 2025 16:28:26 +0000
Subject: [PATCH 2/2] Fixups
---
llvm/lib/Analysis/CostModel.cpp | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Analysis/CostModel.cpp b/llvm/lib/Analysis/CostModel.cpp
index 59904fa4bf40e..27a946c846e67 100644
--- a/llvm/lib/Analysis/CostModel.cpp
+++ b/llvm/lib/Analysis/CostModel.cpp
@@ -55,9 +55,10 @@ static cl::opt<IntrinsicCostStrategy> IntrinsicCost(
"Use TargetTransformInfo::getInstructionCost"),
clEnumValN(IntrinsicCostStrategy::IntrinsicCost, "intrinsic-cost",
"Use TargetTransformInfo::getIntrinsicInstrCost"),
- clEnumValN(IntrinsicCostStrategy::TypeBasedIntrinsicCost,
- "type-based-intrinsic-cost",
- "Calculate intrinsics cost based only on argument types")));
+ clEnumValN(
+ IntrinsicCostStrategy::TypeBasedIntrinsicCost,
+ "type-based-intrinsic-cost",
+ "Calculate the intrinsic cost based only on argument types")));
#define CM_NAME "cost-model"
#define DEBUG_TYPE CM_NAME
More information about the llvm-commits
mailing list