[release/11.0] JIT: Prevent loop hoisting across volatile reads - #134351
Merged
Merged
Conversation
Volatile reads have acquire semantics, but loop optimization could hoist an ordinary load across a prior iteration's acquire. Treat volatile indirections as loop memory havoc and add a regression test for the cross-iteration ordering. Fixes #133579 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Name the test after issue 133579 and mark it as an outer-loop test so it runs at priority 1 without changing the priority of the merged regression assembly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 51ab0cbf-6d32-4701-8e9d-fa19e4d01f6f
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Member
|
@EgorBo ptal |
JulieLeeMSFT
approved these changes
Sep 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #133825 to release/11.0
/cc @AndyAyersMS
Customer Impact
Loop optimization can hoist an ordinary field load across a
Volatile.Readacquire from a prior loop iteration, violating the managed memory model and allowing stale data to be observed. The reported repro returns0after another thread publishes42. This affects .NET 8, 9, 10, and 11. A community contributor noted that application code may encounter this silently and that the cause would be difficult to diagnose. See #133579.Regression
No recent introducing change has been identified. The issue reproduces across all currently supported runtime versions, including .NET 8 through .NET 11.
Testing
Added a focused cross-iteration ordering regression test that fails without the fix and passes with it. The existing Runtime_40444 volatile-ordering regression also passes. Validation included Checked and Release CoreCLR builds, JIT formatting, and Windows x64 Checked SuperPMI across nine collections. Only 2 of 987,559 successful compilations changed, totaling +4 bytes with effectively zero aggregate PerfScore impact.
Risk
Low. The change treats volatile indirections as loop memory havoc, conservatively preventing unsafe load hoisting across acquire operations. It may inhibit optimization in the affected shape, but SuperPMI measured only two tiny code-generation changes and no meaningful performance impact.