[llvm] c49ef14 - [InstSimplify] reduce code duplication for 'or' logic folds; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 30 11:15:18 PST 2021
Author: Sanjay Patel
Date: 2021-11-30T14:08:54-05:00
New Revision: c49ef1448d1779385e0e0ea88b1d8343f4830a79
URL: https://github.com/llvm/llvm-project/commit/c49ef1448d1779385e0e0ea88b1d8343f4830a79
DIFF: https://github.com/llvm/llvm-project/commit/c49ef1448d1779385e0e0ea88b1d8343f4830a79.diff
LOG: [InstSimplify] reduce code duplication for 'or' logic folds; NFC
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 37732b19e1c3e..1f568ad6e839c 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -2198,14 +2198,28 @@ static Value *simplifyOrLogic(Value *X, Value *Y) {
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)
+ // (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;
+ // (~A ^ B) | (A & B) --> ~A ^ B
+ // (B ^ ~A) | (A & B) --> B ^ ~A
+ // (~A ^ B) | (B & A) --> ~A ^ B
+ // (B ^ ~A) | (B & A) --> B ^ ~A
+ if (match(X, m_c_Xor(m_Not(m_Value(A)), m_Value(B))) &&
+ match(Y, m_c_And(m_Specific(A), m_Specific(B))))
+ return X;
+
+ // (A ^ B) | (A | B) --> A | B
+ // (A ^ B) | (B | A) --> B | A
+ if (match(X, m_Xor(m_Value(A), m_Value(B))) &&
+ match(Y, m_c_Or(m_Specific(A), m_Specific(B))))
+ return Y;
+
return nullptr;
}
@@ -2241,38 +2255,6 @@ static Value *SimplifyOrInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
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(Op0, m_And(m_Value(A), m_Value(B))) &&
- (match(Op1, m_c_Xor(m_Specific(A), m_Not(m_Specific(B)))) ||
- match(Op1, m_c_Xor(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(Op1, m_And(m_Value(A), m_Value(B))) &&
- (match(Op0, m_c_Xor(m_Specific(A), m_Not(m_Specific(B)))) ||
- match(Op0, m_c_Xor(m_Not(m_Specific(A)), m_Specific(B)))))
- return Op0;
-
- // (A | B) | (A ^ B) --> A | B
- // (B | A) | (A ^ B) --> B | A
- if (match(Op1, m_Xor(m_Value(A), m_Value(B))) &&
- match(Op0, m_c_Or(m_Specific(A), m_Specific(B))))
- return Op0;
-
- // Commute the outer 'or' operands.
- // (A ^ B) | (A | B) --> A | B
- // (A ^ B) | (B | A) --> B | A
- if (match(Op0, m_Xor(m_Value(A), m_Value(B))) &&
- match(Op1, m_c_Or(m_Specific(A), m_Specific(B))))
- return Op1;
-
// (~A & B) | ~(A | B) --> ~A
// (~A & B) | ~(B | A) --> ~A
// (B & ~A) | ~(A | B) --> ~A
More information about the llvm-commits
mailing list