[llvm] Move 0 vs known-non-zero case to isKnownNonEqual (PR #147330)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 7 09:34:38 PDT 2025


https://github.com/AZero13 updated https://github.com/llvm/llvm-project/pull/147330

>From a02fb39870fe1e96e18e3315abc0938dcc0d5fda Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Mon, 7 Jul 2025 11:37:25 -0400
Subject: [PATCH] [ValueTracking] Check both operands for being 0 and then the
 other for isKnownNonZero

We should check both operands, not just the first one.
---
 llvm/lib/Analysis/ValueTracking.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 09745ed6eac6a..bd9fa1ca5eee2 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2880,9 +2880,10 @@ 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))
+  // TODO: Move these into isKnownNonEqual().
+  if (match(X, m_Zero()) && isKnownNonZero(Y, DemandedElts, Q, Depth))
+      return true;
+  if (match(Y, m_Zero()) && isKnownNonZero(X, DemandedElts, Q, Depth))
       return true;
 
   return ::isKnownNonEqual(X, Y, DemandedElts, Q, Depth);



More information about the llvm-commits mailing list