-
Notifications
You must be signed in to change notification settings - Fork 15k
[ValueTracking] Have sub and xor in KnownNonZero take the same exact path #146975
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
|
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-llvm-analysis Author: AZero13 (AZero13) ChangesIt goes without saying that for x ^ y to be 0, x and y must be equal. Full diff: https://github.com/llvm/llvm-project/pull/146975.diff 1 Files Affected:
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index e576f4899810a..ba8ae3a975729 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3043,6 +3043,10 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
// (X ^ (X != 0)) is non zero
if (matchOpWithOpEqZero(I->getOperand(0), I->getOperand(1)))
return true;
+ // X ^ Y != 0 if X != Y.
+ if (isKnownNonEqual(I->getOperand(0), I->getOperand(1), DemandedElts, Q,
+ Depth))
+ return true;
break;
case Instruction::Or:
// (X | (X != 0)) is non zero
|
|
I really cannot find a case for this, but this is just too obvious and a fast path. |
|
@dtcxzyw Can I see if it affects opt at all so I can use it to make some tests. |
f6d250b to
2636776
Compare
|
Done! @nikic |
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.
Please also add a test showing an improvement (you can take inspiration from the llvm-opt-benchmark results).
Done! |
|
Actually, I have a better idea! |
|
@nikic I am going to have XOR and sub take the same path: |
…path If x - y == 0, then x ^ y == 0. Therefore, we can do the exact same checks. https://alive2.llvm.org/ce/z/MtBRoj
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.
LGTM
|
Thanks. I don't have merge permissions. |
If x - y == 0, then x ^ y == 0. Therefore, we can do the exact same checks.
https://alive2.llvm.org/ce/z/MtBRoj