[llvm] [CodeGen] Notify LRE delegate before foldAsLoad erases UseMI (PR #226250)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 24 10:56:00 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-regalloc
Author: Sam Valladares (samvallad33)
<details>
<summary>Changes</summary>
## Summary
Fixes #<!-- -->222905
`foldAsLoad` erases `UseMI` without calling `LRE_WillEraseInstruction`. `eliminateDeadDef` already does that notify before erase. This path just missed it, so the register coalescer keeps a stale `UseMI*` and crashes later looking like heap corruption.
## Change
In `LiveRangeEdit::foldAsLoad`, call `TheDelegate->LRE_WillEraseInstruction(UseMI)` before `UseMI->eraseFromParent()`, matching the sibling path.
## Testing
No MIR test added. The change mirrors the existing `eliminateDeadDef` notify-before-erase pattern. A full ASan repro needs a backend where `foldMemoryOperandImpl` succeeds for the load being folded while the erased `UseMI` remains on the coalescer worklist; there is not yet a reliably upstream-triggerable MIR case for that.
Assisted-by: Cursor
---
Full diff: https://github.com/llvm/llvm-project/pull/226250.diff
1 Files Affected:
- (modified) llvm/lib/CodeGen/LiveRangeEdit.cpp (+2)
``````````diff
diff --git a/llvm/lib/CodeGen/LiveRangeEdit.cpp b/llvm/lib/CodeGen/LiveRangeEdit.cpp
index 1d6b835f16468..3d25e204743e8 100644
--- a/llvm/lib/CodeGen/LiveRangeEdit.cpp
+++ b/llvm/lib/CodeGen/LiveRangeEdit.cpp
@@ -161,6 +161,8 @@ bool LiveRangeEdit::foldAsLoad(LiveInterval *LI,
// Update the call info.
if (UseMI->shouldUpdateAdditionalCallInfo())
UseMI->getMF()->moveAdditionalCallInfo(UseMI, FoldMI);
+ if (TheDelegate)
+ TheDelegate->LRE_WillEraseInstruction(UseMI);
UseMI->eraseFromParent();
DefMI->addRegisterDead(LI->reg(), nullptr);
Dead.push_back(DefMI);
``````````
</details>
https://github.com/llvm/llvm-project/pull/226250
More information about the llvm-commits
mailing list