Skip to content

JIT: Do not contain local addresses of volatile indirections on xarch - #135720

Merged
EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:fix-jit-135386
Oct 14, 2026
Merged

EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:fix-jit-135386

Conversation

@EgorBo

@EgorBo EgorBo commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

A volatile access to an address-exposed local was emitted through the emitter stack move path, where IsRedundantStackMov has no notion of volatility and dropped an identical consecutive store (or a load right after a store). Keep the local address in a register for volatile indirections so these accesses are never elided. Rare in practice: +21 bytes over 4 methods in libraries.pmi.

Fixes #135386

A few regressions (required for correctness).

A volatile access to an address-exposed local was emitted through the emitter stack move path, where IsRedundantStackMov has no notion of volatility and dropped an identical consecutive store (or a load right after a store). Keep the local address in a register for volatile indirections so these accesses are never elided. Rare in practice: +21 bytes over 4 methods in libraries.pmi.

Fixes dotnet#135386

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 88502efb-96e2-4483-b698-59f5003a2e2c
@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 Oct 13, 2026
@azure-pipelines

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

@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.

🟡 Changes recommended

The regression test passes with the faulty code and must verify the emitted volatile accesses.

1 open finding
What changed in this PR

Prevents xarch JIT peephole optimization from eliding volatile accesses to address-exposed locals.

Changes:

  • Keeps volatile local addresses in registers.
  • Adds a regression test, though it cannot currently detect the bug.
File Description
src/​coreclr/​jit/​lowerxarch.cpp Disables local-address containment for volatile indirections.
src/​tests/​JIT/​Regression_ro_2/​Runtime_135386.cs Adds coverage for consecutive volatile stores.

🧠 Review effort: Balanced

Comment thread src/tests/JIT/Regression_ro_2/Runtime_135386.cs
@EgorBo

EgorBo commented Oct 14, 2026

Copy link
Copy Markdown
Member Author

PTAL @dotnet/jit-contrib, trivial bug-fix

@EgorBo
EgorBo requested a review from a team October 14, 2026 02:04

@JulieLeeMSFT JulieLeeMSFT left a comment

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.

LGTM. It prevents the JIT from incorrectly eliminating consecutive identical volatile accesses to address-exposed locals, preserving required memory ordering and visibility.

@tannergooding tannergooding left a comment

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.

LGTM. It might be good if we had a way to rationalize such loads/stores to emit so we didn't have to pessimize codegen. This feels like something we could handle via the additional flags we support passing down to emi.

@EgorBo
EgorBo merged commit d46dd2e into dotnet:main Oct 14, 2026
136 of 138 checks passed
@EgorBo
EgorBo deleted the fix-jit-135386 branch October 14, 2026 21:45
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 19, 2026
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) stack-move peephole coalesces two Volatile.Writes to an address-exposed local

5 participants