-
Notifications
You must be signed in to change notification settings - Fork 786
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
base: main
Are you sure you want to change the base?
Conversation
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 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?
src/passes/OptimizeInstructions.cpp
Outdated
default: { | ||
} |
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 don't think this empty default case (or the ones below) should be necessary.
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.
Without this I can't compile due to -Werror,-Wswitch
. But I'll use default: break
instead
src/passes/OptimizeInstructions.cpp
Outdated
// (x <= y) | (x == y) ==> x <= y | ||
// (x > y) | (x < y) ==> x != y | ||
// (x != y) | (x == y) ==> 1 | ||
// (x >= y) | (x <= y) ==> 1 |
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.
How are the left-side >=
expressions handled? I don't see those cases below.
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.
Added
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 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?
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.
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
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 |
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