Repository navigation
Raise MAX_SPLITS_PER_SPILLSET from 2 to 4 - #269
Closed
EvanCarroll wants to merge 1 commit into
Closed
EvanCarroll wants to merge 1 commit into
EvanCarroll wants to merge 1 commit into
Conversation
With a limit of 2, a bundle that spans a loop containing calls on x64, where every vector register is a clobber, is split twice and then falls back to `split_into_minimal_bundles`. That puts every gap between uses in the spill bundle, and the spill bundle crosses the calls, so it is given a stack slot: an accumulator updated in a call-free inner loop is then loaded and stored on every iteration. Allowing four splits keeps such values in registers in the inner loop, while still bounding the cost on inputs that need O(|bundle|) splits, which is what the fallback was added for in bytecodealliance#59.
Author
|
This PR is not good. I either need to find out why this patch works so well in my use case. Or find out why it fails so badly in the other code here. For those reasons for the time being, I'm withdrawing, but I do think the bug report is solid. |
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.
Raise MAX_SPLITS_PER_SPILLSET from 2 to 4
Fixes #268.
With a limit of 2, a bundle that spans a loop containing calls on x64, where
every vector register is a clobber, is split twice and then reduced to minimal
bundles. All its gaps then live in a spill bundle that crosses the calls, so a
value updated in a call-free inner loop is loaded and stored every iteration.
Four splits are enough to keep it in a register, and the fallback still bounds
the cost on inputs needing O(|bundle|) splits, as intended in #59.
The constant gets a doc comment saying what it trades off.
Testing
cargo test: passes.cargo fuzz run ion(checker on), 10 minutes, 6 workers: about 138,600inputs, no failure.
Cranelift filetests with this patched in (
[patch.crates-io]in Wasmtimemain): all 1378 pass. 5precise-outputtests change, all x64:i128.clif,ishl.clif,sshr.clif,ushr.clifeach lose 2–4 lines (moves);fma-call.clifchanges register names only (21 lines for 21).No test gains a spill: there are 8 stack-referencing lines on each side of the
diff, all in
fma-call.clif.Wasmtime's SIMD spec tests (
cargo test --test wast -- simd): pass.Measurements
i7-1165G7, 8 cores, Linux; Wasmtime
main(dcfbea188d) built with regalloc20.15.2 at limit 2 against limit 4, everything else equal.
The function from the issue: the inner-loop spill disappears and the
function's stack references drop from 171 to 99. The kernel is 3–12% faster
(table in the issue).
Known pathological inputs: compile time and peak RSS,
wasmtime compilepinned to one core, three runs each:
extract.wasmexample.wasmCompile time: Sightglass,
--measure callgrind, compilation phase, oneiteration per engine. Instruction counts are deterministic: two runs of bz2 agree
to 0.001%.
default.suite+ bz2, pulldown-cmark, spidermonkey-json, blake3-simd)The known pathological inputs,
wasmtime compile -C parallel-compilation=nundercallgrind: bytecodealliance/wasmtime#4291
extract.wasm4,723.7 M → 4,716.4 Minstructions (−0.15%); #218
example.wasm4,612.4 M → 4,647.7 M (+0.77%). So thelimit stays a bound: neither case gets anywhere near the 10× blow-up the fallback
exists to prevent.
All 33 benchmarks
Execution: Sightglass cycles,
--pin, on a machine that was not quiet:default.suite(29 benchmarks, 5 iterations), bz2/pulldown-cmark/spidermonkey-json(10) and blake3-simd/hex-simd/intgemm-simd (20) show no significant difference in
execution geomean. The only significant per-benchmark result is
hashset, fasterwith limit 4 (1.01×–1.35×, p = 0.008). With per-benchmark noise of up to ±20%,
these runs only rule out large execution changes.
So the trade is a small, measurable compile-time cost (+0.40% geomean, +3.56%
worst) for keeping long-lived values in registers in call-free loops (3–12% on the
kernel in the issue). Whether that is the right balance is a judgment for the
maintainers; 3 does not fix the issue's function, 4 is the smallest value that does.