Repository navigation
Conversation
…ult (dotnet#138275) Fixes dotnet#138258 When the result of `Interlocked.Or`/`Interlocked.And` is used, xarch emits a `cmpxchg` loop that needs an internal register. LSRA built the internal register use *after* the fixed-RAX def of the node. When that def has a def-use conflict (e.g. consumed by `PUTARG_REG` in `rdi` on SysV), LSRA defines it in the use's fixed register, evicting the still-live internal register, which then got "reloaded" into the address register: ```asm mov rcx, rax or rcx, rdx lock cmpxchg qword ptr [rcx], rcx ; rcx is both the address and the new value ``` Checked builds assert `genExactlyOneBit(availableSet)` instead. The fix builds internal uses before the def, as other nodes do. Arm64 already uses that order; other targets don't use internal registers here. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 00944461-fda2-4219-ac82-621f01c20bbe (cherry picked from commit 8895186)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8c6b9802-8643-479e-bbb4-f4e04e60fc0a
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
jakobbotsch
approved these changes
Dec 1, 2026
This branch has not been deployed
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.
Fixes Issue #138258
main PR #138275
Description
Backport of #138275 to release/11.0. When the result of
Interlocked.Or/Interlocked.Andis used, LSRA could give thecmpxchgloop the same register for the address and the new value. LSRA now builds the internal register uses before the def, like other nodes do.Customer Impact
Tier0 code that uses the result of
Interlocked.Or/And(e.g. passes it to a call) writes throughcurrent | valueas if it were the address. This causes NullReferenceException, fatal AVs, or silent memory corruption. Every method with this pattern starts in Tier0, so default configurations hit it.Regression
Works on .NET 10, broken in 11.0.0.
Testing
Test is backported.
Risk
Low. A one-line change in the LSRA build order for these nodes, matching what arm64 already does.
Note
PR description generated with GitHub Copilot.