-
Notifications
You must be signed in to change notification settings - Fork 792
OptimizeInstructions: Eq64 of 0 => Eqz64 #2421
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
Conversation
@@ -1312,6 +1312,8 @@ struct OptimizeInstructions | |||
!EffectAnalyzer(getPassOptions(), binary->left) | |||
.hasSideEffects()) { | |||
return binary->right; | |||
} else if (binary->op == EqInt64) { | |||
return Builder(*getModule()).makeUnary(EqZInt64, binary->left); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this optimization done for i32.eqz
? I would expect this optimization to be organized to be symmetrically located with the i32
version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other one appears to be here:
binaryen/src/passes/OptimizeInstructions.cpp
Line 373 in 7fa8c78
if (binary->op == EqInt32 && c->value.geti32() == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is not structured in a very symmetrical way atm. It grew organically + some thoughts about checking common patterns early. So i32.eqz is much more common than i64.eqz, and hence they are differently located. It's very possible that's not worth it, and this should be refactored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, LGTM for now.
(local.get $0) | ||
(i64.const 0) | ||
(i32.eqz | ||
(i64.eqz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems i32.eqz i64.eqz
could be eliminate at all for CFG operands
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "CFG" here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant arguments for control operations like if (i64)
but I forgot that if
should be accept only i32
input argument, so series of eqz
may be better than i64.ne
+ i64.const 0
Fixes #2417
cc @dcodeIO