Skip to content

JIT: remove MorphAddrContext#127684

Draft
EgorBo wants to merge 1 commit intodotnet:mainfrom
EgorBo:remove-morph-addr-context
Draft

JIT: remove MorphAddrContext#127684
EgorBo wants to merge 1 commit intodotnet:mainfrom
EgorBo:remove-morph-addr-context

Conversation

@EgorBo
Copy link
Copy Markdown
Member

@EgorBo EgorBo commented May 2, 2026

Removes the MorphAddrContext thread-through hack from fgMorphTree/fgMorphSmpOp/fgMorphFieldAddr/fgMorphExpandInstanceField and replaces it with a small fgMarkAddrModeForFieldAddr pre-walk that peels constant offsets and chained instance FIELD_ADDRs off an indirection's unmorphed address tree to decide null-check elision (a new GTF_FLD_TGT_NONFAULTING flag is set on each elidable FIELD_ADDR).

No SPMI asmdiffs.

Copilot AI review requested due to automatic review settings May 2, 2026 16:52
@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 May 2, 2026
@EgorBo EgorBo marked this pull request as draft May 2, 2026 16:54
@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 CoreCLR JIT morphing for instance field-address null-check handling by removing the threaded MorphAddrContext state and replacing it with a pre-walk over unmorphed indirection address trees. The goal is to preserve/null-check-elide FIELD_ADDR behavior in a more explicit way during morph.

Changes:

  • Adds fgMarkAddrModeForFieldAddr to pre-scan indirection address trees and mark FIELD_ADDR nodes whose explicit null check can be elided.
  • Replaces the old MorphAddrContext plumbing from fgMorphTree/fgMorphSmpOp/fgMorphFieldAddr/fgMorphExpandInstanceField.
  • Introduces a new GTF_FLD_TGT_NONFAULTING flag to carry the pre-walk decision into field-address expansion.

Reviewed changes

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

File Description
src/coreclr/jit/morph.cpp Adds the new address pre-walk and updates morphing to consume a per-FIELD_ADDR flag instead of threaded context.
src/coreclr/jit/gentree.h Defines the new GT_FIELD_ADDR flag used by the morph pre-walk.
src/coreclr/jit/compiler.h Removes MorphAddrContext declarations and updates morph helper signatures.

Comment thread src/coreclr/jit/morph.cpp Outdated
Replace the threaded MorphAddrContext with fgMarkAddrModeForFieldAddr,
a pre-walk over an indirection's address tree that peels constant
offsets and chained instance FIELD_ADDRs to decide null-check elision.

The new GTF_FLD_TGT_NONFAULTING flag on FIELD_ADDR communicates that
the consuming indirection will fault on null, so the explicit null
check inserted by morph can be elided.

SPMI asmdiffs: no diffs across all 11 collections.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@EgorBo EgorBo force-pushed the remove-morph-addr-context branch from 2b35da4 to 9cbbc60 Compare May 2, 2026 17:38
Comment thread src/coreclr/jit/morph.cpp
mac = nullptr;
// Examine the unmorphed address tree to identify any FIELD_ADDR whose null check
// can be elided because this indirection will fault on null instead.
fgMarkAddrModeForFieldAddr(tree->AsIndir());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It might be handled by PGO, but I think you want an early guard here to avoid the TP hit:

basically do the initial check that tree->Addr()->OperIs(GT_FIELD_ADDR) || !tree->Addr()->AsFieldAddr()->IsInstance(), to avoid hitting the call + loop for all the other indirection types

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