[llvm] 7a7c059 - [InstSimplify] reduce code duplication for 'or' logic fold; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 30 09:57:07 PST 2021
Author: Sanjay Patel
Date: 2021-11-30T12:55:37-05:00
New Revision: 7a7c059d867554e116244ad5639d05d75ed1a7cd
URL: https://github.com/llvm/llvm-project/commit/7a7c059d867554e116244ad5639d05d75ed1a7cd
DIFF: https://github.com/llvm/llvm-project/commit/7a7c059d867554e116244ad5639d05d75ed1a7cd.diff
LOG: [InstSimplify] reduce code duplication for 'or' logic fold; NFC
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 8f1ba831874e..37732b19e1c3 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -2196,6 +2196,16 @@ static Value *simplifyOrLogic(Value *X, Value *Y) {
if (match(Y, m_c_And(m_Specific(X), m_Value())))
return X;
+ Value *A, *B;
+
+ // (A & ~B) | (A ^ B) --> (A ^ B)
+ // (~B & A) | (A ^ B) --> (A ^ B)
+ // (A & ~B) | (B ^ A) --> (B ^ A)
+ // (~B & A) | (B ^ A) --> (B ^ A)
+ if (match(X, m_c_And(m_Value(A), m_Not(m_Value(B)))) &&
+ match(Y, m_c_Xor(m_Specific(A), m_Specific(B))))
+ return Y;
+
return nullptr;
}
@@ -2230,24 +2240,6 @@ static Value *SimplifyOrInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
return V;
Value *A, *B, *NotA;
- // (A & ~B) | (A ^ B) -> (A ^ B)
- // (~B & A) | (A ^ B) -> (A ^ B)
- // (A & ~B) | (B ^ A) -> (B ^ A)
- // (~B & A) | (B ^ A) -> (B ^ A)
- if (match(Op1, m_Xor(m_Value(A), m_Value(B))) &&
- (match(Op0, m_c_And(m_Specific(A), m_Not(m_Specific(B)))) ||
- match(Op0, m_c_And(m_Not(m_Specific(A)), m_Specific(B)))))
- return Op1;
-
- // Commute the 'or' operands.
- // (A ^ B) | (A & ~B) -> (A ^ B)
- // (A ^ B) | (~B & A) -> (A ^ B)
- // (B ^ A) | (A & ~B) -> (B ^ A)
- // (B ^ A) | (~B & A) -> (B ^ A)
- if (match(Op0, m_Xor(m_Value(A), m_Value(B))) &&
- (match(Op1, m_c_And(m_Specific(A), m_Not(m_Specific(B)))) ||
- match(Op1, m_c_And(m_Not(m_Specific(A)), m_Specific(B)))))
- return Op0;
// (A & B) | (~A ^ B) -> (~A ^ B)
// (B & A) | (~A ^ B) -> (~A ^ B)
More information about the llvm-commits
mailing list