RemoveUnusedBrs fails to optimize control flow based dead code
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- wasm
- Domain
- compilers
Research direction
Start with the RemoveUnusedBrs optimization and reproduce the supplied WebAssembly case using wasm-opt version 2b989ae at O2 and O3. Compare the resulting control flow with the expected O2 output; done means O3 also eliminates the unreachable branch body and following dead calls as shown.
Written by the indexing model from the issue text.
Description
Given the following code:
(module
(import "env" "dead" (func $dead))
(func $_start (param $0 i32)
i32.const 0
i32.const 0
call $main)
(func $main (param $0 i32) (param $1 i32)
block ;; label = @1
i32.const 0
i32.const 0
i32.store
i32.const 0
i32.load
local.set $1
i32.const 1
local.set $0
local.get $1
br_if 0 (;@1;)
i32.const 0
i32.const 0
i32.store
i32.const 1
local.set $0
local.get $0
br_if 0 (;@1;)
i32.const 0
local.set $0
end
local.get $0
if ;; label = @1
unreachable
end
call $dead
call $dead
call $dead
)
(memory 1)
(export "_start" (func $_start)))
wasm-opt version: 2b989ae
O2 can eliminate the dead code because it identifies the statements of if unreachable:
(func $_start (param $0 i32)
(i32.store
(i32.const 0)
(i32.const 0)
)
(if
(i32.eqz
(i32.load
(i32.const 0)
)
)
(then
(i32.store
(i32.const 0)
(i32.const 0)
)
)
)
(unreachable)
)
O3 cannot:
(func $_start (param $0 i32)
(if
(block $block (result i32)
(i32.store
(i32.const 0)
(i32.const 0)
)
(drop
(br_if $block
(i32.const 1)
(i32.load
(i32.const 0)
)
)
)
(i32.store
(i32.const 0)
(i32.const 0)
)
(i32.const 1)
)
(then
(unreachable)
)
)
(call $dead)
(call $dead)
(call $dead)
)
- 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 ·