InstCombine: Combine (add (and %a, %b) (or %a, %b)) to (add %a, %b)
[oota-llvm.git] / lib / Transforms / InstCombine / InstCombineAndOrXor.cpp
index 3fd5b7bbd8ca22a3e90aff06b06689f2bc320267..971995694e9e3c54d5d876321596771a9fa56397 100644 (file)
@@ -2524,6 +2524,11 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
       match(Op1, m_Not(m_Specific(A))))
     return BinaryOperator::CreateOr(A, Builder->CreateNot(B));
 
+  // (A & ~B) ^ (~A) -> ~(A & B)
+  if (match(Op0, m_And(m_Value(A), m_Not(m_Value(B)))) &&
+      match(Op1, m_Not(m_Specific(A))))
+    return BinaryOperator::CreateNot(Builder->CreateAnd(A, B));
+
   // (icmp1 A, B) ^ (icmp2 A, B) --> (icmp3 A, B)
   if (ICmpInst *RHS = dyn_cast<ICmpInst>(I.getOperand(1)))
     if (ICmpInst *LHS = dyn_cast<ICmpInst>(I.getOperand(0)))