Stream: git-wasmtime

Topic: wasmtime / PR #15205 cranelift: preserve rematerializatio...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 16:01):

wraitii opened PR #15205 from wraitii:fix/egraph-cloned-remat to bytecodealliance:main:

Egraph elaboration can clone instructions when placing them in separate dominance scopes, including when LICM hoists constants. These clones receive new value IDs that the rematerialization set does not recognize, potentially extending live ranges and increasing register pressure.

Check rematerialization eligibility through the existing value_to_best_value mapping so clones retain the original value’s eligibility.

Add regression coverage for a cloned constant hoisted out of a loop and a cloned non-constant instruction without loops. Both cases fail before the fix.

Validation: 82 egraph test files and 216 codegen unit tests pass.


PR written by GPT 6.1 sol following investigation by Opus 5.5 . Leads to obvious incorrect spilling of constants in a JS JIT I'm working on. As with my earlier PRs, I've spot-checked that the diff looks correct for what the AIs report the problem is, but I cannot really confirm that this is the minimal or cleanest fix, feel free to pong back.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 16:01):

wraitii removed the review request for wasmtime-compiler-reviewers from PR #15205.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 16:01):

wraitii requested alexcrichton for a review on PR #15205.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 16:01):

wraitii requested wasmtime-compiler-reviewers for a review on PR #15205.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 16:11):

wraitii requested wasmtime-core-reviewers for a review on PR #15205.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 16:11):

wraitii updated PR #15205.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 16:13):

alexcrichton removed the review request for alexcrichton from PR #15205.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 16:13):

alexcrichton requested cfallin for a review on PR #15205.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 16:32):

wraitii commented on PR #15205:

Ran Sightglass, Apple Silicon M1 max: 29 workloads, 20 samples per engine.

A 50-sample follow-up confirmed:

Workload Change Codex explanation
shootout-switch compilation −68.8% time large switch with constants, this was hitting a worst-case in regalloc
TinyGo regex execution −2.8%
heapsort execution −1.8%
libsodium-hash3 execution +3.7% more instructions in the inner loop (in printf, it seems)
hex-simd execution +4.8% more instructions in the inner loop (in the vector loop)

Those results read decently odd to me to be honest - i would have expected more functions with concrete wins, and the regressions might highlight unrelated issues. The compile-time win in shootout switch is pretty clear though.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 16:56):

wraitii edited a comment on PR #15205:

Ran Sightglass, Apple Silicon M1 max: 29 workloads, 20 samples per engine.

A 50-sample follow-up confirmed:

Workload Change Codex explanation
shootout-switch compilation −68.8% time large switch with constants, this was hitting a worst-case in regalloc
TinyGo regex execution −2.8%
heapsort execution −1.8%
libsodium-hash3 execution +3.7% more instructions in the inner loop
hex-simd execution +4.8% more instructions in the inner loop (in the vector loop)

Those results read decently odd to me to be honest - i would have expected more functions with concrete wins, and the regressions might highlight unrelated issues. The compile-time win in shootout switch is pretty clear though.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 16:57):

wraitii edited a comment on PR #15205:

Ran Sightglass, Apple Silicon M1 max: 29 workloads, 20 samples per engine.

A 50-sample follow-up confirmed:

Workload Change Codex explanation
shootout-switch compilation −68.8% time large switch with constants, this was hitting a worst-case in regalloc
TinyGo regex execution −2.8%
heapsort execution −1.8%
libsodium-hash3 execution +3.7% more instructions in the inner loop
hex-simd execution +4.8% more instructions in the inner loop (in the vector loop)

Those results read decently odd to me to be honest - i would have expected more functions with concrete wins, and the regressions might highlight unrelated issues. The compile-time win in shootout switch is pretty clear though.


Edit: ran more:

Workload Change
generichash +5.8%
kdf_hkdf +3.0%
auth +2.9%
hash +2.6%
Rust WAT parser −3.5%

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 17:07):

wraitii edited a comment on PR #15205:

Ran Sightglass, Apple Silicon M1 max: 29 workloads, 20 samples per engine.

A 50-sample follow-up confirmed:

Workload Change Codex explanation
shootout-switch compilation −68.8% time large switch with constants, this was hitting a worst-case in regalloc
TinyGo regex execution −2.8%
heapsort execution −1.8%
libsodium-hash3 execution +3.7% more instructions in the inner loop
hex-simd execution +4.8% more instructions in the inner loop (in the vector loop)

Those results read decently odd to me to be honest - i would have expected more functions with concrete wins, and the regressions might highlight unrelated issues. The compile-time win in shootout switch is pretty clear though.


Edit: ran more:

Workload | Change |
-- | -- | --
generichash | +5.8% | Cause is apparently the hex decoder: masks & arithmetics repeats more.
kdf_hkdf | +3.0% |
auth | +2.9% |
hash | +2.6% |
Rust WAT parser | −3.5% |

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 17:08):

wraitii edited a comment on PR #15205:

Ran Sightglass, Apple Silicon M1 max: 29 workloads, 20 samples per engine.

A 50-sample follow-up confirmed:

Workload Change Codex explanation
shootout-switch compilation −68.8% time large switch with constants, this was hitting a worst-case in regalloc
TinyGo regex execution −2.8%
heapsort execution −1.8%
libsodium-hash3 execution +3.7% more instructions in the inner loop
hex-simd execution +4.8% more instructions in the inner loop (in the vector loop)

Those results read decently odd to me to be honest - i would have expected more functions with concrete wins, and the regressions might highlight unrelated issues. The compile-time win in shootout switch is pretty clear though.


Edit: ran more:

Workload Change Notes
generichash +5.8% Likely caused by the hex decoder: masks and arithmetic operations are repeated more frequently.
kdf_hkdf +3.0%  
auth +2.9%  
hash +2.6%  
Rust WAT parser −3.5%

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 17:09):

wraitii edited a comment on PR #15205:

Ran Sightglass, Apple Silicon M1 max: 29 workloads, 20 samples per engine.

A 50-sample follow-up confirmed:

Workload Change Codex explanation
shootout-switch compilation −68.8% time large switch with constants, this was hitting a worst-case in regalloc
TinyGo regex execution −2.8%
heapsort execution −1.8%
libsodium-hash3 execution +3.7% more instructions in the inner loop
hex-simd execution +4.8% more instructions in the inner loop (in the vector loop)

Those results read decently odd to me to be honest - i would have expected more functions with concrete wins, and the regressions might highlight unrelated issues. The compile-time win in shootout switch is pretty clear though.

Codex attributes this to rematierialization for constant-operand integer ALU operations.


Edit: ran more:

Workload Change Notes
generichash +5.8% Likely caused by the hex decoder: masks and arithmetic operations are repeated more frequently.
kdf_hkdf +3.0%  
auth +2.9%  
hash +2.6%  
Rust WAT parser −3.5%

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 17:15):

wraitii edited a comment on PR #15205:

Ran Sightglass, Apple Silicon M1 max: 29 workloads, 20 samples per engine.

A 50-sample follow-up confirmed:

Workload Change Codex explanation
shootout-switch compilation −68.8% time large switch with constants, this was hitting a worst-case in regalloc
TinyGo regex execution −2.8%
heapsort execution −1.8%
libsodium-hash3 execution +3.7% more instructions in the inner loop
hex-simd execution +4.8% more instructions in the inner loop (in the vector loop)

Edit: ran more:

Workload Change Notes
generichash +5.8% constant integer operations are repeated in the inner loop un-necessarily.
kdf_hkdf +3.0%
auth +2.9%
hash +2.6%  
Rust WAT parser −3.5%

After some digging, it seems the culprit is that these now rematerialize constant-operand ALU operations, like "val & 255" & the like, when this seems un-necessary, as the original constants can stay in registers across the loop. This feels like it should be decided at the register-level, or cleaned-up afterwards.
Unfortunately seems like a decently real regression in some cases then. Could be limited to actual constants, where it's less likely to perform poorly.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 17:36):

wraitii edited a comment on PR #15205:

Ran Sightglass, Apple Silicon M1 max: 29 workloads, 20 samples per engine.

A 50-sample follow-up confirmed:

Workload Change Codex explanation
shootout-switch compilation −68.8% time large switch with constants, this was hitting a worst-case in regalloc
TinyGo regex execution −2.8%
heapsort execution −1.8%
libsodium-hash3 execution +3.7% more instructions in the inner loop
hex-simd execution +4.8% more instructions in the inner loop (in the vector loop)

Edit: ran more:

Workload Change Notes
generichash +5.8% constant integer operations are repeated in the inner loop un-necessarily.
kdf_hkdf +3.0%
auth +2.9%
hash +2.6%  
Rust WAT parser −3.5%

After some digging, it seems the culprit is that these now rematerialize constant-operand ALU operations, like "val & 255" & the like, when this seems un-necessary, as the original constants can stay in registers across the loop. This feels like it should be decided at the register-level, or cleaned-up afterwards.
Unfortunately seems like a decently real regression in some cases then. Could be limited to actual constants, where it's less likely to perform poorly.


Edit 2: Ok, so disabling ALU rematerialization entirely seems slightly faster than stock on these workflows. essentially, all of the above table shows ALU remat cost, not constants, which simply don't seem to appear in the Sightglass tests

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 18:08):

cfallin commented on PR #15205:

Thanks! The change itself does-what-it-says-on-the-tin, and looks correct to me. I'm somewhat confused by the ad-hoc benchmark result presentation here though -- would you mind running the full suite, and showing effects on compile time and run-time separately?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 18:41):

wraitii commented on PR #15205:

Ran the default suite with default settings (took ~15 minutes on my machine):
fullsuite-res.txt

The difference _mostly_ seems to come down to constant-op ALU operations that get un-necessarily rematerialized inside loops when their results can be held in register across the loop.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 18:45):

wraitii edited a comment on PR #15205:

Ran the default suite with default settings (took ~15 minutes on my machine):
fullsuite-res.txt

The slowdown cases _mostly_ seems to come down to constant-op ALU operations that get un-necessarily rematerialized inside loops when their results can be held in register across the loop.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 19:13):

wraitii updated PR #15205.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 20:24):

cfallin commented on PR #15205:

OK, thanks -- the signal seems almost entirely positive in those results so I think that plus the theory-of-operation argument (that this is an improvement / alignment with how things should work) make a good argument for merging this. So I'll do so -- thanks!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 20:24):

:thumbs_up: cfallin submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 20:24):

cfallin added PR #15205 cranelift: preserve rematerialization for cloned egraph values to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 20:47):

:check: cfallin merged PR #15205.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 09 2026 at 20:47):

cfallin removed PR #15205 cranelift: preserve rematerialization for cloned egraph values from the merge queue.


Last updated: Nov 19 2026 at 20:05 UTC