[llvm] [RISCV] Add a command line option to disable cost per use for compressed registers. (PR #83320)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 28 11:20:38 PST 2024


https://github.com/topperc created https://github.com/llvm/llvm-project/pull/83320

I've seen cases where the cost per use increase the number of spills. Disabling improves the codegen for #79918.

I propose adding this option to allow easier experimentation.

>From eb4f3a478c776636d879e32cadd0f59d7a2456d1 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Wed, 28 Feb 2024 11:02:09 -0800
Subject: [PATCH] [RISCV] Add a command line option to disable cost per use for
 compressed registers.

I've seen cases where the cost per use increase the number of spills.
Disabling improves the codegen for #79918.

I propose adding this option to allow easier experimentation.
---
 llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
index 9d1f01dffaaf47..a68674b221d38e 100644
--- a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
@@ -30,6 +30,8 @@
 
 using namespace llvm;
 
+static cl::opt<bool> DisableCostPerUse("riscv-disable-cost-per-use",
+                                       cl::init(false), cl::Hidden);
 static cl::opt<bool>
     DisableRegAllocHints("riscv-disable-regalloc-hints", cl::Hidden,
                          cl::init(false),
@@ -712,7 +714,10 @@ void RISCVRegisterInfo::getOffsetOpcodes(const StackOffset &Offset,
 
 unsigned
 RISCVRegisterInfo::getRegisterCostTableIndex(const MachineFunction &MF) const {
-  return MF.getSubtarget<RISCVSubtarget>().hasStdExtCOrZca() ? 1 : 0;
+  return MF.getSubtarget<RISCVSubtarget>().hasStdExtCOrZca() &&
+                 !DisableCostPerUse
+             ? 1
+             : 0;
 }
 
 // Add two address hints to improve chances of being able to use a compressed



More information about the llvm-commits mailing list