[llvm] [regalloc][LiveRegMatrix][AMDGPU] Fix LiveInterval dangling pointers in LiveRegMatrix. (PR #168556)

Valery Pykhtin via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 21 10:52:52 PST 2026


================
@@ -142,6 +144,20 @@ void LiveRegMatrix::unassign(const LiveInterval &VirtReg) {
   LLVM_DEBUG(dbgs() << '\n');
 }
 
+void LiveRegMatrix::unassign(Register VirtReg) {
+  Register PhysReg = VRM->getPhys(VirtReg);
+  LLVM_DEBUG(dbgs() << "unassigning " << printReg(VirtReg, TRI) << " from "
+                    << printReg(PhysReg, TRI) << '\n');
+  VRM->clearVirt(VirtReg);
+
+  assert(LIS->hasInterval(VirtReg));
+  const LiveInterval &LI = LIS->getInterval(VirtReg);
+  for (MCRegUnit Unit : TRI->regunits(PhysReg)) {
+    Matrix[Unit].clearAllSegmentsReferencing(LI);
+  }
----------------
vpykhtin wrote:

I've changed the signature of this unassign to:

`void unassign(Register VirtReg, const LiveInterval *VirtRegLI);`

to emphasize that VirtRegLI can be a pointer to invalid object. The pointer is never accessed and only used to delete segments pointing to the same address. The original function accesses the LiveInterval object.

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


More information about the llvm-commits mailing list