[llvm] [InstCombine] Turn (A | B) != 0 & (A == 0 | B == 0) -> (A == 0) ^ (B == 0) (PR #207257)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 2 12:12:30 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 58b689dea..f05cf6a7c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -1943,9 +1943,16 @@ static Instruction *foldAndToXor(BinaryOperator &I,
   // (A | B) != 0 & (A == 0 | B == 0) -> (A == 0) ^ (B == 0)
   // This is effectively (A | B) & ~(A & B) where A and B are conditions.
   Value *CmpA, *CmpB;
-  if (match(&I, m_c_And(m_SpecificICmp(ICmpInst::ICMP_NE, m_Or(m_Value(A), m_Value(B)), m_Zero()),
-                        m_c_Or(m_CombineAnd(m_Value(CmpA), m_SpecificICmp(ICmpInst::ICMP_EQ, m_Deferred(A), m_Zero())),
-                               m_CombineAnd(m_Value(CmpB), m_SpecificICmp(ICmpInst::ICMP_EQ, m_Deferred(B), m_Zero()))))))
+  if (match(&I,
+            m_c_And(
+                m_SpecificICmp(ICmpInst::ICMP_NE, m_Or(m_Value(A), m_Value(B)),
+                               m_Zero()),
+                m_c_Or(m_CombineAnd(m_Value(CmpA),
+                                    m_SpecificICmp(ICmpInst::ICMP_EQ,
+                                                   m_Deferred(A), m_Zero())),
+                       m_CombineAnd(m_Value(CmpB),
+                                    m_SpecificICmp(ICmpInst::ICMP_EQ,
+                                                   m_Deferred(B), m_Zero()))))))
     return BinaryOperator::CreateXor(CmpA, CmpB);
 
   return nullptr;

``````````

</details>


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


More information about the llvm-commits mailing list