[llvm] [CodeGen] Adjust global-split remat heuristic to match LICM (PR #160709)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 25 07:04:32 PDT 2025


https://github.com/preames created https://github.com/llvm/llvm-project/pull/160709

This heuristic was originally added in 40c4aa with the stated purpose of avoiding global split on live long ranges created by MachineLICM hoisting trivially rematerializable instructions.  In the meantime, various backends have introduced non-trivial rematerialization cases, MachineLICM gained an explicitly triviality check, and we've reworked our APIs to match naming wise.  Let's move this heuristic back to truely trivial remat only.

This is a functional change, though somewhat hard to hit.  This change will cause non-trivially rematerializable instructions to be globally split more often.  This is likely a good thing since non-trivial remat may not be legal at all possible points in the live interval, but may cost slightly more compile time.

I don't have a motivating example; I found it when reviewing the callers of isRemMaterializable(MI).

>From bef1df0986a7036369f3434a1539e6c52bf3d72c Mon Sep 17 00:00:00 2001
From: Philip Reames <preames at rivosinc.com>
Date: Thu, 25 Sep 2025 06:45:30 -0700
Subject: [PATCH] [CodeGen] Adjust global-split remat heuristic to match LICM

This heuristic was originally added in 40c4aa with the stated purpose
of avoiding global split on live long ranges created by MachineLICM
hoisting trivially rematerializable instructions.  In the meantime,
various backends have introduced non-trivial rematerialization cases,
MachineLICM gained an explicitly triviality check, and we've reworked
our APIs to match naming wise.  Let's move this heuristic back to
truely trivial remat only.

This is a functional change, though somewhat hard to hit.  This
change will cause non-trivially rematerializable instructions
to be globally split more often.  This is likely a good thing
since non-trivial remat may not be legal at all possible points
in the live interval, but may cost slightly more compile time.

I don't have a motivating example; I found it when reviewing the
callers of isRemMaterializable(MI).
---
 llvm/lib/CodeGen/TargetRegisterInfo.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/TargetRegisterInfo.cpp b/llvm/lib/CodeGen/TargetRegisterInfo.cpp
index 2e473c6c4e97f..c9e46182decc2 100644
--- a/llvm/lib/CodeGen/TargetRegisterInfo.cpp
+++ b/llvm/lib/CodeGen/TargetRegisterInfo.cpp
@@ -67,7 +67,8 @@ bool TargetRegisterInfo::shouldRegionSplitForVirtReg(
   const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
   const MachineRegisterInfo &MRI = MF.getRegInfo();
   MachineInstr *MI = MRI.getUniqueVRegDef(VirtReg.reg());
-  if (MI && TII->isReMaterializable(*MI) && VirtReg.size() > HugeSizeForSplit)
+  if (MI && TII->isTriviallyReMaterializable(*MI) &&
+      VirtReg.size() > HugeSizeForSplit)
     return false;
   return true;
 }



More information about the llvm-commits mailing list