Skip to content

JIT: Fix WASM scalar extraction from SIMD parameters#131237

Merged
lewing merged 1 commit into
mainfrom
lewing-fix-wasm-simd-scalar-extract
Jul 23, 2026
Merged

JIT: Fix WASM scalar extraction from SIMD parameters#131237
lewing merged 1 commit into
mainfrom
lewing-fix-wasm-simd-scalar-extract

Conversation

@lewing

@lewing lewing commented Jul 22, 2026

Copy link
Copy Markdown
Member

Summary

Fixes a WASM codegen bug where extracting a scalar field from a SIMD-register parameter leaks a v128 where a scalar (f64/f32/...) is expected, producing invalid WASM:

type mismatch: expected f64, found v128

Lowering::FindInducedParameterRegisterLocals maps a scalar field of an unenregisterable parameter to the local created for the containing register segment. Native targets can read the overlapping low scalar value by retyping that local access, but WASM has distinct v128 and scalar value-stack types and cannot reinterpret them implicitly.

This is the floating-point ToScalar / SIMD-to-scalar var_type transition at ABI boundaries noted as deferred in #130444.

Fix

When the mapped incoming register local is SIMD and the field is scalar, use gtNewSimdGetElementNode under TARGET_WASM. For lane zero this becomes ToScalar, which WASM lowers to the appropriate extract_lane operation rather than retyping a v128 local or spilling through memory.

The byte offset is required to be scalar-lane aligned before deriving the lane index. Every non-WASM target retains the existing path unchanged.

Validation

  • ./build.sh clr.jit -rc Debug
  • PATH="/opt/homebrew/bin:$PATH" ./build.sh -os browser -c Debug -subset clr+libs
    • Confirmed lower.cpp compiled into the WASM JIT.
  • python3 src/coreclr/scripts/jitformat.py -r . -o osx -a arm64

There is currently no WASM R2R validation leg in CI suitable for a focused regression test. The existing generalized extraction tests from #131174 were intentionally not included in this narrowly scoped WASM correctness fix.

Note

This PR was authored with the assistance of GitHub Copilot.

Extract scalar fields directly from SIMD parameter-register locals on WASM so v128 values are not retyped as scalar locals.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e48939ab-dc73-4630-a8ca-72c3b926133a
Copilot AI review requested due to automatic review settings July 22, 2026 21:54
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
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

This PR updates CoreCLR JIT lowering to correctly materialize scalar reads from SIMD-register-backed parameter locals on WebAssembly by generating an explicit SIMD lane extraction rather than relying on native-style “retyping” of a v128 local access into a scalar type.

Changes:

  • Add a TARGET_WASM-specific path in Lowering::FindInducedParameterRegisterLocals to use gtNewSimdGetElementNode when extracting a scalar from a SIMD local.
  • Preserve the existing behavior for non-WASM targets.

Comment thread src/coreclr/jit/lower.cpp
@lewing
lewing requested a review from AndyAyersMS July 22, 2026 22:03
@lewing

lewing commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

/ba-g infra failures outside the platform guard on this pr

@lewing
lewing merged commit c8132fb into main Jul 23, 2026
133 of 139 checks passed
@lewing
lewing deleted the lewing-fix-wasm-simd-scalar-extract branch July 23, 2026 02:29
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants