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

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 25 12:50:01 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-regalloc

Author: Philip Reames (preames)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/160765.diff


1 Files Affected:

- (modified) llvm/lib/CodeGen/LiveRangeEdit.cpp (+3-3) 


``````````diff
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);
   }

``````````

</details>


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


More information about the llvm-commits mailing list