Repository navigation
JIT: Model xadd as writing its register operand - #135721
Merged
Merged
Conversation
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
|
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. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
🟡 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
xaddformats. - 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
This was referenced Oct 13, 2026
Closed
Member
Author
|
PTAL @dotnet/jit-contrib, trivial bug-fix |
JulieLeeMSFT
approved these changes
Oct 14, 2026
JulieLeeMSFT
left a comment
Member
There was a problem hiding this comment.
LGTM. It models xadd as read-write for its register operand.
tannergooding
approved these changes
Oct 14, 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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.

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.