Repository navigation
[wasm] Take wasm SIMD instruction sets from the compiler; default relaxed SIMD on for WASI - #137112
Merged
Merged
Conversation
- WasiApp.CoreCLR.targets: default WasmEnableRelaxedSimd=true; when on, pass --instruction-set:relaxed-simd to crossgen2 and set the System.Runtime.Intrinsics.Wasm.RelaxedSimd.IsSupported runtime property. - wasihost and corerun (wasm): enable the RelaxedSimd instruction set when that property is true, as browserhost does. - src/tests: apply WasmEnableRelaxedSimd to crossgen2 and corerun for browser and WASI (default on for WASI), and forward it from build.proj to test projects. Previously /p:WasmEnableRelaxedSimd=true on the hardware-intrinsics-wasm lane reached neither, so RelaxedSimd.IsSupported stayed false. - Add a RelaxedSimd test asserting IsSupported matches the host property under R2R. - Add a wasi_wasm leg to hardware-intrinsics-wasm. - Document the WASI default and trade-offs. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…34949 PackedSimdIsSupported, RelaxedSimdIsSupportedReflects and LoadStoreNullCheckTest call into CoreLib at run time, which is interpreted in WASI ReadyToRun test composites. Skip them only when IsWasi && IsReadyToRunCompiled; they still run in the WASI interpreter lane and on browser. Use the shared IsWasmReadyToRun predicate for IsSupportedMatchesHostConfiguration. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Wasm has no runtime feature detection, so the runtime's CPU flags cannot confirm the instruction sets a ReadyToRun image requires. Previously hosts read a System.Runtime.Intrinsics.Wasm.RelaxedSimd.IsSupported runtime property and called an exported coreclr_wasm_set_relaxed_simd_supported() so the image-wide instruction set fixup would pass. The engine already validates the code when it compiles the module, so on wasm treat instruction sets an image requires as supported. Must-be-unsupported assertions are still checked against the runtime flags. This removes the exported setter, the browserhost/wasihost/corerun property handling, and the RuntimeHostConfigurationOption items; WasmEnableRelaxedSimd now only selects --instruction-set:relaxed-simd (and the browser emcc flags). PublishRelaxedSimdCoreClr now publishes ReadyToRun and checks RelaxedSimd.IsSupported instead of the removed runtime property. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 7 pipeline(s). 8 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Run ConvertToInt32Native and MultiplyAddEstimate through NoInlining methods and check their results when relaxed SIMD is enabled, and check that the opt-out throws PlatformNotSupportedException, instead of only printing IsSupported. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
Contributor
|
Tagging subscribers to this area: @dotnet/crossgen-contrib |
jkotas
reviewed
Nov 6, 2026
IsSupported should be consistent across interpreted and compiled code; the mismatch is tracked by dotnet#134949. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The browser leg runs non-composite: CoreLib's R2R image is precompiled at build time while the tests are crossgen'd with --instruction-set:relaxed-simd, so the two images disagreed on RelaxedSimd.IsSupported. Let crossgen-corelib.proj add the instruction set when WasmEnableRelaxedSimd=true and pass it to the leg's runtime build. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
jkotas
reviewed
Nov 7, 2026
… CoreLib - InstructionSetHelpers adds relaxed-simd to the default WASI instruction sets, so crossgen2 and ILC callers no longer pass it. - Add PublishReadyToRunInstructionSet, the ReadyToRun counterpart of IlcInstructionSet, and drop the WASI WasmEnableRelaxedSimd plumbing. Opt out with PublishReadyToRunInstructionSet=-relaxed-simd. - On wasm the runtime takes its instruction sets from CoreLib's ReadyToRun image and validates other images against them, instead of skipping the check. - WASI src/tests ReadyToRun run with an interpreted CoreLib (dotnet#134949), so they default to -relaxed-simd. - Remove WasiEnableCompositeR2R; PublishReadyToRunComposite is already required, so the host's composite link flags follow PublishReadyToRun. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Add the WASI target framework to System.Runtime.Intrinsics.Tests and run PackedSimdTests and RelaxedSimdTests on WASI as well as browser, so the WASI library ReadyToRun lane exercises relaxed SIMD with CoreLib in the composite. Drop the tests.wasi.targets default; the substitutions it fed are not used on WASI. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Resolve src/tests/Directory.Build.targets: keep main's nativeaot exclusion on the CLRTest.WasmCorerun.targets import and this branch's instruction-set block. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lewing
marked this pull request as ready for review
November 10, 2026 21:51
WASI publishing records a hash of the crossgen2 arguments as an input of _CreateR2RImages and deletes stale images when it changes, as browser already does. CoreLib's crossgen step records PublishReadyToRunInstructionSet. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Member
Author
|
I'm going to combine this with #137114 since the split is reducing clarity rather than adding it. |
Folds in dotnet#137114. NativeAOT's CoreLib now compiles the wasm intrinsics: - ILC maps System.Runtime.Intrinsics.Wasm types to instruction sets in GetHardwareIntrinsicId, so it supplies the IsSupported bodies. - The JIT treats wasm ISA support as exact under the NativeAOT ABI, since wasm has no runtime ISA detection. - SupportsWasmIntrinsics is true for every wasm CoreLib, and relaxed SIMD for every non-Mono one. NativeAOT WASI picks up relaxed SIMD from the compiler's WASI default; opt out with IlcInstructionSet=-relaxed-simd, which src/tests/build.proj now forwards to the inner test build. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nstructionSet Relaxed SIMD only affects ReadyToRun code, so browser opts in the same way as WASI: PublishReadyToRunInstructionSet=relaxed-simd. WasmEnableRelaxedSimd duplicated that and could disagree with it. - Drop -mrelaxed-simd, WASM_ENABLE_RELAXED_SIMD, the relink trigger and the workload requirement; no native code uses relaxed SIMD. - Always enable relaxed SIMD in wasm-opt, so the ReadyToRun wasm-opt pass accepts images built with it. Enabling a feature only allows it. - Stop folding IsSupported with trimmer substitutions on CoreCLR. The JIT and interpreter decide support per method, and measured on a trimmed WASI R2R app the folding saved about 2.7 KB of R2R code. Delete the relaxed SIMD substitution files. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
jkotas
reviewed
Nov 14, 2026
jkotas
reviewed
Nov 14, 2026
jkotas
reviewed
Nov 14, 2026
Changing crossgen2 arguments doesn't recompile R2R images on any target, so the fix belongs in the common crossgen2 targets rather than WASI's. Also drop the instruction-set comment in crossgen-corelib.proj, per review. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This was referenced Nov 15, 2026
jkotas
approved these changes
Nov 15, 2026
lewing
enabled auto-merge (squash)
November 15, 2026 01:01
The SDK's copy of the crossgen2 targets doesn't map PublishReadyToRunInstructionSet yet, so app publishes outside this repo dropped it: browser's relaxed SIMD opt-in and WASI's opt-out had no effect. The browser and WASI targets now add --instruction-set themselves unless crossgen2 already gets one. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…37571 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… targets Remove the fallback targets that mapped PublishReadyToRunInstructionSet for app publishes and disable the enabled case of PublishRelaxedSimdCoreClr against dotnet#137571 until an SDK with the mapping flows. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lewing
added a commit
to lewing/sdk
that referenced
this pull request
Nov 15, 2026
…t argument Matches dotnet/runtime's copy of the crossgen2 targets (dotnet/runtime#137112), so the property works for app publishes, as IlcInstructionSet does for NativeAOT. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
jkotas
approved these changes
Nov 15, 2026
Member
Author
|
/ba-g failures are not related |
lewing
added a commit
that referenced
this pull request
Nov 18, 2026
) `_CreateR2RImages` only compares files, so an incremental publish that changes only the crossgen2 arguments reuses stale ReadyToRun images. Jan's repro: publish a console app with `/p:PublishReadyToRun=true /p:PublishReadyToRunCrossgen2ExtraArgs=--instructionset:avx2`, then again with `avx512`. The second publish does not recompile. ## Change This follows the established SDK pattern (for example, `CreateGeneratedAssemblyInfoInputsCacheFile`). A new target, `_CreateReadyToRunCompilerArgumentsCacheFile`, runs before `_CreateR2RImages`. It uses the `Hash` task to hash: - `PublishReadyToRunCrossgen2ExtraArgs` - the target-computed `_PublishReadyToRunCrossgen2ExtraArgs` - `PublishReadyToRunInstructionSet` (via `_ReadyToRunInstructionSetArgs`) - `PublishReadyToRunComposite` - `PublishReadyToRunContainerFormat` - `PublishReadyToRunUseCrossgen2` - `PublishReadyToRunPerfmapFormatVersion` It writes the hash to `$(IntermediateOutputPath)$(MSBuildProjectName).ReadyToRunCompilerArguments.cache` only when the hash changes. `_CreateR2RImages` lists that file as an input, so changing any of these values makes every image out of date. **Target ordering:** `BeforeTargets` hooks run in declaration order. The new target therefore sees arguments added by hooks declared earlier, including project and `Directory.Build.targets` hooks. Hooks imported after the SDK targets must also run before `_CreateReadyToRunCompilerArgumentsCacheFile`, or list their own inputs in `_ReadyToRunCompilerInputs`. The WASI and browser hooks that add `--directpinvoke` already list their pinvoke manifests that way. The browser `--partial` PGO argument is tracked by `browser-r2r-state.stamp`, which is left unchanged; it also tracks the PGO file list and the wasm-opt post-processing state. **`PublishReadyToRunInstructionSet` with command-line extra args:** #137112 appended `--instruction-set:` to `PublishReadyToRunCrossgen2ExtraArgs` at evaluation time. When that property is passed with `-p:`, it is a global property, so the append was ignored and the instruction set was silently dropped. maraf found this in dotnet/sdk#57127. The instruction set now goes through an internal `_ReadyToRunInstructionSetArgs` property, which both `RunReadyToRunCompiler` calls pass and the hash includes. This mirrors dotnet/sdk@485b9063d4. ## Validation All runs used a `dotnet new console` app with the .NET 11 SDK (11.0.100-preview.6), `-r osx-arm64 -p:PublishReadyToRun=true`, and the in-tree targets imported via `-p:AfterMicrosoftNETSdkTargets=<this file>`: | Scenario | Stock SDK | This PR | |---|---|---| | Change `PublishReadyToRunCrossgen2ExtraArgs` (`--instruction-set:apple-m1` → `armv8.2-a`) | `_CreateR2RImages` skipped (bug) | rebuilt | | Unchanged republish | — | skipped | | Switch back to the earlier args | — | rebuilt | | Args added to `_PublishReadyToRunCrossgen2ExtraArgs` by a `BeforeTargets="_CreateR2RImages"` hook, then changed | — | rebuilt; the new ISA was on the crossgen2 command line | | Self-contained `PublishReadyToRunComposite=true` → `false` | — | rebuilt | | Failing args (`--bogus-option`), republish, then revert to the earlier args | — | the failed compile retried, then reverting recompiled | | Source-only change with the same args, then republish | — | rebuilt once, then skipped | | `PublishReadyToRunInstructionSet=apple-m1` with `-p:PublishReadyToRunCrossgen2ExtraArgs=--Ot` | `--instruction-set` dropped (main's targets) | both arguments passed to crossgen2 | | Change `PublishReadyToRunInstructionSet`, then republish unchanged | — | rebuilt, then skipped | | Invalid `PublishReadyToRunInstructionSet` | — | crossgen2 reports the invalid instruction set | I did not build a WASI or browser CoreCLR app. The hook scenario above uses a hook declared in `Directory.Build.targets`. ## dotnet/sdk The SDK has the same targets in `src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.CrossGen.targets`. The equivalent change is in dotnet/sdk#57127. It also hashes `PublishReadyToRunCrossgen2CompositeExtraArgs`, which only exists there, and adds a ReadyToRun publish test that changing the crossgen2 arguments recompiles. Relates to #137112 (review comments: #137112 (comment), #137112 (comment)) > [!NOTE] > This PR description was generated with GitHub Copilot. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enables wasm relaxed SIMD by default on WASI for both CoreCLR ReadyToRun and NativeAOT. Browser stays opt-in, and Mono is unchanged.
PublishReadyToRunInstructionSet=-relaxed-simdIlcInstructionSet=-relaxed-simdPublishReadyToRunInstructionSet=relaxed-simdInstruction sets come from the compiler
InstructionSetHelpersaddsrelaxed-simdto the default instruction sets for wasm32 WASI, so crossgen2 and ILC both pick it up without callers passing anything.PublishReadyToRunInstructionSet. A general crossgen2 property that maps to--instruction-set:and accepts+x/-xrelative to the defaults, likeIlcInstructionSetfor NativeAOT. It replaces the browser-onlyWasmEnableRelaxedSimd, which only fed the same crossgen2 switch plus native flags no runtime code needed (-mrelaxed-simd, a relink trigger and a workload requirement). wasm-opt now always enables relaxed SIMD, so the ReadyToRun wasm-opt pass accepts relaxed images.Microsoft.NET.CrossGen.targetsis shared with dotnet/sdk, so a matching sdk change will follow.System.Runtime.Intrinsics.Wasmtypes to instruction sets, and the JIT treats wasm ISA support as exact under the NativeAOT ABI, soIsSupportedis a compile-time constant.SupportsWasmIntrinsicsis now true for every wasm CoreLib, and relaxed SIMD for every non-Mono one.WasiEnableCompositeR2Rremoved. WASI R2R already requiresPublishReadyToRunComposite=true, so the host link flags depend only onPublishReadyToRun.IsSupportedon CoreCLR. The JIT and interpreter decide support per method, so folding could make interpreted code take an intrinsic path and throw. Measured on a trimmed WASI R2R app it saved about 2.7 KB of R2R code (6 KB of IL). The substitutions remain for Mono only.PublishReadyToRunInstructionSet, so changing it recompiles CoreLib. Changing crossgen2 arguments doesn't recompile app images on any target; Recompile ReadyToRun images when the crossgen2 arguments change #137563 fixes that in the common crossgen2 targets.PublishReadyToRunInstructionSetyet (ReadyToRun: recompile when crossgen2 arguments change; map PublishReadyToRunInstructionSet sdk#57127). Until it flows, the browser opt-in and the WASI opt-out are no-ops in app publishes, andWasmSIMDTests.PublishRelaxedSimdEnabledCoreClris disabled against [wasm] The SDK's crossgen2 targets ignore PublishReadyToRunInstructionSet #137571. In-repo builds (CoreLib, runtime tests) use the runtime's copy and already honor it.simd128remains required on wasm; #137553 tracks making that explicit by folding it intobase.Trade-offs of the WASI default
Tests
hardware-intrinsics-wasmpipeline. The browser leg now really enables relaxed SIMD; before, the property was never forwarded. A new WASI leg usesWholeProgramCompositeBuildMode, which compiles CoreLib into each test composite.PackedSimdTestsstay quarantined there.System.Runtime.Intrinsics.Testsnow builds for WASI, and thePackedSimd/RelaxedSimdtests run on browser and WASI.PublishRelaxedSimdCoreClrpublishes R2R, runs relaxed operations when enabled, and expectsPlatformNotSupportedExceptionwhen disabled.Validation (local, wasmtime 49.0.1)
HardwareIntrinsics_Wasm_r. Whole-program mode with relaxed SIMD: 73 passed, 1 skipped (the test that expects relaxed SIMD to be unsupported). Default mode: 72 passed, 2 skipped (the [wasi][R2R] Runtime tests run R2R code against an interpreted CoreLib #134949 quarantines).HardwareIntrinsics_Wasm_r. Default: 73 passed, 1 skipped, and the module is rejected under-W relaxed-simd=n. WithIlcInstructionSet=-relaxed-simd: all 74 pass under-W relaxed-simd=n. The NativeAOT WASI CI leg only builds, so these runs are local only.System.Runtime.Intrinsics.Testson WASI. Trimmed R2R: 13,340 passed. Interpreter: 13,296 passed. Opt-out: 53 of 53 passed.Relates to #130223, #134949, #137553
Note
This PR description was generated with GitHub Copilot.