-
Notifications
You must be signed in to change notification settings - Fork 778
O3 fails to const propagation & folding but O2 can #7481
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
I don't think the fallthrough is needed here. (if
(i32.and
(i32.eqz
(i32.load
(i32.const 0)
)
)
(i32.const 4)
) That is false because eqz returns at most one bit, and I believe this is the right area in OptimizeInstructions to add such an optimization, either right before or after these: binaryen/src/passes/OptimizeInstructions.cpp Lines 4667 to 4673 in 93c541d
|
I understand what you mean, that is:
if (curr->op == Abstract::getBinary(type, And)) {
if (leftMaxBits == 1) {
// boolean & (No overlap with boolean's LSB) ==> 0
if (auto* c = curr->right->dynCast<Const>()) {
if ((1 & c->value.getInteger()) == 0) {
replaceCurrent(getDroppedChildrenAndAppend(
curr, LiteralUtils::makeZero(c->value.type, *getModule())));
}
}
}
} However, I am afraid that (i32.and
(i32.eqz
(i32.load $0
(i32.const 0)
)
)
(i32.const 4)
) ( Should we make the |
Good point, I didn't notice that that was inside Adding it alongside other And-related rules would make more sense. Probably near the end of |
Given the following code:
wasm-opt can deduce the condition of the
br_if
to be true by-all -O2
but cannot by-all -O3
.Analysis
The following is result of
-all -O3
:The condition above is not deduced to zero, but it should be. This issue is somewhat similar to #7455. However, we may not be able to use
fallthrough
to optimizex && 0 ==> 0
, as thefallthrough
property doesn't deduce the value of:to
This is problematic. Is there any other ways to resolve it?
The text was updated successfully, but these errors were encountered: