Stream: git-wasmtime

Topic: wasmtime / issue #3106 x64: propagate alignment of loads ...


view this post on Zulip Wasmtime GitHub notifications bot (Jul 21 2021 at 18:36):

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 the i8x16 type:

@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, v5

Benefit

#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.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 26 2021 at 20:38):

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.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 03 2021 at 23:50):

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 the i8x16 type:

@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, v5

Benefit

#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: Nov 22 2024 at 17:03 UTC