Skip to content

Conversation

@AndyAyersMS
Copy link
Member

Wasm switches (br_table) have a default case, so take advantage of this and stop peeling off the default case in lower.

Wasm switches (`br_table`) have a default case, so take advantage of this and
stop peeling off the default case in lower.
Copilot AI review requested due to automatic review settings December 4, 2025 21:39
@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 Dec 4, 2025
@AndyAyersMS
Copy link
Member Author

@dotnet/jit-contrib PTAL

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes WebAssembly switch statement code generation by leveraging the native default case support in Wasm's br_table instruction. Previously, the JIT would peel off the default case during lowering; this change preserves it for Wasm targets, resulting in smaller generated code.

Key changes:

  • Modified switch lowering to skip default case peeling for Wasm targets
  • Updated assertions and comments throughout to reflect that Wasm switches now retain their default cases
  • Adjusted optimization passes to handle the different switch IR representation on Wasm (GT_SWITCH vs GT_SWITCH_TABLE)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/coreclr/jit/lower.cpp Added early return for TARGET_WASM in LowerSwitch to prevent default case peeling
src/coreclr/jit/fgwasm.cpp Updated comments and changed assertion from !HasDefaultCase() to HasDefaultCase() to reflect new behavior
src/coreclr/jit/fgopt.cpp Added TARGET_WASM conditional for switchTree operator assertion (GT_SWITCH vs GT_SWITCH_TABLE)
src/coreclr/jit/codegenwasm.cpp Updated assertion to expect default case and added assertion for empty switch fallthrough case

Copy link
Contributor

@adamperlin adamperlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! It's neat we can completely map GT_SWITCH -> br_table

@dotnet-policy-service
Copy link
Contributor

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

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