[llvm] [ValueTracking] X ^ Y != 0 if X != Y. (PR #146975)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 3 16:56:01 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: AZero13 (AZero13)

<details>
<summary>Changes</summary>

It goes without saying that for x ^ y to be 0, x and y must be equal.

---
Full diff: https://github.com/llvm/llvm-project/pull/146975.diff


1 Files Affected:

- (modified) llvm/lib/Analysis/ValueTracking.cpp (+4) 


``````````diff
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index e576f4899810a..ba8ae3a975729 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3043,6 +3043,10 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
     // (X ^ (X != 0)) is non zero
     if (matchOpWithOpEqZero(I->getOperand(0), I->getOperand(1)))
       return true;
+    // X ^ Y != 0 if X != Y.
+    if (isKnownNonEqual(I->getOperand(0), I->getOperand(1), DemandedElts, Q,
+                        Depth))
+      return true;
     break;
   case Instruction::Or:
     // (X | (X != 0)) is non zero

``````````

</details>


https://github.com/llvm/llvm-project/pull/146975


More information about the llvm-commits mailing list