Skip to content

Fix wasm R2R JIT validation issues#129555

Merged
AndyAyersMS merged 9 commits into
dotnet:mainfrom
AndyAyersMS:fix-wasm-r2r-jit-validation
Jun 22, 2026
Merged

Fix wasm R2R JIT validation issues#129555
AndyAyersMS merged 9 commits into
dotnet:mainfrom
AndyAyersMS:fix-wasm-r2r-jit-validation

Conversation

@AndyAyersMS

@AndyAyersMS AndyAyersMS commented Jun 18, 2026

Copy link
Copy Markdown
Member
  • Use call node type when forming wasm call signatures.
  • Treat GT_FRAME_SIZE as a wasm leaf during use-edge iteration.
  • Classify single-register struct call stores by wasm ABI type.
  • Preserve ABI segment widths for wasm parameter register remaps.
  • Use the return type for wasm fast tail calls (gtType is overwritten to TYP_VOID).
  • JIT/wasm: skip Try/ExnRefWrapper in findTargetDepth for plain br targets.
  • JIT/wasm: emit an explicit br for try-leave even when the target is the contiguous next block.
  • JIT/wasm: extend the exnref wrapper to the catch-resumption dispatcher.
  • JIT/wasm: sort intervals by Start before conflict resolution (cross-try-exit Block intervals are backdated to start at the try header, breaking the non-decreasing-start-order invariant).
  • VM/wasm: use the slow IsFilterFunclet path for wasm R2R (wasm doesn't use personality routines in unwind data). (fixes Wasm / R2R: IsFilterFunclet assertion fires when re-throwing from a finally after a cctor failure (throwinclassconstructor) #129341)
  • JIT/wasm: skip the emitter-driven LCL_ADDR GC-tracking assert (wasm uses stack-slot GC info, not fixed-register tracking).

Issue: #129497

- Use call node type when forming wasm call signatures.

- Treat GT_FRAME_SIZE as a wasm leaf during use-edge iteration.

- Classify single-register struct call stores by wasm ABI type.

- Preserve ABI segment widths for wasm parameter register remaps.

- Bail out on wasm method/call signatures over the engine limit.

Issue: dotnet#129497

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 18, 2026 01:42
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@adamperlin PTAL
fyi @dotnet/wasm-contrib

@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 Jun 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adjusts WebAssembly (Wasm) JIT/R2R codegen plumbing to produce wasm-valid call/method signatures and to avoid validation/assert failures in several JIT phases when compiling for Wasm.

Changes:

  • Update Wasm call signature construction and add explicit bailouts when a call/function would exceed the Wasm engine parameter limit (1000).
  • Treat GT_FRAME_SIZE as a leaf for Wasm during use-edge iteration to avoid consumers assuming it has operands.
  • Refine Wasm ABI typing in lowering for single-register struct call stores and preserve ABI segment widths when inducing parameter-register locals.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/coreclr/jit/lower.cpp Adjusts Wasm ABI-based typing for single-reg struct call stores; preserves register-segment type widths for induced parameter locals.
src/coreclr/jit/lclvars.cpp Adds a Wasm-specific compilation bailout when the function argument count exceeds the Wasm engine limit.
src/coreclr/jit/gentree.cpp Treats GT_FRAME_SIZE as a leaf for Wasm in GenTreeUseEdgeIterator.
src/coreclr/jit/error.h Introduces WASM_IMPL_LIMITATION macro (Wasm-only impl-limitation helper).
src/coreclr/jit/compiler.h Defines MaxWasmFunctionParameters constant for Wasm.
src/coreclr/jit/codegenwasm.cpp Adjusts wasm call signature construction and adds a call-argument-count bailout prior to requesting a type symbol.

Comment thread src/coreclr/jit/codegenwasm.cpp Outdated
Comment thread src/coreclr/jit/error.h Outdated
Comment thread src/coreclr/jit/error.h Outdated
Comment thread src/coreclr/jit/compiler.h Outdated
AndyAyersMS and others added 5 commits June 18, 2026 07:45
For fast tail calls gtType is overwritten to TYP_VOID, so use gtReturnType when forming the wasm call signature.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cross-try-exit Block intervals are backdated to start at the try
header, breaking the non-decreasing-start-order invariant assumed by
the resolve loop.
@AndyAyersMS

Copy link
Copy Markdown
Member Author

Not entirely happy with the "backdate" fix for branches out of try interval. Seems like constraint solving ought to be able to handle it, if a block overlaps a try (and since trys are single entry this means the block begins inside the try and ends outside) it should just stretch to encompass the try and (now) the two wrapper intervals.

Some of the other fixes are consequences of codegen inserting code (namely the post-try unreached and exception-capturing store) without having IR; this may also be something to revisit.

Wasm R2R doesn't use personality routines in unwind data, so fall back
to the slow EH-clause walk like X86 does.
Copilot AI review requested due to automatic review settings June 19, 2026 13:43
@pavelsavara pavelsavara added the arch-wasm WebAssembly architecture label Jun 19, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 1 comment.

Comment thread src/coreclr/jit/lower.cpp
@AndyAyersMS

Copy link
Copy Markdown
Member Author

Pri-0 R2R sweep impact

Baseline After these commits
Tests (merged-runner XML) 699 1299
Pass 561 1161 (+600)
Fail 5 1
Wrapper failures 28 20

A separate Pri-1 sweep on top of these commits shows 1738 / 1909 tests pass (91.0%). No new R2R-specific failure modes surfaced in the broader Pri-1 set; remaining wrapper failures are tracked separately in #129622 and #129337.

Wasm uses stack-slot GC info encoding rather than fixed-register tracking,
so the emitter concern this assert guards (live updates for LCL_ADDR DEFs
of tracked GC vars) does not apply.
Copilot AI review requested due to automatic review settings June 19, 2026 18:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 6 out of 6 changed files in this pull request and generated no new comments.

@davidwrighton davidwrighton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

VM changes look good. JIT looks good too, but I'm not a good reviewer of JIT changes. :)

@adamperlin adamperlin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

JIT changes lgtm from what I understand!

@AndyAyersMS AndyAyersMS merged commit 72788f0 into dotnet:main Jun 22, 2026
136 of 138 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 23, 2026
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.

Wasm / R2R: IsFilterFunclet assertion fires when re-throwing from a finally after a cctor failure (throwinclassconstructor)

6 participants