Skip to content

Handle cross-targeting Vector<T> size mismatch in the JIT - #130873

Merged
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-wasm-simd-size-assert
Jul 17, 2026
Merged

tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-wasm-simd-size-assert

Conversation

@tannergooding

Copy link
Copy Markdown
Member

getBaseTypeAndSizeOfSIMDType asserts that the JIT-computed SIMD size equals the VM's class size. Vector<T> is the only case whose size is target-dependent (getVectorTByteLength), so under a cross-targeting altjit -- e.g. SuperPMI replaying an x64-captured context with the wasm altjit, where the recorded class size reflects the host's Vector<T> length -- the two legitimately differ and the assert fires (simd.cpp (448), during Morph - Inlining, over System.Numerics.Vector<T> methods).

Rather than relax the assert and carry a size the VM disagrees with (which would leave later size queries inconsistent and emit misleading SIMD codegen), treat Vector<T> as a regular struct when the sizes disagree -- the same way the FEATURE_HW_INTRINSICS path already degrades on an unrecognized size. This keeps every size query consistent with the VM and only affects mismatched-VM altjit scenarios; matched VMs are unchanged (there size == getClassSize always holds, exactly what the existing assert guarantees).


Validated via SuperPMI base-vs-diff over the libraries MCH (libraries_tests_no_tiered_compilation.run, 397,158 contexts) with the wasm altjit and JitWasmSimdNyiToR2RUnsupported=1:

Signature Base Diff
simd.cpp (448) 137 0
every other assert signature -- byte-identical

Total assert occurrences drop by exactly 137 with no new signatures introduced; the formerly-asserting Vector<T> methods now replay as SuperPMI misses (a collection gap already tolerated for the wasm SIMD-NYI path).

Note

This PR description was drafted by Copilot.

getBaseTypeAndSizeOfSIMDType asserts that the JIT-computed SIMD size equals
the VM's class size. Vector<T> is the only case whose size is target-dependent
(getVectorTByteLength), so under a cross-targeting altjit -- e.g. SuperPMI
replaying an x64-captured context with the wasm altjit, where the recorded
class size reflects the host's Vector<T> length -- the two legitimately differ.

Rather than relax the assert and carry a size the VM disagrees with (which would
leave later size queries inconsistent and emit misleading SIMD codegen), treat
Vector<T> as a regular struct when the sizes disagree, the same way the
FEATURE_HW_INTRINSICS path already degrades on an unrecognized size. This keeps
every size query consistent with the VM and only affects mismatched-VM altjit
scenarios; matched VMs are unchanged.

Co-authored-by: Copilot App <[email protected]>
Copilot AI review requested due to automatic review settings July 16, 2026 14:02
@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 16, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
10 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: @JulieLeeMSFT, @jakobbotsch
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 the JIT’s SIMD type classification for System.Numerics.Vector<T> to avoid failing internal invariants when the JIT target and the VM’s recorded type layout don’t match (e.g., cross-targeting altjit/SuperPMI replay scenarios). The change makes the JIT treat Vector<T> as a regular struct (non-SIMD) when the JIT-computed Vector<T> size disagrees with the VM’s getClassSize, preventing downstream SIMD codegen from operating on an inconsistent size.

Changes:

  • Add a Vector<T>-specific size-consistency check in getBaseTypeAndSizeOfSIMDType.
  • Degrade Vector<T> to non-SIMD (TYP_UNDEF) when the JIT’s getVectorTByteLength() disagrees with the VM’s recorded class size.
Show a summary per file
File Description
src/coreclr/jit/simd.cpp Adds a Vector<T> size mismatch guard to avoid asserting/using inconsistent SIMD sizes under cross-targeting scenarios.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread src/coreclr/jit/simd.cpp Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings July 16, 2026 14:24

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.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new

@tannergooding

Copy link
Copy Markdown
Member Author

CC. @dotnet/jit-contrib, @adamperlin, removes one of the WASM SPMI asserts and generally improves the mismatched VM (altjit) scenario for cases where the collection hasn't forced the Vector size using the JIT config knob.

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

This looks good to me.

@tannergooding
tannergooding enabled auto-merge (squash) July 17, 2026 01:23
@tannergooding
tannergooding merged commit 56946bb into dotnet:main Jul 17, 2026
140 checks passed
@tannergooding
tannergooding deleted the tannergooding-wasm-simd-size-assert branch July 17, 2026 02:07
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 18, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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