[llvm] [RISCV] Add TuneJumpIsExpensive (PR #191374)
Pengcheng Wang via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 10 02:59:46 PDT 2026
https://github.com/wangpc-pp updated https://github.com/llvm/llvm-project/pull/191374
>From dbc3d0cc2c52cd3f2b2101d150249040b4267ed1 Mon Sep 17 00:00:00 2001
From: Pengcheng Wang <wangpengcheng.pp at bytedance.com>
Date: Fri, 10 Apr 2026 17:42:03 +0800
Subject: [PATCH] [RISCV] Add TuneJumpIsExpensive
We have `setJumpIsExpensive(true)` before 18.x but it was removed
in #74647. This feature allows users to tune the ISel behavior.
We have #80124 and #178394 landed, so it should be more flexible
to tune branches and selects now.
This is an alternative of #191158.
---
llvm/lib/Target/RISCV/RISCVFeatures.td | 4 ++++
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 2 ++
llvm/test/CodeGen/RISCV/features-info.ll | 1 +
llvm/unittests/TargetParser/RISCVTargetParserTest.cpp | 3 ++-
4 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 492c44a35b35a..ccc07e5518048 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -2051,6 +2051,10 @@ def TunePreferVsetvliOverReadVLENB
"prefer-vsetvli-over-read-vlenb", "PreferVsetvliOverReadVLENB",
"true", "Prefer vsetvli over read vlenb CSR to calculate VLEN">;
+def TuneJumpIsExpensive
+ : RISCVSimpleTuneFeature<"jump-is-expensive", "IsJumpExpensive",
+ "true", "Jump is expensive">;
+
//===----------------------------------------------------------------------===//
// CPU Families (alphabetized by vendor).
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index ce8cd0f6f5776..dc427f54c4e07 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -1914,6 +1914,8 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
setMaxLargeFPConvertBitWidthSupported(Subtarget.is64Bit() ? 128 : 64);
+ setJumpIsExpensive(Subtarget.isJumpExpensive());
+
// Disable strict node mutation.
IsStrictFPEnabled = true;
EnableExtLdPromotion = true;
diff --git a/llvm/test/CodeGen/RISCV/features-info.ll b/llvm/test/CodeGen/RISCV/features-info.ll
index 7c4271b409f82..4be8273430a2e 100644
--- a/llvm/test/CodeGen/RISCV/features-info.ll
+++ b/llvm/test/CodeGen/RISCV/features-info.ll
@@ -62,6 +62,7 @@
; CHECK-NEXT: fusion-zextw - Enable SLLI+SRLI to be fused to zero extension of word.
; CHECK-NEXT: h - 'H' (Hypervisor).
; CHECK-NEXT: i - 'I' (Base Integer Instruction Set).
+; CHECK-NEXT: jump-is-expensive - Jump is expensive.
; CHECK-NEXT: log-vrgather - Has vrgather.vv with LMUL*log2(LMUL) latency
; CHECK-NEXT: m - 'M' (Integer Multiplication and Division).
; CHECK-NEXT: mips-p8700 - MIPS p8700 processor.
diff --git a/llvm/unittests/TargetParser/RISCVTargetParserTest.cpp b/llvm/unittests/TargetParser/RISCVTargetParserTest.cpp
index 0302d56e3e3fa..3949e0f0bab0a 100644
--- a/llvm/unittests/TargetParser/RISCVTargetParserTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVTargetParserTest.cpp
@@ -44,13 +44,14 @@ TEST(RISCVTuneFeature, AllTuneFeatures) {
RISCV::getAllTuneFeatures(AllTuneFeatures);
// Only allowed subtarget features that are explicitly marked by
// special TableGen class.
- EXPECT_EQ(AllTuneFeatures.size(), 20U);
+ EXPECT_EQ(AllTuneFeatures.size(), 21U);
for (auto F : {"conditional-cmv-fusion",
"disable-latency-sched-heuristic",
"disable-misched-load-clustering",
"disable-misched-store-clustering",
"disable-postmisched-load-clustering",
"disable-postmisched-store-clustering",
+ "jump-is-expensive",
"single-element-vec-fp64",
"no-default-unroll",
"no-sink-splat-operands",
More information about the llvm-commits
mailing list