[llvm] 3375046 - [ValueTracking] Use isKnownNonEqual() in isNonZeroSub()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 18 03:26:52 PST 2023
Author: Nikita Popov
Date: 2023-12-18T12:26:40+01:00
New Revision: 337504683efa0b898bcf69b4e5be67d73dbaf180
URL: https://github.com/llvm/llvm-project/commit/337504683efa0b898bcf69b4e5be67d73dbaf180
DIFF: https://github.com/llvm/llvm-project/commit/337504683efa0b898bcf69b4e5be67d73dbaf180.diff
LOG: [ValueTracking] Use isKnownNonEqual() in isNonZeroSub()
(x - y) != 0 is true iff x != y, so use the isKnownNonEqual()
helper, which knows some additional tricks.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Analysis/ValueTracking/known-non-zero.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 9ae05a4b5ccc72..45fdd4eda47d76 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2368,19 +2368,12 @@ static bool isNonZeroAdd(const APInt &DemandedElts, unsigned Depth,
static bool isNonZeroSub(const APInt &DemandedElts, unsigned Depth,
const SimplifyQuery &Q, unsigned BitWidth, Value *X,
Value *Y) {
+ // TODO: Move this case into isKnownNonEqual().
if (auto *C = dyn_cast<Constant>(X))
if (C->isNullValue() && isKnownNonZero(Y, DemandedElts, Depth, Q))
return true;
- KnownBits XKnown = computeKnownBits(X, DemandedElts, Depth, Q);
- if (XKnown.isUnknown())
- return false;
- KnownBits YKnown = computeKnownBits(Y, DemandedElts, Depth, Q);
- // If X != Y then X - Y is non zero.
- std::optional<bool> ne = KnownBits::ne(XKnown, YKnown);
- // If we are unable to compute if X != Y, we won't be able to do anything
- // computing the knownbits of the sub expression so just return here.
- return ne && *ne;
+ return ::isKnownNonEqual(X, Y, Depth, Q);
}
static bool isNonZeroShift(const Operator *I, const APInt &DemandedElts,
diff --git a/llvm/test/Analysis/ValueTracking/known-non-zero.ll b/llvm/test/Analysis/ValueTracking/known-non-zero.ll
index d8dbd1a1b0bda4..c8e17f8dcc69f8 100644
--- a/llvm/test/Analysis/ValueTracking/known-non-zero.ll
+++ b/llvm/test/Analysis/ValueTracking/known-non-zero.ll
@@ -1222,10 +1222,7 @@ define i1 @sub_via_non_eq(i8 %x, i8 %y) {
; CHECK-LABEL: @sub_via_non_eq(
; CHECK-NEXT: [[NE:%.*]] = icmp ne i8 [[X:%.*]], 0
; CHECK-NEXT: call void @llvm.assume(i1 [[NE]])
-; CHECK-NEXT: [[SHL:%.*]] = shl nuw i8 [[X]], 3
-; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[X]], [[SHL]]
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[SUB]], 0
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 false
;
%ne = icmp ne i8 %x, 0
call void @llvm.assume(i1 %ne)
More information about the llvm-commits
mailing list