Skip to content

JIT: Separate map select caches by VN kind - #137855

Merged
AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:fix/134489-vn-cache-kind
Nov 20, 2026
Merged

AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:fix/134489-vn-cache-kind

Conversation

@AndyAyersMS

@AndyAyersMS AndyAyersMS commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Map-select results were cached without including the value-number kind. A liberal result could be reused during conservative phi evaluation, causing the JIT to treat separate field reads as equal and remove a necessary array bounds check. This change keeps separate caches for each kind and adds a regression test.

Validation

  • src\tests\build.cmd -Test JIT\Regression_ro_2\Regression_ro_2.csproj x64 checked -Priority 1 - passed.
  • .\build.cmd clr.jit -c Checked - passed.
  • src\tests\build.cmd -GenerateLayoutOnly x64 checked - passed.
  • Ran Runtime_134489.TestEntryPoint with the checked Core_Root: failed with an access violation before the fix; passed after it (exit code 100).

Resolves #134489

Note

This PR description was generated with GitHub Copilot.

Map select cache keys omit VN kind, so a liberal result can be reused
during conservative phi evaluation. This can make the JIT treat separate
field reads as equal and remove a necessary array bounds check. Keep
separate caches for each VN kind. Fixes dotnet#134489.

Co-authored-by: Copilot <[email protected]>
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 18, 2026
@AndyAyersMS
AndyAyersMS requested review from jakobbotsch and a balanced review from Copilot November 18, 2026 18:00
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@AndyAyersMS

Copy link
Copy Markdown
Member Author

@jakobbotsch ptal
fyi @dotnet/jit-contrib

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the JIT value-numbering cache fix.

No open issues 🎉

What changed in this PR

This PR fixes JIT value numbering so liberal map-select results cannot be reused during conservative evaluation, preventing incorrect bounds-check removal described in #134489.

Changes:

  • Separates map-select work caches by value-number kind.
  • Updates cache lookups and writes to use the requested kind.
  • Adds a regression test that exercises bounds checks while another thread changes the source field.
File Description
src/​tests/​JIT/​Regression_ro_2/​Runtime_134489.cs Adds the concurrent field-read regression test.
src/​coreclr/​jit/​valuenum.h Defines separate liberal and conservative caches and a kind-aware accessor.
src/​coreclr/​jit/​valuenum.cpp Passes the value-number kind to every map-select work-cache access.

Review effort: Balanced

@jakobbotsch

Copy link
Copy Markdown
Member

/azp run runtime-coreclr superpmi-diffs

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@AndyAyersMS

Copy link
Copy Markdown
Member Author

/ba-g infrastructure issue, agent did not connect within 45 minutes

@AndyAyersMS
AndyAyersMS merged commit 6c4e159 into dotnet:main Nov 20, 2026
129 of 131 checks passed
Comment on lines +17 to +28
Thread writer = new Thread(() =>
{
while (Volatile.Read(ref stop) == 0)
{
Volatile.Write(ref holder.F.A, 0);
Volatile.Write(ref holder.F.A, 100_000_000);
}
})
{
IsBackground = true
};
writer.Start();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is failing on wasm it looks like ("Operation not supported")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We apparently don't run this under Wasm in CI. I'll add an exclusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: (bug) bounds check wrongly removed under a data race (liberal VN reused as conservative VN for LCL_FLD of struct phi)

3 participants