Skip to content

Implement more cases for "combine or" in OptimizeInstruction pass #2863

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

MaxGraey
Copy link
Contributor

@MaxGraey MaxGraey commented May 21, 2020

Added more peephole optimizations for "combine or"

  • (x <=> y) | (x == y)x <=> y
  • (x < y) | (x > y)x != y
  • (x == y) | (x != y)1
  • (x != y) | (x == y)1
  • (x <= y) | (x > y)1
  • (x < y) | (x >= y)1
  • (x >= y) | (x <= y)1
  • (x > y) | (x <= y)1
  • (x >= y) | (x < y)1

relate to #1764

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these optimizations could be much simpler to write if we had some nice template magic to abstract over the signedness and size of operations. Perhaps it's worth doing some up-front investment in that area?

Comment on lines 1264 to 1265
default: {
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this empty default case (or the ones below) should be necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this I can't compile due to -Werror,-Wswitch. But I'll use default: break instead

// (x <= y) | (x == y) ==> x <= y
// (x > y) | (x < y) ==> x != y
// (x != y) | (x == y) ==> 1
// (x >= y) | (x <= y) ==> 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are the left-side >= expressions handled? I don't see those cases below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the tests didn't need updating, but I see a few examples in the tests with i32.ge_s on the left hand side. Were they somehow being handled already by previous code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess it swapped (canonize) by code earlier:

if (Properties::isSymmetric(binary)) {
  canonicalize(binary);
}

here: https://github.com/WebAssembly/binaryen/blob/master/src/passes/OptimizeInstructions.cpp#L348

@MaxGraey
Copy link
Contributor Author

MaxGraey commented Jun 2, 2020

I think these optimizations could be much simpler to write if we had some nice template magic to abstract over the signedness and size of operations. Perhaps it's worth doing some up-front investment in that area?

Unfortunately in this case we can't use switch/case any more what could make stuffs more complicate for readability. Also such switch cases pretty fast in term of performance. Also I thought how we could automatize some pattern matching but if we will use de-morgan's laws it cover just minor part of x < y | x >= y and tree similar patterns and that's it. So I guess current solution near to optimal

@MaxGraey MaxGraey requested a review from kripken June 4, 2020 13:09
Base automatically changed from master to main January 19, 2021 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants