Skip to content

JIT: omit redundant wasm eqz pairs before conditional branches - #137205

Merged
AndyAyersMS merged 2 commits into
dotnet:mainfrom
AndyAyersMS:wasm-eqz-peephole
Nov 9, 2026
Merged

AndyAyersMS merged 2 commits into
dotnet:mainfrom
AndyAyersMS:wasm-eqz-peephole

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Fold i32.eqz; i32.eqz; br_if to br_if. The two eqz instructions normalize an i32 to 0/1, which a conditional branch does not need. Value-producing and mixed-width sequences remain unchanged.

Enable the emitter's existing backward instruction navigation for Wasm. Keep zero-byte descriptors for elided instructions so captured instruction positions remain valid.

Size

Havit composite R2R:

Metric Reduction
Wasm owner image 50,640 bytes (0.158%)
Brotli-compressed owner image 1,285 bytes (0.031%)
SuperPMI code bytes 25,010 bytes (0.168%)

All 25,312 double-eqz branch sequences disappear from the linked image. SuperPMI: 38,469 successful contexts per JIT, 8,081 smaller, none larger. No GC-info size or EH-clause-count changes. Size figures use emitted code-byte metrics; the Wasm native differ has known decoder failures and false reports.

Validation

  • build.cmd clr.crossarchtools -os browser -arch wasm -c Release /p:RuntimeFlavor=CoreCLR passed for baseline and changed JITs.
  • build.cmd clr.crossarchtools -os browser -arch wasm -c Checked /p:RuntimeFlavor=CoreCLR passed.
  • 81 emitter harness controls passed, covering branch-only folding, descriptor locations, debug headers, instruction-group boundaries and GC boundaries. The optimization control fails with the baseline emitter.
  • 30 focused branch/value checks and existing boolean, GC/liveness, local-use and EH controls passed under Node with baseline and changed Release JITs, and with the Checked JIT under forced STRESS_EMITTER.
  • Havit and control Wasm images validated; formatting and whitespace checks passed.
  • Havit browser walkthrough completed. Strict smoke retains the baseline Bootstrap JavaScript error.
  • Full Checked corpus replay was blocked by missing Checked-only EE queries in the Release-collected MCH. Live Checked compilation and execution passed as noted above.
  • Full runtime suite, clang-tidy and performance timing comparisons were not run.

Contributes to #135985.

Note

This PR description was generated with GitHub Copilot.

Fold i32.eqz; i32.eqz; br_if to br_if.

Contributes to dotnet#135985.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 1da7d7aa-79b4-4ae1-ae4a-9861fdf9681c
@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
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@adamperlin PTAL
fyi @dotnet/wasm-contrib

@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.

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

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 1da7d7aa-79b4-4ae1-ae4a-9861fdf9681c
@AndyAyersMS

Copy link
Copy Markdown
Member Author

Failure is similar to #123280.

@AndyAyersMS
AndyAyersMS merged commit 1889003 into dotnet:main Nov 9, 2026
131 of 134 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