Skip to content

JIT: Propagate class handle when split tree#128485

Open
hez2010 wants to merge 3 commits into
dotnet:mainfrom
hez2010:split-preserve-class
Open

JIT: Propagate class handle when split tree#128485
hez2010 wants to merge 3 commits into
dotnet:mainfrom
hez2010:split-preserve-class

Conversation

@hez2010
Copy link
Copy Markdown
Contributor

@hez2010 hez2010 commented May 22, 2026

Propagate the class handle when we spill a tree into a local so that later devirtualization can see the more exact class.

Codegen for the snippet in the linked issue:

Before:

G_M000_IG01:                ;; offset=0x0000
       sub      rsp, 40
 
G_M000_IG02:                ;; offset=0x0004
       mov      rcx, 0x7FFB9190F410
       call     CORINFO_HELP_NEWSFAST
       mov      rcx, rax
       mov      byte  ptr [rcx+0x08], 0
       mov      r11, 0x7FFB91640078
       call     [r11]Program+IBar:Bar():this
       nop      
 
G_M000_IG03:                ;; offset=0x0028
       add      rsp, 40
       ret      
 
; Total bytes of code 45

After:

G_M24006_IG01:  ;; offset=0x0000
       sub      rsp, 40
                                                ;; size=4 bbWeight=1 PerfScore 0.25
G_M24006_IG02:  ;; offset=0x0004
       mov      ecx, 42
       call     [System.Console:WriteLine(int)]
       nop
                                                ;; size=12 bbWeight=1 PerfScore 3.50
G_M24006_IG03:  ;; offset=0x0010
       add      rsp, 40
       ret
                                                ;; size=5 bbWeight=1 PerfScore 1.25

; Total bytes of code 21

Resolves #128483

Copilot AI review requested due to automatic review settings May 22, 2026 14:07
@hez2010
Copy link
Copy Markdown
Contributor Author

hez2010 commented May 22, 2026

@MihuBot

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

Note

Copilot was unable to run its full agentic suite in this review.

Updates gtSplitTree to better annotate compiler-generated temps created during tree splitting, including marking them as single-definition locals and propagating reference type class metadata when available.

Changes:

  • Marks the temporary local produced by gtNewTempStore as lvSingleDef.
  • When the value is a TYP_REF, attempts to propagate its class handle to the temp via lvaSetClass.
  • Refactors the splitting logic to use a named value temp for clarity.
Comments suppressed due to low confidence (2)

src/coreclr/jit/gentree.cpp:1

  • isNonNull is computed via gtGetClassHandle(...) but not used. Either remove isNonNull entirely if it’s not needed here, or (preferred if available in this codebase) propagate the non-null information to the temp local (e.g., via the appropriate lva* API) so the extra work has a functional effect.
    src/coreclr/jit/gentree.cpp:1
  • This directly mutates lvSingleDef at the point of inserting a store. If later phases can introduce additional defs for this temp (or if lvSingleDef is expected to be derived by an analysis pass instead of being set manually), this risks stale/incorrect single-def metadata. Consider setting this only when the temp is created (where its lifetime/def-count is guaranteed), or using an existing helper/annotation mechanism for ‘compiler temp known single-def’ (so invariants stay centralized).

@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 22, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label May 22, 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.

Copilot AI review requested due to automatic review settings May 22, 2026 14:31
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 1 out of 1 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

src/coreclr/jit/gentree.cpp:1

  • isNonNull is populated by gtGetClassHandle but never used afterward. If nullability isn’t needed here, pass nullptr for that out-param and remove isNonNull; if it is needed, propagate it onto the local using the appropriate local/property so the information isn’t computed and then dropped.
    src/coreclr/jit/gentree.cpp:1
  • Prefer assigning boolean fields using true/false rather than 1/0 to better communicate intent and avoid relying on the underlying representation of the field.

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 community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gtSplitTree can drop the type information from locals

2 participants