-
Notifications
You must be signed in to change notification settings - Fork 777
[Unhoisted] [Binary] [Should fallthrough] load & store order affects the constant propagation in binaryOp #7455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Simplified: (module
(import "External" "external_function" (func $external_function))
(memory $0 258 258)
(export "_start" (func $_start))
(func $_start (param $0 i32)
(if
(i32.lt_u
(i32.load
(i32.const 0)
)
(block (result i32)
(i32.store
(i32.const 0)
(i32.const 0)
)
(i32.const 0)
)
)
(then
(call $external_function)
)
)
)
) This code is normally optimized by OptimizeInstructions could handle this even with the store in place, but we would need to use |
Got it, that is the limitation of the binaryen/src/passes/OptimizeInstructions.cpp Lines 2865 to 2867 in d0d970c
|
Yes, I think that might be the relevant TODO. We need to look at the fallthrough, and then keep dropped children as needed. |
Given the following code:
The wasm-opt (16dbac1) can eliminate the dead true branch by
-all -O2
but cannot by-all -O3
.Analysis
O2 produces the following if statement before
inlining-optimizing
:After inline, the condition is deduced to be zero, thus the true branch is deleted (
call $external_function
is in the true branch). (Of course it preserves the side-effect statements in the branch)O3 produces the following if statement before
inlining-optimizing
:After inline, the condition is transformed to
As you can see, the condition is almost the same as O2 produced before
inlining-optimizing
. However,wasm-opt
failed to deduced the condition to be zero after inline -- It should be.The only difference is the O2 uses
gt_u
and the O3 useslt_u
. Maybe the reorder of the comparison operands affects the optimization? So weird. (I am not sure about that).Overall, I think there is a missed optimization in the
updateAfterInlining
-- wasm-opt may not handle constant propagation properly after inlining. (Similar to the #7454 )The text was updated successfully, but these errors were encountered: