Repository navigation
JIT: use scalar stores for small wasm zero fills - #137234
Merged
Merged
Conversation
Replace constant zero fills of 1, 2, 4, or 8 bytes with scalar stores. Contain zero-valued initblk operands so codegen emits i64.const 0 directly for 8-byte stores. Contributes to dotnet#135985. Co-authored-by: Copilot <[email protected]> Copilot-Session: 1da7d7aa-79b4-4ae1-ae4a-9861fdf9681c
|
Azure Pipelines: Successfully started running 6 pipeline(s). 9 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: @JulieLeeMSFT, @jakobbotsch |
Member
Author
|
I recall there was some discussion about rewriting zero fills as a perf win; here it's just done as a small size win. @adamperlin PTAL |
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
davidwrighton
approved these changes
Nov 10, 2026
lewing
added a commit
that referenced
this pull request
Nov 14, 2026
<!-- --> Follow-up to #137234. `genWasmZeroInit` now emits `i32.const 0; i8x16.splat; v128.store` for constant 16-byte zero fills instead of `memory.fill`. This covers frame zero-init, constant localloc, native initblk and GC-ref zeroing. CoreCLR browser-wasm already requires SIMD. `i8x16.splat` is used rather than a zero `v128.const` because it is 14 bytes smaller per site (8 vs 22 bytes) and was never slower in the measurements below. It is 1 byte larger than the `memory.fill` sequence (7 bytes). ### Size In a composite R2R browser-wasm publish of a small test app (CoreLib + System.Console + app), 300 of 321 16-byte `memory.fill` sites (of 1,539 total `memory.fill`s) became `v128.store`. The composite image grew from 2,449,568 to 2,449,856 bytes (+288 B). ### Speed Pure-wasm microbenchmark, 16-byte zero fill, net ns per fill, Apple M5 Max: | Engine / tier | `memory.fill` | `i8x16.splat` + `v128.store` | `v128.const 0` + `v128.store` | |---|---:|---:|---:| | V8 Liftoff (`node --liftoff-only`) | 2.74 | 0.149 | 0.359 | | V8 TurboFan (`node --no-liftoff`) | 0.170 | 0.082 | 0.082 | | JSC BBQ (`jsc --useOMGJIT=false`) | 1.86 | 0.130 | 0.130 | | JSC default | 0.190 | 0.082 | 0.081 | Both baseline tiers compile `memory.fill` as an out-of-line call, so code that has not tiered up gains the most. V8's `--print-wasm-code` shows both v128 forms as a single `str q0` on arm64. Composite R2R browser-wasm app on node (best of 7 per run, 5 interleaved runs, ns/op). These loops run long enough to tier up: | Kernel | Base | This PR | Change | |---|---:|---:|---:| | `arr[i] = default` for 16-byte structs (two `long`s, four refs, `Guid`, `decimal`, mixed) | 0.386–0.392 | 0.308–0.310 | about -20% | | Prolog zeroing of a 16-byte struct local with refs | 4.075 | 3.922 | -3.8% (ranges overlap) | | `List<(string,string,string,string)>` Add/RemoveAt, `Dictionary<Guid,object>` set/remove, decimal math | | | within ±0.4% | The A/B used JITs built from the same commit, swapped into the same crossgen2 and runtime pack. Another build was running on the machine during part of the measurements. ### Validation - `./build.sh clr.crossarchtools -os browser -arch wasm -c Release /p:RuntimeFlavor=CoreCLR` passed at this commit. - `./build.sh clr.crossarchtools -os browser -arch wasm -c Checked /p:RuntimeFlavor=CoreCLR` passed at this commit. - `python3 src/coreclr/scripts/jitformat.py -a arm64 -o osx -r <repo>` passed with no changes. - With the same patch applied at `62278fed5a1`, the composite R2R publish (`PublishReadyToRun=true`, `PublishReadyToRunComposite=true`) compiled with no asserts under a Checked JIT. The resulting app ran with checksums matching the baseline. - SuperPMI, the runtime and library test suites, x64, and browsers other than node were not run. Contributes to #135985. > [!NOTE] > This PR description was generated with GitHub Copilot. Co-authored-by: Copilot App <[email protected]>
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.
Replace constant zero
memory.filloperations of 1, 2, 4, or 8 bytes with scalar stores. Share the selection across frame initialization, constant localloc, native initblk, and GC zeroing codegen.Contain zero-valued initblk operands during lowering so codegen emits the correctly typed zero directly, including
i64.const 0for eight-byte stores. Nonzero fills, dynamic fills, copy operations, and existing explicit null checks retain their current paths.Size
Havit composite R2R, compared with main at
e8b295c1ba0:SuperPMI: 38,469 successful contexts per JIT, none larger. No GC-info size or EH-clause-count changes. Code-size figures use successful compilation CSV metrics; the Wasm native differ has known decoder failures and false reports.
The comparison uses identical frozen compiler dependencies and existing local runtime packs, changing only the JIT. Compressed assets were verified to decompress byte-for-byte to their respective images. No runtime-speed improvement is claimed.
Validation
build.cmd clr.crossarchtools -os browser -arch wasm -c Release /p:RuntimeFlavor=CoreCLRpassed for the clean baseline and changed JIT.build.cmd clr.crossarchtools -os browser -arch wasm -c Checked /p:RuntimeFlavor=CoreCLRpassed for the changed JIT.STRESS_EMITTERfor Checked: 48 constant zero/nonzero fill sentinel cases, 30 frame/EH calls, two heap GC-ref zeroing cases, and existing throw-helper/EH, boolean, GC/liveness, and local-use controls.wasm-tools validate;jit-format --untidyandgit diff --checkpassed.Contributes to #135985.
Note
This PR description was generated with GitHub Copilot.