Skip to content

JIT: Compute async liveness for address exposed locals#124001

Merged
jakobbotsch merged 21 commits intodotnet:mainfrom
jakobbotsch:async-address-exposed-liveness
Feb 9, 2026
Merged

JIT: Compute async liveness for address exposed locals#124001
jakobbotsch merged 21 commits intodotnet:mainfrom
jakobbotsch:async-address-exposed-liveness

Conversation

@jakobbotsch
Copy link
Member

This should still give correct liveness at async suspension points given that local addresses cannot be taken across those.

Based on #123500

Copilot AI review requested due to automatic review settings February 4, 2026 12: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 Feb 4, 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 enables precise liveness computation for address-exposed locals during async transformations. Building on #123500 (which introduced full liveness computation for MinOpts with async), this change recognizes that local addresses cannot be taken across async suspension points, allowing the JIT to track address-exposed locals directly instead of conservatively treating them as always live.

Changes:

  • Refactored the Liveness class template to support multiple liveness computation modes via compile-time template parameters (TrackAddressExposedLocals, IsEarly, EliminateDeadCode)
  • Replaced fgLocalVarLiveness() with specialized functions: fgSsaLiveness(), fgAsyncLiveness(), and fgPostLowerLiveness()
  • Extracted lvaComputePreciseRefCounts() from lvaComputeRefCounts() to allow reuse in async transformations

Reviewed changes

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

Show a summary per file
File Description
src/coreclr/jit/liveness.cpp Major refactoring of liveness computation to use template-based specialization; added fgSsaLiveness(), fgAsyncLiveness(), fgPostLowerLiveness(); renamed member variables for clarity; inlined LiveVarAnalysis into DoLiveVarAnalysis()
src/coreclr/jit/async.cpp Updated to use fgAsyncLiveness() and lvaComputePreciseRefCounts(); simplified AsyncLiveness class by removing m_hasLiveness field; added cleanup logic for unoptimized codegen
src/coreclr/jit/compiler.h Added declarations for new liveness functions and lvaComputePreciseRefCounts(); removed obsolete fgLocalVarLivenessChanged and fgIsDoingEarlyLiveness fields
src/coreclr/jit/lclvars.cpp Extracted lvaComputePreciseRefCounts() as a separate function for reuse
src/coreclr/jit/ssabuilder.cpp Updated call from fgLocalVarLiveness() to fgSsaLiveness()
src/coreclr/jit/lower.cpp Updated calls from fgLocalVarLiveness() to fgPostLowerLiveness()
src/coreclr/jit/compiler.cpp Updated call from fgLocalVarLiveness() to fgSsaLiveness()

@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 February 6, 2026 18:00
Copilot AI review requested due to automatic review settings February 6, 2026 18:00
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 2 comments.

@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS

This starts tracking address exposed locals for the liveness we do in the runtime async pass. It is based on a few observations:

  1. The async transformation does not need liveness to be correct except at async suspension points. Concretely, with this PR the liveness can be wrong for address exposed locals between suspension points. In other words, we may consider locals to be dead that are actually live. It would be wrong to use any of this liveness for anything (like DCE), but we do not do that after recent PRs.
  2. At async suspension points we know that the address of each local is not taken anymore. At those points the local is hence only live if we can see a "proper" use before a def after the call.
  3. A "proper" use is either a normal LCL_VAR/LCL_FLD, but it can also be a LCL_ADDR now (retaking the address of a local after a suspension point). No change is needed for this as the LIR liveness already processes LCL_ADDRs and generally considers these to be uses.

Diffs.

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