llvm / llvm/llvm-project

missing offset folding in WASM load/store

Open
#187,367 8 comments 0 reactions 0 assignees View on GitHub
backend:WebAssembly missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

WebAssembly backend fails to fold constant GEP offsets into load/store offset parameters when the base pointer comes from a GEP instruction with a variable index in a loop context.

The minimal reproducer [here](https://github.com/lvella/llvm-unopt) is expected to generate, among other instances:
```wasm
...
local.get 1
i64.load offset=8
i64.store offset=2576
```
but instead it generates
```wasm
...
i32.const 2576
i32.add
local.get 1
i32.const 8
i32.add
i64.load
i64.store
```

Contributor guide

Open the contributing guide

Research direction

Start with the minimal reproducer at https://github.com/lvella/llvm-unopt and inspect the WebAssembly backend path that lowers load/store operations when the base pointer comes from a variable-index GEP in a loop. Compare the generated WebAssembly with the expected offset parameters; done means the constant offsets are folded into the load/store instructions rather than emitted as separate additions.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.