JIT: Fix register move ordering bug in genConsumeBlockOp for CpObjUnroll#126118
Closed
JIT: Fix register move ordering bug in genConsumeBlockOp for CpObjUnroll#126118
Conversation
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Under JitStressRegs, LSRA can legitimately assign the source address to
the register that is fixed for the destination (e.g. source → RDI, dest
→ RAX, with CpObjUnroll requiring dst=RDI, src=RSI on Linux x64 SysV).
The original code always moved the destination first:
mov rdi, rax ; dst → dstReg (CLOBBERS source already in rdi!)
mov rsi, rdi ; src → srcReg (now copies wrong value)
Fix: detect when the source's current register equals the required
destination register, and if so swap the move order (source first):
mov rsi, rdi ; src → srcReg first
mov rdi, rax ; dst → dstReg (safe: source already moved)
Also add an assert to catch the circular-dependency case (both operands
in each other's required register), which LSRA is not expected to produce.
Fixes: System.Diagnostics.Metrics.Tests.MetricsTests.PassingVariableTagsParametersTest
under JitStress=2 + JitStressRegs={2,0x80} on Linux x64.
Co-authored-by: mangod9 <61718172+mangod9@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5680c424-5cec-471e-b646-b2dada458fed
Copilot
AI
changed the title
[WIP] Fix test failure in MetricsTests.PassingVariableTagsParametersTest
JIT: Fix register move ordering bug in genConsumeBlockOp for CpObjUnroll
Mar 25, 2026
This was referenced Mar 26, 2026
Open
Member
|
Closing, not sure why copilot is creating multiple PRs |
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.
Under
JitStressRegs, LSRA can assign the source address of a block copy to the register that is the fixed requirement for the destination (e.g. source → RDI, dest → RAX, withCpObjUnrollneeding dst=RDI, src=RSI on Linux x64 SysV ABI). The original code always moved the destination first, clobbering the source:This manifested as
MetricsTests.PassingVariableTagsParametersTestcorrupting the firstKeyValuePairelement when passing 4+ tags viaparams ReadOnlySpan<KeyValuePair<string, object?>>(which triggers inline-array-at-call-site codegen, producing aCpObjUnrollwith GC-ref struct fields).Changes
src/coreclr/jit/codegenlinear.cpp—genConsumeBlockOpsrcCurReg == dstReg). In that case, emit the source move first, then the destination — avoiding the clobber.CopyBlkwith aGT_INDsource; local sources use aLEA(no conflict possible).assert(dstAddr->GetRegNum() != srcReg)to surface any circular-dependency (register-swap) case, which LSRA is not expected to produce.Security
No security impact. Pure codegen correctness fix affecting register-constrained struct copy sequences.
Original prompt
This section details on the original issue you should resolve
<issue_title>Test failure: System.Diagnostics.Metrics.Tests.MetricsTests.PassingVariableTagsParametersTest</issue_title>
<issue_description>Failed in: runtime-coreclr libraries-jitstress2-jitstressregs 20260307.1
Failed tests:
Error message:
Stack trace: