[llvm] [ValueTracking] Recognize `X op (X != 0)` as non-zero (PR #88579)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 13 01:32:28 PDT 2024
================
@@ -2420,9 +2420,20 @@ static bool isNonZeroRecurrence(const PHINode *PN) {
}
}
+static bool matchOpWithOpEqZero(Value *Op0, Value *Op1) {
+ ICmpInst::Predicate Pred;
+ return (match(Op0, m_ZExtOrSExt(m_ICmp(Pred, m_Specific(Op1), m_Zero()))) ||
+ match(Op1, m_ZExtOrSExt(m_ICmp(Pred, m_Specific(Op0), m_Zero())))) &&
+ Pred == ICmpInst::ICMP_EQ;
+}
+
static bool isNonZeroAdd(const APInt &DemandedElts, unsigned Depth,
const SimplifyQuery &Q, unsigned BitWidth, Value *X,
Value *Y, bool NSW, bool NUW) {
+ // (X + (X != 0)) is non zero
----------------
dtcxzyw wrote:
Yeah, it is a common pattern. But I would like to canonicalize it into `umax(X, 1)` (or vice versa).
https://github.com/llvm/llvm-project/pull/88579
More information about the llvm-commits
mailing list