Skip to content

[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
AndyAyersMS:WasmMoreCodegen4
Open

[Wasm RyuJit] Null checks for calls, overflow checks for int to int casts, resolve stack ordering, more#124534
AndyAyersMS wants to merge 16 commits intodotnet:mainfrom
AndyAyersMS:WasmMoreCodegen4

Conversation

@AndyAyersMS
Copy link
Member

@AndyAyersMS AndyAyersMS commented Feb 18, 2026

Various fixes from running crossgen

  • fix return type classification for structs returned as primitives
  • null checks for calls
  • overflow checks for int to int casts
  • stack ordering and null check for delegate invoke
  • stack ordering for NOT

Copilot AI review requested due to automatic review settings February 18, 2026 03:30
@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 Feb 18, 2026
@AndyAyersMS
Copy link
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

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 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_PrimitiveType instead of SPK_ByValue when 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

Copilot AI review requested due to automatic review settings February 18, 2026 19:11
@AndyAyersMS AndyAyersMS changed the title Wasm more codegen4 [Wasm RyuJit] Null checks for calls, overflow checks for int to int casts, resolve stack ordering, more Feb 18, 2026
@AndyAyersMS AndyAyersMS marked this pull request as ready for review February 18, 2026 19:13
@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

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

@am11 am11 added the arch-wasm WebAssembly architecture label Feb 18, 2026
@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.

Copilot AI review requested due to automatic review settings February 19, 2026 20:24
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

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.

Copy link
Contributor

@SingleAccretion SingleAccretion left a comment

Choose a reason for hiding this comment

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

LGTM modulo the delegate invoke question and comments.

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.

4 participants

Comments