Skip to content

JIT: Handle some def/use conflicts less conservatively in LSRA#125214

Merged
jakobbotsch merged 7 commits intodotnet:mainfrom
jakobbotsch:less-conservative-du-conflicts
Mar 6, 2026
Merged

JIT: Handle some def/use conflicts less conservatively in LSRA#125214
jakobbotsch merged 7 commits intodotnet:mainfrom
jakobbotsch:less-conservative-du-conflicts

Conversation

@jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Mar 5, 2026

A def-use conflict happens for SDSU intervals when the def and use share no common candidate register. For these cases we run through a set of potential ways to resolve the conflict that make use of the contract between LSRA and codegen. For example, when the definition requires a single fixed register, it is still valid for LSRA to assign a different register. This means that codegen can use the original fixed register, but that it must insert a copy into the register assigned by LSRA.

In the worst case we cannot use any of the approaches to solve the conflict and then we will fall back to spilling/copying as necessary.

It appears that several of the cases were overly conservative. Particularly case 1 and 2, as described by the function header, were never reachable; we assign defRegConflict and useRegConflict based on whether there is a conflict in register constraints, but that is always true when we get into this function. It appears the original intention of these variables were whether there is a conflict with a different use of the registers we could otherwise have resolved the original conflict with. This PR restores the meaning to that.

A def-use conflict happens for SDSU intervals when the def and use share
no common register. For these cases we run through a set of potential
ways to resolve the conflict that make use of the contract between LSRA
and codegen. For example, when the definition requires a single fixed
register, it is still valid for LSRA to assign a different register.
This means that codegen can use the original fixed register, but that it
must insert a copy into the register assigned by LSRA.

In the worst case we cannot use any of the approaches to solve the
conflict and then we will fall back to spilling/copying as necessary.

It appears that several of the cases were overly conservative.
Particularly case 1 and 2, as described by the function header, were
never reachable; we assign `defRegConflict` and `useRegConflict` based
on whether there is a conflict in register constraints, but that is
always true when we get into this function. It appears the original
intention of these variables were whether there is a conflict with a
_different_ use of the registers we could otherwise have resolved the
original conflict with. This PR restores the meaning to that.
Copilot AI review requested due to automatic review settings March 5, 2026 11:24
@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 5, 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

This PR fixes an over-conservative bug in LinearScan::resolveConflictingDefAndUse in the JIT's LSRA (Linear Scan Register Allocator). When a single-def, single-use interval has conflicting register requirements between its definition and use, LSRA tries several resolution strategies (Cases 1–6) before falling back to spilling/copying. The two guard variables defRegConflict and useRegConflict were incorrectly initialized to true (based on the def/use set disjointness — which is always true at the call site), making Cases 1 and 2 entirely unreachable dead code. The PR restores their intended semantics by initializing them to false, so they instead track whether a specific candidate register has an intervening conflict elsewhere — only being set to true inside the blocks when such a conflict is actually detected.

Changes:

  • Initialize defRegConflict and useRegConflict to false instead of deriving them from the always-true def/use register set disjointness.
  • Remove the redundant && !defRegConflict / && !useRegConflict guards from the isFixedRegRef checks (now replaced by the corrected initialization).

Copilot AI review requested due to automatic review settings March 5, 2026 12:44
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

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

Copilot AI review requested due to automatic review settings March 5, 2026 14:36
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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@jakobbotsch
Copy link
Member Author

/azp run runtime-coreclr jitstress, runtime-coreclr libraries-jitstress, runtime-coreclr jitstressregs

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jakobbotsch jakobbotsch marked this pull request as ready for review March 5, 2026 22:19
Copilot AI review requested due to automatic review settings March 5, 2026 22:19
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib. @AndyAyersMS can you take a look?

Diffs. Regressions will mostly be addressed by #125219. Large improvements for arm32 and this PR should supersede #125178.

@jakobbotsch jakobbotsch requested a review from AndyAyersMS March 5, 2026 22:21
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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

Not very familiar with this code, but this looks reasonable.

@jakobbotsch jakobbotsch merged commit 703be08 into dotnet:main Mar 6, 2026
173 of 183 checks passed
@jakobbotsch jakobbotsch deleted the less-conservative-du-conflicts branch March 6, 2026 20:19
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.

3 participants