Skip to content

JIT: Model xadd as writing its register operand - #135721

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

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

Conversation

@EgorBo

@EgorBo EgorBo commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

xadd [mem], reg stores the old memory value in reg, but the emitter only gave xchg a read-write register format and xadd got a read-only one. The peephole for redundant movs therefore looked past a lock xadd and dropped the "mov eax, eax" zero-extension of its result. Use the RW register format for xadd as for xchg.

Fixes #135385

No diffs.

xadd [mem], reg stores the old memory value in reg, but the emitter only gave xchg a read-write register format and xadd got a read-only one. The peephole for redundant movs therefore looked past a lock xadd and dropped the "mov eax, eax" zero-extension of its result. Use the RW register format for xadd as for xchg.

Fixes dotnet#135385

Co-authored-by: Copilot <[email protected]>
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 register-register xadd form remains incorrectly modeled with its second register as read-only.

1 open finding
What changed in this PR

Corrects JIT emitter metadata so memory-form xadd operations record their register operand as read-write, preserving required zero-extension moves.

Changes:

  • Updates static, address, and stack xadd formats.
  • Adds a regression test for the incorrect upper-bit retention.
File Description
src/​coreclr/​jit/​emitxarch.cpp Models memory-form xadd register operands as read-write.
src/​tests/​JIT/​Regression_ro_2/​Runtime_135385.cs Verifies correct zero-extension of an Interlocked.Add result.

🧠 Review effort: Balanced

Comment thread src/coreclr/jit/emitxarch.cpp Resolved
@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 models xadd as read-write for its register operand.

@EgorBo
EgorBo merged commit d24a264 into dotnet:main Oct 14, 2026
136 of 138 checks passed
@EgorBo
EgorBo deleted the fix-jit-135385 branch October 14, 2026 21:45
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 19, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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) zero-extension of a lock xadd result is wrongly elided, so (uint)Interlocked.Add(ref long, ...) keeps the upper 32 bits

4 participants