Skip to content

JIT x64: fix register allocation for Interlocked.Or/And with used result - #138275

Merged
EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:fix-138258
Nov 28, 2026
Merged

EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:fix-138258

Conversation

@EgorBo

@EgorBo EgorBo commented Nov 25, 2026

Copy link
Copy Markdown
Member

Fixes #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:

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.

When the result of Interlocked.Or/And is used, the cmpxchg loop needs an
internal register. Its use was built after the fixed-RAX def, so a def-use
conflict could evict the still-live internal register and reload it into
the address register.

Fixes dotnet#138258

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 00944461-fda2-4219-ac82-621f01c20bbe
@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 Nov 25, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 6 pipeline(s).
9 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.

@EgorBo

EgorBo commented Nov 28, 2026

Copy link
Copy Markdown
Member Author

/ba-g deadletter

@EgorBo
EgorBo enabled auto-merge (squash) November 28, 2026 00:20
@EgorBo
EgorBo merged commit 8895186 into dotnet:main Nov 28, 2026
133 of 135 checks passed
@EgorBo
EgorBo deleted the fix-138258 branch November 28, 2026 00:21
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 x64: Tier0 Interlocked.Or / Interlocked.And with a used result writes through current | value (address and new value share a register)

2 participants