WebAssembly / WebAssembly/binaryen
SIMD add not being optimized away
Nobody has claimed this yet.
- Dominant language
- WebAssembly
- Stars
- 8.6k
- Forks
- 885
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 69
Description
The i64x2.add in the following WAT isn't being optimized at all (build/bin/wasm-opt --enable-simd -O3 -S -o - test.wat):
(module
(export "v128-add" (func $v128-add))
(export "i64-add" (func $i64-add))
(func $v128-add (param v128) (result v128)
(i64x2.add (local.get 0) (v128.const i64x2 0 0))
)
(func $i64-add (param i64) (result i64)
(i64.add (local.get 0) (i64.const 0))
)
)
It outputs:
(module
(type $v128_=>_v128 (func (param v128) (result v128)))
(type $i64_=>_i64 (func (param i64) (result i64)))
(export "v128-add" (func $v128-add))
(export "i64-add" (func $i64-add))
(func $v128-add (; has Stack IR ;) (param $0 v128) (result v128)
(i64x2.add
(local.get $0)
(v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000)
)
)
(func $i64-add (; has Stack IR ;) (param $0 i64) (result i64)
(local.get $0)
)
)
I'd have expected that add to be optimized away into (local.get $0). How do I get that to work?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied WAT reproducer with build/bin/wasm-opt --enable-simd -O3 -S and compare the i64x2.add result with the scalar i64.add result. Trace the SIMD optimization path responsible for constant-zero additions; done means the v128-add function is reduced to local.get $0 while the existing scalar behavior remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- wasm
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100