Skip to content

JIT: Elide adjacent Wasm local set/get pairs at known last uses - #137199

Merged
AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:wasm-last-use-peephole
Nov 9, 2026
Merged

AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:wasm-last-use-peephole

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Peephole optimize local.set N; local.get N away when the get is known to be the last use. Leave the value on the operand stack instead.

Preserve multiply-used candidate-local information into codegen, since one IR use can emit multiple reads. Keep elided instruction descriptors as zero-byte placeholders to preserve debug and GC instruction positions.

Size

Havit composite R2R:

Metric Reduction
Wasm owner image 48,768 bytes (0.152%)
Brotli-compressed owner image 12,094 bytes (0.291%)
SuperPMI code bytes 25,044 bytes (0.169%)

SuperPMI replayed 38,469 contexts successfully with both JITs: 7,346 smaller, none larger. One context with identical missing collection data on both JITs was excluded. Size figures use code-byte metrics; the Wasm native differ also produces false size-neutral reports.

Validation

  • build.cmd clr.crossarchtools -os browser -arch wasm -c Release /p:RuntimeFlavor=CoreCLR passed.
  • 33 managed controls passed under Node with baseline and changed R2R images.
  • Changed Havit Wasm validated and the browser walkthrough completed. Strict smoke still encounters the same Bootstrap JavaScript error as the baseline.
  • Full runtime suite and performance timing comparisons were not run.

Contributes to #135985.

Note

This PR description was generated with GitHub Copilot.

Peephole optimize 'local.set N; local.get N; ' -> '' if the get is
known to be the last use of the local. Instead the value is just
left on the stack.

Preserve multiply-used candidate-local information into codegen since
those locals may not have an obvious last use.

Contributes to dotnet#135985.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 1da7d7aa-79b4-4ae1-ae4a-9861fdf9681c
@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.

@AndyAyersMS

Copy link
Copy Markdown
Member Author

@adamperlin PTAL
fyi @dotnet/wasm-contrib

Small improvement in code size.

@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 9, 2026
@pavelsavara pavelsavara added the arch-wasm WebAssembly architecture label Nov 9, 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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

Comment thread src/coreclr/jit/emitwasm.cpp Resolved
@AndyAyersMS
AndyAyersMS merged commit e3704f4 into dotnet:main Nov 9, 2026
125 of 127 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture 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.

3 participants