From e194a17dab63f4e59d12a4971318e180e9cd1c53 Mon Sep 17 00:00:00 2001 From: Rose Date: Mon, 7 Jul 2025 11:37:25 -0400 Subject: [PATCH] [ValueTracking] Move 0 vs known-non-zero case to isKnownNonEqual --- llvm/lib/Analysis/ValueTracking.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 09745ed6eac6a..8b14a6a0ab7a3 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2880,7 +2880,8 @@ static bool isNonZeroSub(const APInt &DemandedElts, const SimplifyQuery &Q, if (matchOpWithOpEqZero(X, Y)) return true; - // TODO: Move this case into isKnownNonEqual(). + // TODO: isKnownNonEqual() should catch these cases, but it is not, resulting + // in regressions. if (auto *C = dyn_cast(X)) if (C->isNullValue() && isKnownNonZero(Y, DemandedElts, Q, Depth)) return true; @@ -3892,6 +3893,12 @@ static bool isKnownNonEqual(const Value *V1, const Value *V2, if (Depth >= MaxAnalysisRecursionDepth) return false; + // 0 vs known-non-zero + 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.