Skip to content

JIT: Defer physical promotion readbacks across basic blocks - #134048

Draft
jakobbotsch wants to merge 9 commits into
dotnet:mainfrom
jakobbotsch:lazy-physical-promotion-readbacks
Draft

jakobbotsch wants to merge 9 commits into
dotnet:mainfrom
jakobbotsch:lazy-physical-promotion-readbacks

Conversation

@jakobbotsch

@jakobbotsch jakobbotsch commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Defer physical-promotion readbacks across basic blocks instead of eagerly initializing parameter replacements and materializing pending fields at every block boundary.

Visit blocks in reverse postorder, carrying pending readbacks when all predecessors agree. At mixed joins, materialize on pending predecessors; retain conservative loop/EH boundaries and preserve whether the struct home is current to avoid redundant writebacks.

Before replacement, use the existing field-liveness use/def sets to estimate readback and reconciliation sites. Plan a shared readback in their common dominator when block weights predict fewer executions. Replacement materializes it only if still pending, preserving its exact handling of uses, writes, and exceptional control flow.

jakobbotsch and others added 2 commits September 11, 2026 14:22
Generalize the existing FindInducedParameterRegisterLocals transformation
from entry-block-only rewriting in lowering to all-block rewriting during
rationalization. Record parameter field reads, stores, and address uses in
the existing execution-order visitor rather than adding a separate IR walk.

After rationalization, propagate parameter kills through normal and EH
successors, including loop backedges. Rewrite field reads only when every
reaching path still observes the incoming parameter value, respecting
read-before-kill ordering within each block. Reuse the existing extraction
logic and parameter-register target mappings.

Remove the entry-block discovery and unused reuse helper from lowering,
while retaining mappings for independently promoted parameters. Account
for the earlier parameter-register targets in async default-value analysis
and invalidate recorded uses when rationalization discards their nodes.

Physical promotion's eager readbacks remain unchanged; profitability of
keeping packed values live across calls is follow-up work.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4c28b3c3-cf6c-4149-8eb1-964831492011
Visit blocks in reverse postorder and track pending field readbacks at
block exits instead of eagerly initializing parameter replacements or
materializing every pending readback at each block boundary.

Keep replacement locals current by default. Carry the special pending
state into a successor only when all reachable predecessors agree. At
mixed joins, materialize readbacks on the pending predecessors rather
than loading a potentially stale struct home in the successor.

Require already-read-back locals at loop/backedge targets and handler
entries. Retain regular-successor traversal and explicit EH barriers,
including the existing materialization before throwing operations.
Readbacks otherwise occur at uses, allowing generalized rationalization
to extract parameter fields in the blocks that actually need them.

This changes readback placement, not promotion selection or its costing.
It avoids unnecessary eager extractions on early-return paths such as
Guid.CompareTo while leaving broader profitability tuning as follow-up.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4c28b3c3-cf6c-4149-8eb1-964831492011
@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 Sep 16, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

jakobbotsch and others added 2 commits September 21, 2026 10:18
Keep upstream's merged parameter-register rewriting implementation and preserve the lazy physical-promotion readback changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4c28b3c3-cf6c-4149-8eb1-964831492011
Index lazy-readback state by DFS postorder and use postorder bitsets for block flags. Track original-field currency across forward joins to avoid writing back replacements that have only been read, retaining conservative loop and handler entry state.

Remove the low-weight parameter extraction costing heuristic now that readbacks can be deferred. Keep the existing pending-readback intersection policy at joins.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4c28b3c3-cf6c-4149-8eb1-964831492011
jakobbotsch and others added 2 commits September 24, 2026 15:18
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 628eb6b2-f468-4a67-b2c9-f8de24969633
jakobbotsch and others added 3 commits September 25, 2026 12:40
Estimate lazy readback and reconciliation sites from liveness use/def sets. Let replacement materialize planned readbacks using its exact state, removing post-replacement commoning and may-definition tracking.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 628eb6b2-f468-4a67-b2c9-f8de24969633
Cache materialization boundaries for planning and replacement, short-circuit successor traversal, skip planning without eligible incoming fields, and avoid unnecessary definition queries.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 628eb6b2-f468-4a67-b2c9-f8de24969633
Move field tracking setup, boundary computation, and planning into PrepareReadBacks, called after constructing ReplaceVisitor.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 628eb6b2-f468-4a67-b2c9-f8de24969633

This branch has not been deployed

No deployments
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.

1 participant