bytecodealliance / bytecodealliance/wasmtime

x64: propagate alignment of loads with offsets

Open
#3,106 1 comment 0 reactions 0 assignees View on GitHub
cranelift:area:x64
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.