[llvm] [SelectionDAG] Don't unfold a load in the pre-RA schedulers if the unfolded load already exists (PR #226652)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 26 01:18:39 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-x86
Author: Akash Manna (akash-manna-sky)
<details>
<summary>Changes</summary>
Fixes #<!-- -->204079
When the pre-RA scheduler has to duplicate a flags-producing instruction with a folded load (a `CMP32mi` here) to break an EFLAGS interference, it first tries to unfold it into a plain load and a register operation. `X86InstrInfo::unfoldMemoryOperand` builds that load with `getMachineNode`, which CSEs it with a load of the same address that is already in the DAG, and `TryUnfoldSU` then redirects the chain uses of the folded node to that existing load. Its chain result already had users, so one of the redirected `TokenFactor`s became a duplicate of another one and `ReplaceAllUsesOfValueWith` deleted it, while the scheduler still had an SUnit pointing at it. The emitter later ran into the freed node, hence the `<<Deleted Node!>>` in the report. `ScheduleDAGFast` carries the same code and crashes the same way with `-pre-RA-sched=fast`.
Both schedulers now give up on unfolding when the unfolded load already has an SUnit, and the caller falls back to copying EFLAGS the usual way. Returning the original node so that it gets cloned instead would not be safe either: the clone doesn't inherit the chain successors, so a store to the loaded address could end up between the original and the clone. The old path also never re-attached the chain successor edges to the existing load, so that goes away with it. The fallback is a couple of instructions longer, but it only kicks in when the same load is already in the DAG.
---
Full diff: https://github.com/llvm/llvm-project/pull/226652.diff
6 Files Affected:
- (modified) llvm/docs/ReleaseNotes.md (+5)
- (modified) llvm/lib/CodeGen/SelectionDAG/ScheduleDAGFast.cpp (+18-29)
- (modified) llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp (+31-55)
- (added) llvm/test/CodeGen/X86/pr204079.ll (+119)
- (modified) llvm/test/CodeGen/X86/pr37916.ll (+5-2)
- (added) llvm/test/CodeGen/X86/sched-unfold-existing-load.ll (+55)
``````````diff
The server is unavailable at this time. Please wait a few minutes before you try again.
``````````
</details>
https://github.com/llvm/llvm-project/pull/226652
More information about the llvm-commits
mailing list