Skip to content

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

Merged
merged 3 commits into from
Nov 4, 2019
Merged

OptimizeInstructions: Eq64 of 0 => Eqz64 #2421

merged 3 commits into from
Nov 4, 2019

Conversation

kripken
Copy link
Member

@kripken kripken commented Nov 4, 2019

Fixes #2417

cc @dcodeIO

@kripken kripken requested a review from tlively November 4, 2019 21:46
@@ -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);
Copy link
Member

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.

Copy link
Contributor

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:

if (binary->op == EqInt32 && c->value.geti32() == 0) {
also handling various sign extension cases, which made me shy away from a quick fix as it seems there's more to it.

Copy link
Member Author

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.

Copy link
Member

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
Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Contributor

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

@kripken kripken merged commit 74526f3 into master Nov 4, 2019
@kripken kripken deleted the eqz64 branch November 4, 2019 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OptimizeInstructions and i64
4 participants