Skip to content

JIT: Disallow op2 for mulx to be in edx#125331

Merged
jakobbotsch merged 3 commits intodotnet:mainfrom
jakobbotsch:fix-125328
Mar 10, 2026
Merged

JIT: Disallow op2 for mulx to be in edx#125331
jakobbotsch merged 3 commits intodotnet:mainfrom
jakobbotsch:fix-125328

Conversation

@jakobbotsch
Copy link
Member

mulx has a fixed register requirement requiring op1 to be in edx. However, LSRA can still allow an op1 that is defined in another register than edx, even though op1 is constrained to edx. This gets resolved during codegen by first moving op1 to edx. However, that means we must also constraint op2 from not being in edx. LSRA believes the uses happen simultaneously, even when op1 was defined in a different register, but that's not faithful to what happens in codegen (which needs a separate mov instruction).

This adds similar logic as how shifts already handle similar constraints on the shift count having to be in ecx.

Fix #125328

I think there is a mismatch in LSRA's idealized location model compared to what has to happen in codegen. I am not sure it makes much sense to allow resolving def-use conflicts by changing registers on the uses. I will open a separate PR to experiment with removing these cases.

LSRA can still allow an op1 that is defined in another register than
edx, even though op1 is constrained to edx. This gets resolved during
codegen by first moving op1 to edx. However, that means we must also
constraint op2 from _not_ being in edx.

This adds similar logic as how shifts already handle similar constraints
on the shift count having to be in ecx.
Copilot AI review requested due to automatic review settings March 9, 2026 13:39
@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 Mar 9, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates xarch LSRA handling for mulx/MultiplyNoFlags to ensure the second operand is not allocated to EDX, aligning LSRA’s operand-location assumptions with codegen’s required move of op1 into EDX/RDX and preventing a codegen assert.

Changes:

  • In LSRA, exclude EDX from op2 register candidates for NI_AVX2(_X64)_MultiplyNoFlags.
  • Add a JIT regression test reproducing the original assertion failure and validating correct behavior.
  • Wire the new regression test into Regression_ro_2.csproj.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/jit/lsraxarch.cpp Tightens register candidate selection for MultiplyNoFlags so op2 cannot be allocated to EDX.
src/tests/JIT/Regression/Regression_ro_2.csproj Adds the new regression test source file to the merged regression project.
src/tests/JIT/Regression/JitBlue/Runtime_125328/Runtime_125328.cs New regression test covering the MultiplyNoFlags scenario that previously hit the codegen assertion.

@jakobbotsch
Copy link
Member Author

/azp run Fuzzlyn

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jakobbotsch jakobbotsch marked this pull request as ready for review March 9, 2026 23:55
@jakobbotsch jakobbotsch merged commit 68de53c into dotnet:main Mar 10, 2026
143 of 150 checks passed
@jakobbotsch jakobbotsch deleted the fix-125328 branch March 10, 2026 11:13
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: Assertion failed '(op2Reg != REG_EDX) || (op1Reg == REG_EDX)' during 'Generate code'

3 participants