Skip to content

[Wasm RyuJit] Debug SPC Wasm Validation Fixes#125852

Open
AndyAyersMS wants to merge 9 commits intodotnet:mainfrom
AndyAyersMS:WasmCodegen6
Open

[Wasm RyuJit] Debug SPC Wasm Validation Fixes#125852
AndyAyersMS wants to merge 9 commits intodotnet:mainfrom
AndyAyersMS:WasmCodegen6

Conversation

@AndyAyersMS
Copy link
Member

Fixes for validation issues 2, 3, 4, 5, and 7 for Debug SPC.

See #125756 (comment)

  1. extend shift amount to i64 if necessary
  2. fix type used to pass 8 byte structs in registers
  3. Wasm relops always produce i32
  4. add generic context and async continuation args for Wasm method sig

Also add another bail-out option JitR2RUnsupportedRange that causes the JIT to fail R2R compilations for methods with the indicated JIT hashes. This is useful for selectively suppressing JIT codegen that has validation failures so we can find the full set without having fixes (since the validator will stop at the first error).

Copilot AI review requested due to automatic review settings March 20, 2026 18:56
@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 Mar 20, 2026
@AndyAyersMS
Copy link
Member Author

FYI @dotnet/jit-contrib

With these, #125812, workarounds for the asserts in #125756 and JitWasmNyiToR2RUnsupported=1, a debug SPC will validate. It contains about 14K method bodies.

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 targets WebAssembly RyuJit “Debug SPC” validation failures by adjusting Wasm calling signatures and fixing/guarding several codegen and lowering cases that produce invalid Wasm.

Changes:

  • Update Wasm method signature lowering to include generic-context and async-continuation hidden arguments.
  • Fix/adjust Wasm codegen for relop result typing, shift amount typing, and selected intrinsics with mixed operand/result widths.
  • Add a Wasm-only JIT config (JitR2RUnsupportedRange) to force R2R-unsupported bailouts for selected method hashes.

Reviewed changes

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

Show a summary per file
File Description
src/coreclr/tools/Common/JitInterface/WasmLowering.cs Extends Wasm signature construction to include async continuation + generic context hidden args.
src/coreclr/jit/morph.cpp Tweaks struct arg field list creation for Wasm to use the segment register type.
src/coreclr/jit/jitconfigvalues.h Adds JitR2RUnsupportedRange config string under TARGET_WASM.
src/coreclr/jit/codegenwasm.cpp Fixes several Wasm instruction typing issues; adds CopyBlk NYI guard; updates intrinsic handling for mixed types.
src/coreclr/jit/codegencommon.cpp Adds debug-only Wasm hook to fail R2R codegen for method-hash ranges.

// Note this will cause DNER if the arg was an unpromoted local.
//
#if defined(TARGET_WASM)
var_types slotType = regType;
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like something that needs to be handled in createSlotAccess, as another instance of LOWER_DECOMPOSE_LONGS == 0 problem. As-is we'll lose the GC types here (I don't have a clean change in mind though, it looks tricky for the general multi-reg case, and like we should really be passing regType down and making decisions based on that).

Copy link
Member Author

Choose a reason for hiding this comment

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

I meant to bypass this for GC structs; I think the createSlotAccess logic works there, at least for now.

Copy link
Member

Choose a reason for hiding this comment

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

I would suggest adding an overload of ABIRegisterSegment::GetRegisterType that takes ClassLayout and teaching it to return GC types appropriately, then switch the code here to always use the regType returned by that. I think multiple places can benefit from that.

Copy link
Member Author

Choose a reason for hiding this comment

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

GetRegisterType(ClassLayout*, unsigned offset)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I guess we can assume offset is part of the seg. Seems like we already have that overload.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need an offset version here, you can use the layout from the signature. Looks like the overload actually already exists. So probably

var_types regType = arg->GetSignatureLayout() != null ? seg.GetRegisterType(arg->GetSignatureLayout()) : seg.GetRegisterType()

would work.

Copy link
Member

Choose a reason for hiding this comment

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

(actually layout can be used in place of arg->GetSignatureLayout())

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. How do you feel about allowing GetRegisterType(nullptr)?

Copy link
Member

Choose a reason for hiding this comment

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

That sounds good to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just changed this one spot. Verified no x64 diffs locally.

@am11 am11 added the arch-wasm WebAssembly architecture label Mar 20, 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.

Copy link
Member

@jakobbotsch jakobbotsch left a comment

Choose a reason for hiding this comment

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

Morph changes look good to me. I think the arm64 diffs are fine (we stop doing some "out-of-bounds" loads resulting in fewer ldp's, I assume).

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.

7 participants