-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[ValueTracking] Check both operands for being 0 and then the other for isKnownNonZero #147330
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
@llvm/pr-subscribers-llvm-analysis Author: AZero13 (AZero13) ChangesFull diff: https://github.com/llvm/llvm-project/pull/147330.diff 1 Files Affected:
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 09745ed6eac6a..a8f5728c940b1 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2880,11 +2880,6 @@ static bool isNonZeroSub(const APInt &DemandedElts, const SimplifyQuery &Q,
if (matchOpWithOpEqZero(X, Y))
return true;
- // TODO: Move this case into isKnownNonEqual().
- if (auto *C = dyn_cast<Constant>(X))
- if (C->isNullValue() && isKnownNonZero(Y, DemandedElts, Q, Depth))
- return true;
-
return ::isKnownNonEqual(X, Y, DemandedElts, Q, Depth);
}
@@ -3892,6 +3887,12 @@ static bool isKnownNonEqual(const Value *V1, const Value *V2,
if (Depth >= MaxAnalysisRecursionDepth)
return false;
+ // 0 vs known-non-zero => definitely different
+ if (match(V1, m_Zero()) && isKnownNonZero(V2, DemandedElts, Q, Depth + 1))
+ return true;
+ if (match(V2, m_Zero()) && isKnownNonZero(V1, DemandedElts, Q, Depth + 1))
+ return true;
+
// See if we can recurse through (exactly one of) our operands. This
// requires our operation be 1-to-1 and map every input value to exactly
// one output value. Such an operation is invertible.
|
@dtcxzyw Can you please run the opt-benchmark so I can make tests |
✅ With the latest revision this PR passed the C/C++ code formatter. |
if (match(V1, m_Zero()) && isKnownNonZero(V2, DemandedElts, Q, Depth + 1)) | ||
return true; | ||
if (match(V2, m_Zero()) && isKnownNonZero(V1, DemandedElts, Q, Depth + 1)) | ||
return true; |
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 makes sense. x - 0 is just x and should get folded away.
We should check both operands, not just the first one.