Skip to content

[wasm] Bail R2R for SIMD16 store-indirect and SIMD16 parameters#130101

Merged
AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:fix-wasm-simd16-store-param-bail
Jul 2, 2026
Merged

[wasm] Bail R2R for SIMD16 store-indirect and SIMD16 parameters#130101
AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:fix-wasm-simd16-store-param-bail

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Fix a few missing SIMD bail outs that prevent SPC from validating.

Vector128 parameters are lowered to i32 in the wasm signature and a
SIMD16 store-indirect emits v128.store with an i32 operand, both of
which produce invalid modules; bail such methods to the interpreter
via NYI_WASM_SIMD until SIMD16 is properly supported.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AndyAyersMS AndyAyersMS requested review from adamperlin and Copilot July 1, 2026 22:47
@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 Jul 1, 2026
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@adamperlin PTAL
fyi @dotnet/wasm-contrib

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 adds additional WebAssembly (wasm) SIMD-related “not yet implemented” bailouts in CoreCLR JIT codegen to avoid generating invalid wasm modules (notably in ReadyToRun scenarios) when TYP_SIMD16 values flow through unsupported code paths.

Changes:

  • Bail out when a method has TYP_SIMD16 (Vector128) parameters, since they are currently represented as i32 in the wasm signature.
  • Bail out when emitting an indirect store of a TYP_SIMD16 value to avoid producing invalid v128.store sequences.

Comment thread src/coreclr/jit/codegenwasm.cpp

@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.

These fixes look good to me for now!

@AndyAyersMS AndyAyersMS enabled auto-merge (squash) July 2, 2026 01:16
@AndyAyersMS AndyAyersMS merged commit 8fe2929 into dotnet:main Jul 2, 2026
137 of 139 checks passed
@pavelsavara pavelsavara added the arch-wasm WebAssembly architecture label Jul 2, 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.

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 3, 2026
lewing added a commit that referenced this pull request Jul 9, 2026
Vector2 (`TYP_SIMD8`) and Vector3 (`TYP_SIMD12`) parameters are lowered
to `i32` in the wasm signature, the same as Vector128 (`TYP_SIMD16`),
but the argument-spill prolog in `genBeginFnProlog` only bailed R2R for
`TYP_SIMD16`.

As a result, a method with an 8-byte SIMD parameter — e.g.
`System.Numerics.Matrix3x2.CreateRotation(float, Vector2)` — emitted an
`f64.store` fed by the `i32` parameter local, producing an invalid
module that fails wasm validation:

```
func 20691 failed to validate
  type mismatch: expected f64, found i32
```

This currently prevents `System.Private.CoreLib` from producing a valid
R2R image (both single-file and composite).

## Fix

Broaden the parameter bail from `== TYP_SIMD16` to `varTypeIsSIMD(...)`
so `SIMD8`/`SIMD12`/`SIMD16` parameters are all sent to the interpreter
until SIMD parameters are supported in the wasm calling convention.

This is a direct follow-up to the SIMD16 parameter bail added in #130101
("Fix a few missing SIMD bail outs that prevent SPC from validating") —
it was the same class of bug, just missed for the smaller SIMD sizes.

## Validation

With this change, crossgen2 `--targetos wasi --targetarch wasm` on
`System.Private.CoreLib` (and a composite including it) produces a
module that passes `wasm-tools validate --features all`. Verified
locally on macOS/arm64.

> [!NOTE]
> This change was authored with the assistance of GitHub Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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