Skip to content

[Wasm RyuJIT] Set wasm's vector width to 128 bits#126375

Open
kg wants to merge 2 commits intodotnet:mainfrom
kg:wasm-vector-width
Open

[Wasm RyuJIT] Set wasm's vector width to 128 bits#126375
kg wants to merge 2 commits intodotnet:mainfrom
kg:wasm-vector-width

Conversation

@kg
Copy link
Copy Markdown
Member

@kg kg commented Mar 31, 2026

This fixes a late compilation failure in crossgen when doing dependency analysis for Vector<T> in S.P.CoreLib:

Unhandled exception. System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at Internal.TypeSystem.LayoutInt.get_AsInt()
   at Internal.JitInterface.WasmLowering.LowerToAbiType(TypeDesc type)
   at Internal.JitInterface.WasmLowering.GetSignature(MethodSignature signature, LoweringFlags flags)
   at Internal.JitInterface.WasmLowering.GetSignature(MethodDesc method)
   at ILCompiler.DependencyAnalysis.NodeFactory.WasmTypeNode(MethodDesc method)
   at ILCompiler.DependencyAnalysis.ObjectNode.GetStaticDependencies(NodeFactory factory)
   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependenciesImpl(DependencyNodeCore`1 node)
   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes()
   at ILCompiler.ReadyToRunCodegenCompilation.Compile(String outputFile)
   at ILCompiler.Program.RunSingleCompilation(Dictionary`2 inFilePaths, InstructionSetSupport instructionSetSupport, String compositeRootPath, Dictionary`2 unrootedInputFilePaths, HashSet`1 versionBubbleModulesHash, ReadyToRunCompilerContext typeSystemContext, Logger logger) in Z:\runtime\src\coreclr\tools\aot\crossgen2\Program.cs:line 669
   at ILCompiler.Program.Run() in Z:\runtime\src\coreclr\tools\aot\crossgen2\Program.cs:line 314
   at ILCompiler.Crossgen2RootCommand.<>c__DisplayClass217_0.<.ctor>b__0(ParseResult result) in Z:\runtime\src\coreclr\tools\aot\crossgen2\Crossgen2RootCommand.cs:line 274
   at System.CommandLine.Invocation.InvocationPipeline.Invoke(ParseResult parseResult)
   at ILCompiler.Program.Main(String[] args) in Z:\runtime\src\coreclr\tools\aot\crossgen2\Program.cs:line 946

Also includes a related change Andy suggested to disable being optimistic about instruction sets, since we don't have a Wasm client-side jit.

See also #125756

@kg kg added the arch-wasm WebAssembly architecture label Mar 31, 2026
Copilot AI review requested due to automatic review settings March 31, 2026 20:55
@kg kg added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 31, 2026
@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.

Copy link
Copy Markdown
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

Sets the WebAssembly (Wasm32) target’s Vector<T> SIMD width to a concrete 128-bit size during toolchain compilation, avoiding LayoutInt.AsInt failures (indeterminate size) when crossgen2 computes Wasm signatures and dependency analysis for Vector<T>.

Changes:

  • Update InstructionSetSupport.GetVectorTSimdVector() to return SimdVectorLength.Vector128Bit for TargetArchitecture.Wasm32 (previously None).

@kg
Copy link
Copy Markdown
Member Author

kg commented Apr 1, 2026

@dotnet/jit-contrib PTAL

Copy link
Copy Markdown
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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/coreclr/tools/aot/crossgen2/Program.cs:95

  • The rationale here (“no Wasm client-side jit”) seems to apply to WASI targets as well. As-is, allowOptimistic will remain enabled by default for TargetOS.Wasi, which can reintroduce the same class of issues this change is trying to avoid. Consider extending the condition to include TargetOS.Wasi (or basing it on targetArchitecture == TargetArchitecture.Wasm32 rather than OS).
            if (targetOS is TargetOS.iOS or TargetOS.tvOS or TargetOS.iOSSimulator or TargetOS.tvOSSimulator or TargetOS.MacCatalyst or TargetOS.Browser)
            {
                // These platforms do not support jitted code, so we want to ensure that we don't
                // need to fall back to the interpreter for any hardware-intrinsic optimizations.
                // Disable optimistic instruction sets by default.
                allowOptimistic = false;

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.

2 participants