[llvm] [CodeGen] Remove unsatisfiable hints in RegAllocGreedy. (PR #190983)

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 14 21:19:39 PDT 2026


================
@@ -2454,6 +2456,30 @@ void RAGreedy::initializeCSRCost() {
   }
 }
 
+/// For each virtual register whose simple hint is a physical register,
+/// check whether that physreg's live range overlaps the vreg's live range.
+/// If it does the hint can never be satisfied; clear it so the vreg does not
+/// receive a spurious priority boost and does not trigger futile evictions.
+void RAGreedy::removeUnsatisfiableHints() {
+  for (unsigned Idx = 0, End = MRI->getNumVirtRegs(); Idx < End; ++Idx) {
+    Register VReg = Register::index2VirtReg(Idx);
+    if (MRI->reg_nodbg_empty(VReg))
+      continue;
+    Register HintReg = MRI->getSimpleHint(VReg);
+    if (!HintReg.isPhysical())
+      continue;
+    const LiveInterval &LI = LIS->getInterval(VReg);
+    for (MCRegUnit Unit : TRI->regunits(HintReg.asMCReg())) {
+      const LiveRange &PhysLR = LIS->getRegUnit(Unit);
+      if (!PhysLR.empty() && PhysLR.overlaps(LI)) {
+        MRI->clearSimpleHint(VReg);
----------------
qcolombet wrote:

We'll need to introduce a new method to clear the simple hint, because that nukes the full hints, not just the simple one :).

https://github.com/llvm/llvm-project/pull/190983


More information about the llvm-commits mailing list