[Wasm RyuJit] Null checks for calls, overflow checks for int to int casts, resolve stack ordering, more#124534
Conversation
|
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 |
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 |
|
@dotnet/jit-contrib PTAL |
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
SingleAccretion
left a comment
There was a problem hiding this comment.
LGTM modulo the delegate invoke question and comments.
adamperlin
left a comment
There was a problem hiding this comment.
I left a few comments with some questions!
adamperlin
left a comment
There was a problem hiding this comment.
This overall looks good to me! Just one small suggestion and an additional question.
Various fixes from running crossgen