Implement (A&((~A)|B)) -> A&B transformation in the instruction combiner. This
takes care of all permutations of this pattern.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60290 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 8716e9a..ace3ff8 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -3993,6 +3993,7 @@
         std::swap(Op0, Op1);
       }
     }
+
     if (Op1->hasOneUse() &&
         match(Op1, m_Xor(m_Value(A), m_Value(B)))) {
       if (B == Op0) {                                // B&(A^B) -> B&(B^A)
@@ -4005,6 +4006,24 @@
         return BinaryOperator::CreateAnd(A, NotB);
       }
     }
+
+    // (A&((~A)|B)) -> A&B
+    if (match(Op0, m_Or(m_Not(m_Value(A)), m_Value(B)))) {
+      if (A == Op1)
+        return BinaryOperator::CreateAnd(A, B);
+    }
+    if (match(Op0, m_Or(m_Value(A), m_Not(m_Value(B))))) {
+      if (B == Op1)
+        return BinaryOperator::CreateAnd(A, B);
+    }
+    if (match(Op1, m_Or(m_Not(m_Value(A)), m_Value(B)))) {
+      if (A == Op0)
+        return BinaryOperator::CreateAnd(A, B);
+    }
+    if (match(Op1, m_Or(m_Value(A), m_Not(m_Value(B))))) {
+      if (B == Op0)
+        return BinaryOperator::CreateAnd(A, B);
+    }
   }
   
   if (ICmpInst *RHS = dyn_cast<ICmpInst>(Op1)) {