Skip to content

JIT: Type implicit byref args as TYP_I_IMPL - #134644

Merged
EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:implicit-byref-i-impl
Sep 26, 2026
Merged

EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:implicit-byref-i-impl

Conversation

@EgorBo

@EgorBo EgorBo commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Implicit byref args are never on the GC heap (#133304), so type them as TYP_I_IMPL instead of TYP_BYREF (no GC reporting); async methods keep TYP_BYREF since their storage changes on resumption.
Treat return buffers as non-null in fgAddrCouldBeNull, and use fgAddrCouldBeHeap (now aware of implicit byrefs) for write barrier selection.
Contributes to #82166

Implicit byref arguments are never on the GC heap (dotnet#133304), so type them as
TYP_I_IMPL rather than TYP_BYREF to avoid GC reporting them. Also treat return
buffers as non-null in fgAddrCouldBeNull.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5bb92e6b-deb1-4963-9107-87559f446347
Copilot AI lite review requested due to automatic review settings September 25, 2026 10:01
@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 25, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 6 pipeline(s).
10 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

One or more issues must be addressed before approval.

Review effort: Lite
Findings: None

What changed in this PR

Updates JIT handling of implicit byref parameters to use TYP_I_IMPL, avoiding GC reporting and unnecessary write barriers. It also recognizes return-buffer locals as non-null.

Changes:

  • Retypes implicit byref locals and related IR.
  • Updates diagnostics, async analysis, and scope handling.
  • Documents the non-GC semantics of implicit byrefs.
File Description
src/​coreclr/​jit/​scopeinfo.cpp Updated as part of this pull request.
src/​coreclr/​jit/​morph.cpp Updated as part of this pull request.
src/​coreclr/​jit/​lclvars.cpp Updated as part of this pull request.
src/​coreclr/​jit/​importer.cpp Updated as part of this pull request.
src/​coreclr/​jit/​gentree.cpp Updated as part of this pull request.
src/​coreclr/​jit/​flowgraph.cpp Updated as part of this pull request.
src/​coreclr/​jit/​fgdiagnostic.cpp Updated as part of this pull request.
src/​coreclr/​jit/​compiler.h Updated as part of this pull request.
src/​coreclr/​jit/​asyncanalysis.cpp Updated as part of this pull request.
docs/​design/​coreclr/​botr/​clr-abi.md Updated as part of this pull request.

* Keep implicit byrefs TYP_BYREF in async methods: their storage changes on
  resumption, so derived addresses must not be kept live (e.g. CSE'd) across
  suspension points.
* Use fgAddrCouldBeHeap for write barrier selection and teach it about implicit
  byrefs, removing checked barriers for stores to ret bufs and implicit byrefs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5bb92e6b-deb1-4963-9107-87559f446347
Copilot AI review requested due to automatic review settings September 25, 2026 10:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Add targeted GC regression coverage and clarify the ABI documentation exceptions.

Review effort: Lite
Findings: None

@EgorBo

EgorBo commented Sep 25, 2026

Copy link
Copy Markdown
Member Author

PTAL @jakobbotsch @dotnet/jit-contrib Diffs mostly from teaching fgAddCanBeNull (ret buffer and implicit byref are never null) and fgAddrCouldBeHeap

@adamperlin

Copy link
Copy Markdown
Contributor

@EgorBo I wonder if this will have beneficial impacts for Wasm CQ; Specifically, we are trying to reduce conservative spilling of refs to the shadow stack, so if these were marked as possibly GC references before and they aren't now, this could maybe remove the need for some spills.

@adamperlin

Copy link
Copy Markdown
Contributor

Update: looking at the diffs, I see some removals of both spills and explicit null checks, and it looks like the biggest overall code size reduction was actually on the Wasm CoreLib collection!

@EgorBo
EgorBo merged commit a4dade2 into dotnet:main Sep 26, 2026
139 of 142 checks passed
@EgorBo

EgorBo commented Sep 26, 2026

Copy link
Copy Markdown
Member Author

Update: looking at the diffs, I see some removals of both spills and explicit null checks, and it looks like the biggest overall code size reduction was actually on the Wasm CoreLib collection!

Yep, it seems wasm uses implicit byrefs more (Non-unwrappable structures)

@EgorBo
EgorBo deleted the implicit-byref-i-impl branch September 26, 2026 10:58
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 27, 2026
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.

5 participants