-
Notifications
You must be signed in to change notification settings - Fork 776
OptimizeInstruction: Optimize any boolean & (No overlap with boolean's LSB) ==> 0 #7505
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
uint64_t constantValue = c->value.getInteger(); | ||
if ((constantValue & mask) == 0) { | ||
replaceCurrent(getDroppedChildrenAndAppend( | ||
curr, LiteralUtils::makeZero(type, *getModule()))); |
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.
For both the replaceCurrent()
calls in this function, the caller does that on the returned value, so we can just return the value here.
auto* right = curr->right; | ||
auto leftMaxBits = Bits::getMaxBits(left, this); | ||
|
||
if (leftMaxBits == 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.
Does 0 need to be special-cased? I think it can work without it (if not, a comment would help).
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.
Oh, also, the case of 0 & ..
should already be handled elsewhere, so we don't need to handle it here anyhow
;; CHECK-NEXT: (i32.and | ||
;; CHECK-NEXT: (i32.const 1) | ||
;; CHECK-NEXT: (i32.const 2) | ||
;; CHECK-NEXT: ) |
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 goal of this existing test is to see the order of the operands, so this optimization prevents the test from working. To avoid that, the test can be modified to check two different numbers, perhaps (does 2, 1 - reversing the order - work perhaps?)
;; CHECK-NEXT: (i32.const 127) | ||
;; CHECK-NEXT: (i32.const 128) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (i32.const 0) | ||
;; CHECK-NEXT: ) | ||
(func $sext-24-and-127-128 (result i32) | ||
(i32.shr_s |
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 goal in this test is to see that the sign-extend can be removed. If it optimizes all the way to 0, that isn't clear. Perhaps the constant 128 a few lines below can be replaced with a local.get
, so it is unknown?
;; CHECK-NEXT: (local.get $x) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (i32.const 2) | ||
;; CHECK-NEXT: ) |
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.
Perhaps the i64 2
could be an i64
param, to avoid this getting optimized away.
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (i32.const 2) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (i32.const 0) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (drop | ||
;; CHECK-NEXT: (i32.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.
We will need new tests for the new function optimizeAndNoOverlappingBits
, including the various corner cases (just one overlapping bit, no overlapping bits, etc.)
There are so many rules for
and
, but we still cannot optimize the following one:to zero.
Adding rule for
add
:any boolean & (No overlap with boolean's LSB) ==> 0
Fixes: #7481