Skip to content

[wasm] Avoid Spilling Many GC-ref Typed Tree Temps - #135577

Draft
adamperlin wants to merge 1 commit into
dotnet:mainfrom
adamperlin:adamperlin/wasm-spill-refs-opt
Draft

adamperlin wants to merge 1 commit into
dotnet:mainfrom
adamperlin:adamperlin/wasm-spill-refs-opt

Conversation

@adamperlin

@adamperlin adamperlin commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

The current fgWasmSpillRefs pass spills all outstanding GC-ref typed temporary values, even if those temps are consumed by the most immediate managed, non-helper call. However, for a managed non-helper call, it should be the callee's responsibility to maintain GC safety of any incoming GC-ref typed args (either by spilling to a pinned stack home in the prolog or potentially avoiding spilling at all, see #135543). In the R2R fixup case, where a thunk will fix up the call target on first invocation, we should also be GC-protecting all incoming args by default (See the spilling logic in crossgen2 WasmImportThunk.cs).

This PR removes the need for spilling in cases like:

MyClass x = Allocate();
Use(x);

Where Use is managed.

Note that the spilling STILL needs to happen for nested calls, where a ref has an outstanding use which is NOT its most immediate parent.

MyClass x = Allocate();
M(x, F()) // <-- temporary value of x is an operand of the call to M, and may be live across the other sub-tree call, F where a GC might occur.

…by a direct parent call that is managed and non-helper
@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 Oct 10, 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.

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