Skip to content

JIT: fix Wasm local declaration counts - #136956

Open
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:jit-wasm-local-count
Open

AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:jit-wasm-local-count

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Count ABI register reuse by Wasm type rather than register index, using the same check for counting and allocating locals. Preserve the existing type-mismatch fallback.

CoreLib examples:

  • TupleExtensions.Deconstruct<T1,T2> drops three unused locals: 137 -> 135 bytes.
  • Number.ConvertDecimalIeee754ToInteger<Decimal128,UInt128,ulong> drops one unused local: 331 bytes unchanged.

Code size

Libraries Wasm SuperPMI, 87,080 successful contexts on both JITs:

Bytes
Baseline 34,623,911
Fixed 34,615,484
Change -8,427 (-0.0243%)

4,074 methods shrink, none grow; 22,099 contexts have codegen differences. No compilation failures or missing contexts.

Validation

  • Built the Checked browser/Wasm runtime and cross-JIT with Release libraries/host.
  • Node/ReadyToRun execution: 186 optimized CodeGenBringUpTests passed; one existing multithreading-dependent test skipped.
  • Existing Runtime_133502 ABI type-mismatch regression passed in Node/ReadyToRun.
  • Verified matching runtime/JIT artifacts and successful ReadyToRun initialization.
  • Pinned clang-format dry run and git diff --check passed. Full jit-format/clang-tidy checks were blocked by local cross-target toolchain configuration.

Resolves #136727

Note

This PR description was generated with GitHub Copilot.

Match local counts with type-based ABI register reuse.
CoreLib tuple deconstruction drops 3 unused locals (137 -> 135 bytes).
Libraries SPMI: 8,427 bytes saved, 4,074 methods smaller, none larger.

Fixes dotnet#136727

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@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 Nov 4, 2026
@azure-pipelines

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

@AndyAyersMS

Copy link
Copy Markdown
Member Author

@adamperlin PTAL
fyi @dotnet/wasm-contrib

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.

🟢 Approval recommended

No active review issues were identified for the change aligning WebAssembly local counting with allocation.

No open issues 🎉

What changed in this PR

This PR corrects WebAssembly local declaration counts in the JIT by aligning ABI register reuse checks with local allocation, avoiding unused locals while preserving the type-mismatch fallback.

Changes:

  • Share a validity-and-type check between local counting and allocation instead of requiring identical register indices.
  • Add an assertion that allocated locals do not exceed the declared count.
File Description
src/​coreclr/​jit/​regallocwasm.cpp Aligns ABI register reuse checks and adds a local-count bounds assertion.

Review effort: Balanced

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.

[wasm][JIT] RA declares wasm locals that are never used when a parameter's virtual register index differs from its ABI register

2 participants