Skip to content

JIT: Avoid resolving def-use conflicts by changing use registers#125333

Draft
jakobbotsch wants to merge 10 commits intodotnet:mainfrom
jakobbotsch:remove-use-reg-changes
Draft

JIT: Avoid resolving def-use conflicts by changing use registers#125333
jakobbotsch wants to merge 10 commits intodotnet:mainfrom
jakobbotsch:remove-use-reg-changes

Conversation

@jakobbotsch
Copy link
Copy Markdown
Member

@jakobbotsch jakobbotsch commented Mar 9, 2026

The only benefit is that it saves insertion of some explicit copies, but the trade off is an implicit contract between LSRA and codegen that is not very faithful. When LSRA defines in a different register than the constrained register, it believes that codegen can insert a copy and simultaneously use it from the new location, which is not true. This difference in the model has to be handled by inserting additional kill constraints during LSRA build, for example for shifts on xarch.

This PR additionally fixes a few issues uncovered while making this change:

  • GT_CATCH_ARG codegen was straight up wrong, not properly producing its register value
  • Multireg definitions cannot have their register assignment changed since that could override another defined register.

Fix #125432
Fix #125685

The only benefit is that it saves insertion of some explicit copies, but
the trade off is an implicit contract between LSRA and codegen that is
not very faithful. When LSRA defines in a different register than the
constrained register, it believes that codegen can insert a copy and
simultaneously use it from the new location, which is not true.
Copilot AI review requested due to automatic review settings March 9, 2026 14:02
@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
Copy Markdown
Contributor

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

Copy link
Copy Markdown
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

This PR refactors LinearScan::resolveConflictingDefAndUse in the JIT's register allocator (LSRA) to eliminate the practice of changing use-side register assignments when resolving def-use conflicts. The change ensures that only the definition RefPosition's register assignment is ever modified, while explicit copies are inserted for cases where the use constraint cannot be satisfied. This removes a fragile implicit contract between LSRA and codegen where LSRA would assign a def to a different register than constrained and expect codegen to simultaneously insert a copy and use from the new location.

Changes:

  • Simplifies resolveConflictingDefAndUse in lsrabuild.cpp by removing old Cases 1 and 4 (which changed the USE register assignment), consolidating the remaining cases into four cleaner ones that only modify the DEF's register assignment.
  • Updates the LsraDumpEvent enum in lsra.h to replace numbered case events (CASE1CASE6) with descriptive names.
  • Updates the debug dump handler in lsra.cpp to use the new event names and removes the now-dead LSRA_EVENT_DEFUSE_FIXED_DELAY_USE no-op case.

Reviewed changes

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

File Description
src/coreclr/jit/lsrabuild.cpp Core logic change: removes use-register-changing cases, simplifies conflict resolution to only modify def registers, updates comments
src/coreclr/jit/lsra.h Replaces numbered DEFUSE case enum values with descriptive names
src/coreclr/jit/lsra.cpp Updates debug dump switch/case to use new enum names, removes dead LSRA_EVENT_DEFUSE_FIXED_DELAY_USE case

Copilot AI review requested due to automatic review settings March 10, 2026 13:04
Copy link
Copy Markdown
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

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

@jakobbotsch
Copy link
Copy Markdown
Member Author

Another related issue here is #10196

Copilot AI review requested due to automatic review settings April 1, 2026 11:01
Copy link
Copy Markdown
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

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

@jakobbotsch
Copy link
Copy Markdown
Member Author

/azp run runtime-coreclr jitstressregs

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@jakobbotsch
Copy link
Copy Markdown
Member Author

/azp run runtime-coreclr jitstressregs

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copilot AI review requested due to automatic review settings April 9, 2026 14:16
Copy link
Copy Markdown
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

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

@jakobbotsch
Copy link
Copy Markdown
Member Author

/azp run runtime-coreclr jitstressregs

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@jakobbotsch
Copy link
Copy Markdown
Member Author

jitstressregs failures looks like the same that are present in main.

Rest looks like infra failures, will rerun CI.

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.

Test Failure: ComInterfaceGenerator.Unit.Tests and other tests JIT: Invalid codegen with byref return

2 participants