[Wasm RyuJit] Null checks for calls, overflow checks for int to int casts, resolve stack ordering, more#124534
Open
AndyAyersMS wants to merge 16 commits intodotnet:mainfrom
Open
[Wasm RyuJit] Null checks for calls, overflow checks for int to int casts, resolve stack ordering, more#124534AndyAyersMS wants to merge 16 commits intodotnet:mainfrom
AndyAyersMS wants to merge 16 commits intodotnet:mainfrom
Conversation
Member
Author
|
Sample codegen for ulong -> uint. Note I am seeing apparently unneeded local declarations like in the below. G_M6689_IG01: ; func=00, offs=0x000000, size=0x0003, bbWeight=1, PerfScore 2.00, gcrefRegs=00000000, byrefRegs=00000000, byref, nogc <-- Prolog IG
IN000d: 000000 local.cnt 1
IN000e: 000001 local[3] type=i64
G_M6689_IG02: ; offs=0x000003, size=0x0002, bbWeight=1, PerfScore 1.00, gcrefRegs=00000000, byrefRegs=00000000, BB01 [0000], byref
IN0001: 000003 block
G_M6689_IG03: ; offs=0x000005, size=0x000E, bbWeight=1, PerfScore 6.00, gcrefRegs=00000000, byrefRegs=00000000, BB01 [0000], byref
IN0002: 000005 local.get 1
IN0003: 000007 local.get 1
IN0004: 000009 i64.const 4294967295
IN0005: 00000F i64.gt_u
IN0006: 000010 br_if 0 ;; G_M6689_IG05
IN0007: 000012 i32.wrap_i64
G_M6689_IG04: ; offs=0x000013, size=0x0001, bbWeight=1, PerfScore 1.00, epilog, nogc, extend
IN000f: 000013 return
G_M6689_IG05: ; offs=0x000014, size=0x000C, bbWeight=0, PerfScore 0.00, gcVars=0000000000000000 {}, gcrefRegs=00000000, byrefRegs=00000000, BB02 [0001], gcvars, byref
IN0008: 000014 end
IN0009: 000015 local.get 0
IN000a: 000017 i32.const 0
IN000b: 000019 call 0 ;; CORINFO_HELP_OVERFLOW
IN000c: 00001F unreachable |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements three WASM codegen improvements: fixing return type classification for structs returned as primitives, adding null checks for calls, and implementing overflow checks for integer-to-integer casts.
Changes:
- Fixed struct return type classification to use
SPK_PrimitiveTypeinstead ofSPK_ByValuewhen WASM returns structs as primitive types - Added null check support for WASM calls that need them, with proper register allocation and code generation
- Implemented overflow checking for integer-to-integer casts in WASM codegen
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/jit/compiler.cpp | Fixed return type classification to use SPK_PrimitiveType for WASM structs returned as primitives |
| src/coreclr/jit/gentree.cpp | Added empty WASM case in InitializeStructReturnType for SPK_ByValue handling |
| src/coreclr/jit/lower.cpp | Mark thisArg as multiply-used for WASM calls needing null checks |
| src/coreclr/jit/lowerwasm.cpp | Mark cast operands as multiply-used when overflow checks are needed |
| src/coreclr/jit/stacklevelsetter.cpp | Register throw helper blocks for WASM calls needing null checks |
| src/coreclr/jit/regallocwasm.h | Added method declarations for call and cast reference collection |
| src/coreclr/jit/regallocwasm.cpp | Implemented register reference collection for calls and casts with checks |
| src/coreclr/jit/codegenwasm.cpp | Implemented overflow checking and null checking code generation for WASM |
| src/coreclr/jit/codegenarm.cpp | CRITICAL BUG: Incorrect code added that will not compile |
Member
Author
|
@dotnet/jit-contrib PTAL |
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
Contributor
SingleAccretion
left a comment
There was a problem hiding this comment.
LGTM modulo the delegate invoke question and comments.
SingleAccretion
approved these changes
Feb 20, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Various fixes from running crossgen