SimplifyLocals causes ineffective code
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- wasm
- Domain
- compilers
Research direction
Reproduce the example with wasm-opt using -O3 and -O3 -sp=simplify-locals, then inspect the simplify-locals entry point and the subsequent condition optimization. Compare the generated WebAssembly for the two runs. Done means the missed optimization is addressed without incorrectly removing reachable behavior, with a regression test for this input.
Written by the indexing model from the issue text.
Description
Given the following code:
(module
(type (;0;) (func))
(import "External" "external_function" (func $external_function (type 0)))
(func $_start (type 0)
i32.const 9576
i32.load
i32.load
i32.load
drop
i32.const 9576
i32.load
i32.load
i32.load
i32.const 9576
i32.load
i32.load
i32.load
i32.gt_s
if (result i32) ;; label = @1
call $external_function
i32.const 1
else
i32.const 0
end
drop
unreachable)
(memory $0 258 258)
(export "_start" (func $_start)))
For wasm-opt (c91c0520a61), -O3 -sp=simplify-locals can eliminate the unreachable code, while -O3 cannot:
(func $_start
(local $0 i32)
(if
(i32.gt_s
(local.tee $0
(i32.load
(i32.load
(i32.load
(i32.const 9576)
)
)
)
)
(local.get $0)
)
(then
(call $external_function)
)
)
(unreachable)
)
After investigating, it is the Wasm-specific optimization simplify-locals causes the counter-intuitive code. Below is the change made by simplify-locals:
As you can see, the currently wasm-opt cannot optimize the if condition on the right---it can only do that on the left, which I think it is missed optimization (It is not the simplify-locals fault...).
- Dominant language
- WebAssembly
- Stars
- 8.6k
- Forks
- 885
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 77
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.
More from WebAssembly/binaryen
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
WebAssembly/binaryen#9135 · 1 comment ·
-
Difficulty 2/5 Half a day Newbie friendliness 76/100
WebAssembly/binaryen#9018 · 3 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
WebAssembly/binaryen#9133 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
WebAssembly/binaryen#9123 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
WebAssembly/binaryen#9122 ·
All issues in WebAssembly/binaryen
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
internal.h中,漏掉了1个定义。 Open
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
oxc-project/oxc#26944 ·