abrown opened issue #3106:
Feature
In certain cases, the Wasm-to-CLIF translation loses track of the alignment of loads. In the snippet below, we 1) know that loading the heap offset from
v0(i.e.,VMContext) is aligned, 2) could assume that the heap is aligned, and 3) see that an aligned heap address plus 16 is still aligned for thei8x16type:@004b v3 = iconst.i32 16 @004d v7 = uextend.i64 v3 @004d v8 = load.i64 notrap aligned readonly v0 @004d v4 = iadd v8, v7 @004d v5 = load.i8x16 little v4 @0051 v6 = bxor v2, v5Benefit
#2943 discovered a bug with load-coalescing SIMD operations: they can only be coalesced when the load is aligned. Implementing this feature would allow load-coalescing in more situations.
There may be other benefits of keeping track of load/store alignment. This all seems closely related to constant propagation so perhaps a solution there would also solve this issue.
Implementation
It does not seem impossible to detect the following Wasm pattern and combine it into a "load with offset:"
....load (i32.const ...) (...)This could be done in the Wasm-to-CLIF translator (if it isn't already) or in a separate CLIF pass.
Alternatives
Do nothing.
abrown commented on issue #3106:
See @cfallin's comments at https://github.com/bytecodealliance/wasmtime/pull/3107#pullrequestreview-715145673: one alternative is to thread alignment hints through CLIF so that we can catch the error and jump to a non-coalesced snippet.
abrown labeled issue #3106:
Feature
In certain cases, the Wasm-to-CLIF translation loses track of the alignment of loads. In the snippet below, we 1) know that loading the heap offset from
v0(i.e.,VMContext) is aligned, 2) could assume that the heap is aligned, and 3) see that an aligned heap address plus 16 is still aligned for thei8x16type:@004b v3 = iconst.i32 16 @004d v7 = uextend.i64 v3 @004d v8 = load.i64 notrap aligned readonly v0 @004d v4 = iadd v8, v7 @004d v5 = load.i8x16 little v4 @0051 v6 = bxor v2, v5Benefit
#2943 discovered a bug with load-coalescing SIMD operations: they can only be coalesced when the load is aligned. Implementing this feature would allow load-coalescing in more situations.
There may be other benefits of keeping track of load/store alignment. This all seems closely related to constant propagation so perhaps a solution there would also solve this issue.
Implementation
It does not seem impossible to detect the following Wasm pattern and combine it into a "load with offset:"
....load (i32.const ...) (...)This could be done in the Wasm-to-CLIF translator (if it isn't already) or in a separate CLIF pass.
Alternatives
Do nothing.
Last updated: Dec 06 2025 at 06:05 UTC