summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d05b6c6)
raw | patch | inline | side by side (parent: d05b6c6)
author | Suyog Sarda <suyog.sarda@samsung.com> | |
Fri, 1 Aug 2014 04:59:26 +0000 (04:59 +0000) | ||
committer | Suyog Sarda <suyog.sarda@samsung.com> | |
Fri, 1 Aug 2014 04:59:26 +0000 (04:59 +0000) |
Differential Revision: http://reviews.llvm.org/D4628
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214478 91177308-0d34-0410-b5e6-96231b3b80d8
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214478 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | patch | blob | history | |
test/Transforms/InstCombine/or-xor.ll | patch | blob | history |
diff --git a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index add2f29b341c056bf1373bdf9d10c3d56ae6a21b..3fd5b7bbd8ca22a3e90aff06b06689f2bc320267 100644 (file)
if (match(Op1, m_Xor(m_Specific(B), m_Specific(A))))
if (Op0->hasOneUse() || cast<BinaryOperator>(Op0)->hasOneUse())
return BinaryOperator::CreateAnd(Op1, Builder->CreateNot(C));
+
+ // (A | B) & ((~A) ^ B) -> (A & B)
+ if (match(Op0, m_Or(m_Value(A), m_Value(B))) &&
+ match(Op1, m_Xor(m_Not(m_Specific(A)), m_Specific(B))))
+ return BinaryOperator::CreateAnd(A, B);
+
+ // ((~A) ^ B) & (A | B) -> (A & B)
+ if (match(Op0, m_Xor(m_Not(m_Value(A)), m_Value(B))) &&
+ match(Op1, m_Or(m_Specific(A), m_Specific(B))))
+ return BinaryOperator::CreateAnd(A, B);
}
if (ICmpInst *RHS = dyn_cast<ICmpInst>(Op1))
index 3f247e27522a50033ebcae06bbfca22c34a18ddc..5c15c456f8df2569b95ae3f41609ccab5b0b3eb4 100644 (file)
; CHECK-LABEL: @test11(
; CHECK-NEXT: ret i32 -1
}
+
+; (x | y) & ((~x) ^ y) -> (x & y)
+define i32 @test12(i32 %x, i32 %y) {
+ %or = or i32 %x, %y
+ %neg = xor i32 %x, -1
+ %xor = xor i32 %neg, %y
+ %and = and i32 %or, %xor
+ ret i32 %and
+; CHECK-LABEL: @test12(
+; CHECK-NEXT: %and = and i32 %x, %y
+; CHECK-NEXT: ret i32 %and
+}
+
+; ((~x) ^ y) & (x | y) -> (x & y)
+define i32 @test13(i32 %x, i32 %y) {
+ %neg = xor i32 %x, -1
+ %xor = xor i32 %neg, %y
+ %or = or i32 %x, %y
+ %and = and i32 %xor, %or
+ ret i32 %and
+; CHECK-LABEL: @test13(
+; CHECK-NEXT: %and = and i32 %x, %y
+; CHECK-NEXT: ret i32 %and
+}