Skip to content

[release/11.0] JIT: Prevent loop hoisting across volatile reads - #134351

Merged
JulieLeeMSFT merged 2 commits into
release/11.0from
backport/pr-133825-to-release/11.0
Sep 21, 2026
Merged

JulieLeeMSFT merged 2 commits into
release/11.0from
backport/pr-133825-to-release/11.0

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #133825 to release/11.0

/cc @AndyAyersMS

Customer Impact

  • Customer reported
  • Found internally

Loop optimization can hoist an ordinary field load across a Volatile.Read acquire from a prior loop iteration, violating the managed memory model and allowing stale data to be observed. The reported repro returns 0 after another thread publishes 42. 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

  • Yes
  • No

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.

AndyAyersMS and others added 2 commits September 21, 2026 15:57
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

Copy link
Copy Markdown
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.

@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 Sep 21, 2026
@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.

@AndyAyersMS
AndyAyersMS requested a review from EgorBo September 21, 2026 18:54
@AndyAyersMS

Copy link
Copy Markdown
Member

@EgorBo ptal

@AndyAyersMS AndyAyersMS added the Servicing-consider Issue for next servicing release review label Sep 21, 2026
@JulieLeeMSFT JulieLeeMSFT added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Sep 21, 2026
@JulieLeeMSFT JulieLeeMSFT added this to the 11.0.0 milestone Sep 21, 2026
@JulieLeeMSFT
JulieLeeMSFT merged commit 8b1a4a1 into release/11.0 Sep 21, 2026
127 of 129 checks passed
@JulieLeeMSFT
JulieLeeMSFT deleted the backport/pr-133825-to-release/11.0 branch September 21, 2026 21:49
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 Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants