[llvm] b05804a - [Analysis] reduce code for isOnlyUsedInZeroEqualityComparison; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 22 11:59:05 PDT 2021
Author: Sanjay Patel
Date: 2021-09-22T14:57:53-04:00
New Revision: b05804ab4c8c62a9d24aff9a0da0eb8ba5d0296f
URL: https://github.com/llvm/llvm-project/commit/b05804ab4c8c62a9d24aff9a0da0eb8ba5d0296f
DIFF: https://github.com/llvm/llvm-project/commit/b05804ab4c8c62a9d24aff9a0da0eb8ba5d0296f.diff
LOG: [Analysis] reduce code for isOnlyUsedInZeroEqualityComparison; NFC
There's a bug here noted by the FIXME and visible in variations of PR50836.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index d381ee22f159..9458c895094a 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -279,16 +279,12 @@ bool llvm::haveNoCommonBitsSet(const Value *LHS, const Value *RHS,
return KnownBits::haveNoCommonBitsSet(LHSKnown, RHSKnown);
}
-bool llvm::isOnlyUsedInZeroEqualityComparison(const Instruction *CxtI) {
- for (const User *U : CxtI->users()) {
- if (const ICmpInst *IC = dyn_cast<ICmpInst>(U))
- if (IC->isEquality())
- if (Constant *C = dyn_cast<Constant>(IC->getOperand(1)))
- if (C->isNullValue())
- continue;
- return false;
- }
- return true;
+bool llvm::isOnlyUsedInZeroEqualityComparison(const Instruction *I) {
+ // FIXME: Should not return true if there are no users.
+ return all_of(I->users(), [](const User *U) {
+ ICmpInst::Predicate P;
+ return match(U, m_ICmp(P, m_Value(), m_Zero())) && ICmpInst::isEquality(P);
+ });
}
static bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero, unsigned Depth,
More information about the llvm-commits
mailing list