[Wasm RyuJit] Slightly smaller code for switches#122198
Merged
AndyAyersMS merged 2 commits intodotnet:mainfrom Dec 9, 2025
Merged
[Wasm RyuJit] Slightly smaller code for switches#122198AndyAyersMS merged 2 commits intodotnet:mainfrom
AndyAyersMS merged 2 commits intodotnet:mainfrom
Conversation
Wasm switches (`br_table`) have a default case, so take advantage of this and stop peeling off the default case in lower.
Member
Author
|
@dotnet/jit-contrib PTAL |
Contributor
There was a problem hiding this comment.
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 |
This was referenced Dec 5, 2025
Open
adamperlin
approved these changes
Dec 8, 2025
Contributor
adamperlin
left a comment
There was a problem hiding this comment.
This looks good to me! It's neat we can completely map GT_SWITCH -> br_table
This was referenced Dec 9, 2025
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Wasm switches (
br_table) have a default case, so take advantage of this and stop peeling off the default case in lower.