Repository navigation
Recompile ReadyToRun images when the crossgen2 arguments change - #137563
Merged
lewing merged 3 commits intoNov 18, 2026
Merged
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/crossgen-contrib |
jkotas
reviewed
Nov 15, 2026
lewing
added a commit
that referenced
this pull request
Nov 15, 2026
…axed SIMD on for WASI (#137112) Enables wasm relaxed SIMD by default on WASI for both CoreCLR ReadyToRun and NativeAOT. Browser stays opt-in, and Mono is unchanged. | Target | Relaxed SIMD | Opt out / in | |---|---|---| | CoreCLR WASI (R2R) | On | `PublishReadyToRunInstructionSet=-relaxed-simd` | | NativeAOT WASI | On | `IlcInstructionSet=-relaxed-simd` | | CoreCLR browser (R2R) | Off | `PublishReadyToRunInstructionSet=relaxed-simd` | | Mono | Not implemented | — | ## Instruction sets come from the compiler - **WASI default.** `InstructionSetHelpers` adds `relaxed-simd` to 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`/`-x` relative to the defaults, like `IlcInstructionSet` for NativeAOT. It replaces the browser-only `WasmEnableRelaxedSimd`, 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.targets` is shared with dotnet/sdk, so a matching sdk change will follow. - **Images are checked against CoreLib.** Wasm has no runtime ISA detection. The runtime now adopts the instruction sets CoreLib's R2R image was compiled for, and every other image is checked against them; a mismatch is rejected like on other platforms. This removes the browserhost hook that set the flag from a runtime config property. - **NativeAOT.** NativeAOT's CoreLib now compiles the wasm intrinsics. ILC maps `System.Runtime.Intrinsics.Wasm` types to instruction sets, and the JIT treats wasm ISA support as exact under the NativeAOT ABI, so `IsSupported` is a compile-time constant. `SupportsWasmIntrinsics` is now true for every wasm CoreLib, and relaxed SIMD for every non-Mono one. - **`WasiEnableCompositeR2R` removed.** WASI R2R already requires `PublishReadyToRunComposite=true`, so the host link flags depend only on `PublishReadyToRun`. - **No trimmer folding of `IsSupported` on 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. - **Incremental publish.** CoreLib's crossgen step records `PublishReadyToRunInstructionSet`, so changing it recompiles CoreLib. Changing crossgen2 arguments doesn't recompile app images on any target; #137563 fixes that in the common crossgen2 targets. `simd128` remains required on wasm; #137553 tracks making that explicit by folding it into `base`. ## Trade-offs of the WASI default - There's no runtime feature detection, so a host without relaxed SIMD fails to load the module. Use the opt-out for such hosts. - Relaxed SIMD results can differ by host CPU. - The pinned wasmtime 49.0.1 enables relaxed SIMD by default. ## Tests - **`hardware-intrinsics-wasm` pipeline.** The browser leg now really enables relaxed SIMD; before, the property was never forwarded. A new WASI leg uses `WholeProgramCompositeBuildMode`, which compiles CoreLib into each test composite. - **Other WASI R2R runtime tests** run R2R code against an interpreted CoreLib (#134949), so they default to the baseline instruction sets, and two `PackedSimdTests` stay quarantined there. - **Library tests.** `System.Runtime.Intrinsics.Tests` now builds for WASI, and the `PackedSimd`/`RelaxedSimd` tests run on browser and WASI. - **Wasm.Build.Tests.** `PublishRelaxedSimdCoreClr` publishes R2R, runs relaxed operations when enabled, and expects `PlatformNotSupportedException` when disabled. ## Validation (local, wasmtime 49.0.1) - **CoreCLR WASI `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 #134949 quarantines). - **NativeAOT WASI `HardwareIntrinsics_Wasm_r`.** Default: 73 passed, 1 skipped, and the module is rejected under `-W relaxed-simd=n`. With `IlcInstructionSet=-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.Tests` on WASI.** Trimmed R2R: 13,340 passed. Interpreter: 13,296 passed. Opt-out: 53 of 53 passed. - **WASI app.** R2R default, opt-out, and non-R2R publishes all behave correctly. - **Browser** is covered by CI only. Relates to #130223, #134949, #137553 > [!NOTE] > This PR description was generated with GitHub Copilot. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
_CreateR2RImages only compared files, so an incremental publish that changed only the crossgen2 arguments (for example PublishReadyToRunCrossgen2ExtraArgs) kept the stale images. Each batch now also outputs a state file named after a hash of the arguments. Outputs is expanded after the targets that run before _CreateR2RImages, so arguments they add to _PublishReadyToRunCrossgen2ExtraArgs are included. The state file is written after every batch compiles. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Follow the established SDK pattern (for example CreateGeneratedAssemblyInfoInputsCacheFile): hash the arguments with the Hash task into a fixed cache file written only when it changes, and list it as an input of _CreateR2RImages. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
PublishReadyToRunCrossgen2ExtraArgs set with -p: is a global property, so appending to it at evaluation time was ignored and PublishReadyToRunInstructionSet was silently dropped. Pass it through an internal property consumed by both compiler invocations and the arguments cache hash. Mirrors dotnet/sdk@485b9063d4. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lewing
force-pushed
the
lewing-crossgen2-args-r2r-incrementality
branch
from
November 16, 2026 16:55
6df602e to
8fbf831
Compare
This was referenced Nov 17, 2026
Member
|
@jtschuster for visibility. |
davidwrighton
approved these changes
Nov 18, 2026
jtschuster
approved these changes
Nov 18, 2026
Member
Author
|
/ba-g mac timeout not related |
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.
_CreateR2RImagesonly 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 withavx512. 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 theHashtask to hash:PublishReadyToRunCrossgen2ExtraArgs_PublishReadyToRunCrossgen2ExtraArgsPublishReadyToRunInstructionSet(via_ReadyToRunInstructionSetArgs)PublishReadyToRunCompositePublishReadyToRunContainerFormatPublishReadyToRunUseCrossgen2PublishReadyToRunPerfmapFormatVersionIt writes the hash to
$(IntermediateOutputPath)$(MSBuildProjectName).ReadyToRunCompilerArguments.cacheonly when the hash changes._CreateR2RImageslists that file as an input, so changing any of these values makes every image out of date.Target ordering:
BeforeTargetshooks run in declaration order. The new target therefore sees arguments added by hooks declared earlier, including project andDirectory.Build.targetshooks. 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--directpinvokealready list their pinvoke manifests that way. The browser--partialPGO argument is tracked bybrowser-r2r-state.stamp, which is left unchanged; it also tracks the PGO file list and the wasm-opt post-processing state.PublishReadyToRunInstructionSetwith command-line extra args: #137112 appended--instruction-set:toPublishReadyToRunCrossgen2ExtraArgsat 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_ReadyToRunInstructionSetArgsproperty, which bothRunReadyToRunCompilercalls pass and the hash includes. This mirrors dotnet/sdk@485b9063d4.Validation
All runs used a
dotnet new consoleapp 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>:PublishReadyToRunCrossgen2ExtraArgs(--instruction-set:apple-m1→armv8.2-a)_CreateR2RImagesskipped (bug)_PublishReadyToRunCrossgen2ExtraArgsby aBeforeTargets="_CreateR2RImages"hook, then changedPublishReadyToRunComposite=true→false--bogus-option), republish, then revert to the earlier argsPublishReadyToRunInstructionSet=apple-m1with-p:PublishReadyToRunCrossgen2ExtraArgs=--Ot--instruction-setdropped (main's targets)PublishReadyToRunInstructionSet, then republish unchangedPublishReadyToRunInstructionSetI 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 hashesPublishReadyToRunCrossgen2CompositeExtraArgs, 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.