Commit 3d9b089
[release/8.0-staging] Fix loop hoist memory-dependence tracking (#122057)
Port the .NET 9 fix in `optRecordLoopMemoryDependence` so that memory
dependencies coming from nested loops are recorded against the closest
ancestor loop that contains the consuming tree, rather than being
silently discarded.
Without this fix, when the loop hoister considers an IND whose value VN
has been folded to a constant via VN's MapStore/MapSelect machinery, the
`IsTreeLoopMemoryInvariant` check finds no entry in
`NodeToLoopMemoryBlockMap` and returns `true` vacuously. The IND is
then relocated to the loop preheader where it loads a stale value
instead of the post-store value the VN-folded constant represents.
Example pattern from the linked issue:
```csharp
for (sbyte i = -126; i > -128; i--)
{
for (byte j = 2; j > 0; j--)
{
s_rt.Checksum(""c_0"", var4); // virtual call inside inner loop
}
s_2 = 1;
s_2 = s_2--; // hoisted IND reads stale s_2
}
```
Fix: walk up the parent chain of the update loop until one is found
that contains the tree's block (the .NET 9 `FlowGraphNaturalLoops`
version generalizes this; the 8.0 port uses `optLoopTable[..].lpParent`).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 29db7c7 commit 3d9b089
3 files changed
Lines changed: 879 additions & 6 deletions
File tree
- src
- coreclr/jit
- tests/JIT/Regression/JitBlue/Runtime_122057
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7150 | 7150 | | |
7151 | 7151 | | |
7152 | 7152 | | |
7153 | | - | |
7154 | | - | |
| 7153 | + | |
| 7154 | + | |
| 7155 | + | |
| 7156 | + | |
7155 | 7157 | | |
7156 | | - | |
| 7158 | + | |
7157 | 7159 | | |
7158 | | - | |
7159 | | - | |
7160 | | - | |
| 7160 | + | |
| 7161 | + | |
| 7162 | + | |
| 7163 | + | |
| 7164 | + | |
| 7165 | + | |
| 7166 | + | |
| 7167 | + | |
7161 | 7168 | | |
7162 | 7169 | | |
7163 | 7170 | | |
| |||
0 commit comments