[llvm] [RegAlloc] Consider rematerialization over CSR use (PR #206756)
Lukas Sommer via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 21 03:02:15 PDT 2026
================
@@ -2372,6 +2372,87 @@ BlockFrequency RAGreedy::calcSpillCost(const LiveInterval &LI) {
return BlockFrequency(SpillCost);
}
+bool RAGreedy::shouldAvoidCSRForRemat(const LiveInterval &VirtReg,
+ AllocationOrder &Order) const {
+ if (!VirtReg.isSpillable())
+ return false;
+
+ // This logic is intentionally narrow: handle a single concrete value
+ // whose def can be cheaply rematerialized at every use.
+ const VNInfo *OnlyVNI = nullptr;
+ for (const VNInfo *VNI : VirtReg.vnis()) {
+ if (!VNI || VNI->isUnused())
+ continue;
+ if (VNI->isPHIDef())
+ return false;
+ if (OnlyVNI)
+ return false;
+ OnlyVNI = VNI;
+ }
+ if (!OnlyVNI)
+ return false;
+
+ MachineInstr *DefMI = LIS->getInstructionFromIndex(OnlyVNI->def);
+ if (!DefMI || DefMI->isImplicitDef() || !TII->isReMaterializable(*DefMI) ||
+ !TII->isAsCheapAsAMove(*DefMI))
+ return false;
+
+ // This logic aims to address a specific problem: The first use of CSR for
+ // cheap-to-rematerialize live ranges because they cross calls, not because
----------------
sommerlukas wrote:
Done in the latest commit.
https://github.com/llvm/llvm-project/pull/206756
More information about the llvm-commits
mailing list