Closed
Description
Given the following code:
(module
(import "External" "external_function" (func $external_function))
(func $_start (result i32)
(local i32 i32 i32 i32 i32 i32 i32 i32 i32)
call $foo
local.set 1
i32.const 1
local.set 2
local.get 1
local.get 2
i32.and
local.set 3
i32.const -556321873
local.set 4
local.get 3
local.get 4
i32.ge_u
local.set 5
i32.const 0
i32.load
local.set 6
local.get 5
local.get 6
i32.and
local.set 7
i32.const 0
local.set 0
block ;; label = @1
local.get 7
i32.eqz
br_if 0 (;@1;)
call $external_function
i32.const 0
local.set 0
end
local.get 0
local.set 8
i32.const 0
local.get 8
i32.store
unreachable)
(func $foo (result i32)
i32.const 0
i32.const 0
i32.store8
i32.const 0)
(memory (;0;) 258 258)
(export "_start" (func $_start)))
wasm-opt (16dbac1) can eliminate the dead br_if
body by -all -O2
but cannot by -all -O3
.
Analysis
The most probable issue lies in the optimize-instructions pass:
- In O3,
optimize-instructions
fails to deduce the condition to zero:- While in O2, it successfully deduces the condition to zero.
- Additional DCE is performed in the
updateAfterInlining
ofinlining-optimizing
in O2.
- In O3, the condition is eventually reduced to zero after
inlining-optimizing
, but no further DCE (likevacuum
) is performed.- This makes the optimization too late compared to O2.
In short, there appears to be a missed optimization in optimize-instructions
for O3.
Metadata
Metadata
Assignees
Labels
No labels