Repository navigation
[wasm] Avoid Spilling Many GC-ref Typed Tree Temps - #135577
Merged
adamperlin merged 5 commits intoOct 15, 2026
Merged
Conversation
|
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. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Explicit call null checks can invoke a GC-triggering throw helper before the callee protects the newly unspilled arguments.
1 open finding
What changed in this PR
Optimizes Wasm GC-reference handling by avoiding unnecessary spills for arguments passed directly to managed calls.
Changes:
- Extracts operand-use removal into a reusable helper.
- Removes managed-call arguments before spilling other live references.
- Preserves spills for nested, helper, and unmanaged calls.
A blocking GC-safety issue remains for managed calls with explicit null checks.
| File | Description |
|---|---|
src/coreclr/jit/fgwasm.cpp |
Refines GC-reference spill decisions around calls. |
🧠 Review effort: Balanced
…by a direct parent call that is managed and non-helper
adamperlin
force-pushed
the
adamperlin/wasm-spill-refs-opt
branch
from
October 14, 2026 23:33
06c6b43 to
9f2a77c
Compare
adamperlin
marked this pull request as ready for review
October 14, 2026 23:44
Contributor
Author
|
cc @dotnet/wasm-contrib |
This was referenced Oct 15, 2026
Closed
EgorBo
approved these changes
Oct 15, 2026
EgorBo
left a comment
Member
There was a problem hiding this comment.
This looks very similar to what async.cpp does, wondering if we can share that
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The current
fgWasmSpillRefspass spills all outstanding GC-ref typed temporary values, even if those temps are consumed by the most immediate call. However, for calls 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, spilling and reloading, 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 crossgen2WasmImportThunk.cs).This PR removes the need for spilling in cases like:
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.
Results
SuperPMI
Total bytes of base: 8771651
Total bytes of diff: 8555629
Total bytes of delta: -216,022 (-2.46% of base)
Local Benchmarks