[llvm] [RegAlloc] Strengthen asserts in LiveRangeEdit::scanRemattable [nfc] (PR #160765)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 25 12:49:23 PDT 2025


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

We should always be able to find the VNInfo in the original live interval which corresponds to the subset we're trying to spill, and the only cases where we have a VNInfo without a definition instruction are if the vni is unused, or corresponds to a phi. Adjust the code structure to explicitly check for PHIDef, and assert the stronger conditions.

>From 91a554f178c2032e14882c6f28a0778f49147248 Mon Sep 17 00:00:00 2001
From: Philip Reames <preames at rivosinc.com>
Date: Thu, 25 Sep 2025 12:34:23 -0700
Subject: [PATCH] [RegAlloc] Strengthen asserts in
 LiveRangeEdit::scanRemattable [nfc]

We should always be able to find the VNInfo in the original live
interval which corresponds to the subset we're trying to spill,
and the only cases where we have a VNInfo without a definition
instruction are if the vni is unused, or corresponds to a phi.
Adjust the code structure to explicitly check for PHIDef, and
assert the stronger conditions.
---
 llvm/lib/CodeGen/LiveRangeEdit.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/CodeGen/LiveRangeEdit.cpp b/llvm/lib/CodeGen/LiveRangeEdit.cpp
index 2f65be51bb726..dc1121d7d9e28 100644
--- a/llvm/lib/CodeGen/LiveRangeEdit.cpp
+++ b/llvm/lib/CodeGen/LiveRangeEdit.cpp
@@ -75,11 +75,11 @@ void LiveRangeEdit::scanRemattable() {
     Register Original = VRM->getOriginal(getReg());
     LiveInterval &OrigLI = LIS.getInterval(Original);
     VNInfo *OrigVNI = OrigLI.getVNInfoAt(VNI->def);
-    if (!OrigVNI)
+    assert(OrigVNI && "Corrupt interval mapping?");
+    if (OrigVNI->isPHIDef())
       continue;
     MachineInstr *DefMI = LIS.getInstructionFromIndex(OrigVNI->def);
-    if (!DefMI)
-      continue;
+    assert(DefMI && "Missing instruction for def slot");
     if (TII.isReMaterializable(*DefMI))
       Remattable.insert(OrigVNI);
   }



More information about the llvm-commits mailing list