(A == Op0 || B == Op0))
return Constant::getAllOnesValue(Op0->getType());
+ // (A & ~B) | (A ^ B) -> (A ^ B)
+ // (~B & A) | (A ^ B) -> (A ^ B)
+ if (match(Op0, m_c_And(m_Value(A), m_Not(m_Value(B)))) &&
+ match(Op1, m_Xor(m_Specific(A), m_Specific(B))))
+ return Op1;
+
+ // Commute the 'or' operands.
+ // (A ^ B) | (A & ~B) -> (A ^ B)
+ // (A ^ B) | (~B & A) -> (A ^ B)
+ if (match(Op1, m_c_And(m_Value(A), m_Not(m_Value(B)))) &&
+ match(Op0, m_Xor(m_Specific(A), m_Specific(B))))
+ return Op0;
+
if (auto *ICILHS = dyn_cast<ICmpInst>(Op0)) {
if (auto *ICIRHS = dyn_cast<ICmpInst>(Op1)) {
if (Value *V = SimplifyOrOfICmps(ICILHS, ICIRHS))
match(Op0, m_c_And(m_Specific(A), m_Value(B))))
return BinaryOperator::CreateOr(Op1, B);
- // (A & ~B) | (A ^ B) -> (A ^ B)
- // (~B & A) | (A ^ B) -> (A ^ B)
- if (match(Op0, m_c_And(m_Value(A), m_Not(m_Value(B)))) &&
- match(Op1, m_Xor(m_Specific(A), m_Specific(B))))
- return BinaryOperator::CreateXor(A, B);
-
- // Commute the 'or' operands.
- // (A ^ B) | (A & ~B) -> (A ^ B)
- // (A ^ B) | (~B & A) -> (A ^ B)
- if (match(Op1, m_c_And(m_Value(A), m_Not(m_Value(B)))) &&
- match(Op0, m_Xor(m_Specific(A), m_Specific(B))))
- return BinaryOperator::CreateXor(A, B);
-
// (A & C)|(B & D)
Value *C = nullptr, *D = nullptr;
if (match(Op0, m_And(m_Value(A), m_Value(C))) &&
ret i32 %or
}
-; (A & ~B) | (A ^ B) -> A ^ B
-
-define i32 @test43(i32 %a, i32 %b) {
-; CHECK-LABEL: @test43(
-; CHECK-NEXT: [[OR:%.*]] = xor i32 %a, %b
-; CHECK-NEXT: ret i32 [[OR]]
-;
- %neg = xor i32 %b, -1
- %and = and i32 %a, %neg
- %xor = xor i32 %a, %b
- %or = or i32 %and, %xor
- ret i32 %or
-}
-
-define i32 @test43_commuted_and(i32 %a, i32 %b) {
-; CHECK-LABEL: @test43_commuted_and(
-; CHECK-NEXT: [[OR:%.*]] = xor i32 %a, %b
-; CHECK-NEXT: ret i32 [[OR]]
-;
- %neg = xor i32 %b, -1
- %and = and i32 %neg, %a
- %xor = xor i32 %a, %b
- %or = or i32 %and, %xor
- ret i32 %or
-}
-
-; Commute operands of the 'or'.
-; (A ^ B) | (A & ~B) -> A ^ B
-
-define i32 @test44(i32 %a, i32 %b) {
-; CHECK-LABEL: @test44(
-; CHECK-NEXT: [[OR:%.*]] = xor i32 %a, %b
-; CHECK-NEXT: ret i32 [[OR]]
-;
- %xor = xor i32 %a, %b
- %neg = xor i32 %b, -1
- %and = and i32 %a, %neg
- %or = or i32 %xor, %and
- ret i32 %or
-}
-
-define i32 @test44_commuted_and(i32 %a, i32 %b) {
-; CHECK-LABEL: @test44_commuted_and(
-; CHECK-NEXT: [[OR:%.*]] = xor i32 %a, %b
-; CHECK-NEXT: ret i32 [[OR]]
-;
- %xor = xor i32 %a, %b
- %neg = xor i32 %b, -1
- %and = and i32 %neg, %a
- %or = or i32 %xor, %and
- ret i32 %or
-}
-
define i32 @test45(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @test45(
; CHECK-NEXT: [[TMP1:%.*]] = and i32 %x, %z
ret <2 x i3> %and
}
+; (A & ~B) | (A ^ B) -> A ^ B
+
+define i32 @test43(i32 %a, i32 %b) {
+; CHECK-LABEL: @test43(
+; CHECK-NEXT: [[OR:%.*]] = xor i32 %a, %b
+; CHECK-NEXT: ret i32 [[OR]]
+;
+ %neg = xor i32 %b, -1
+ %and = and i32 %a, %neg
+ %xor = xor i32 %a, %b
+ %or = or i32 %and, %xor
+ ret i32 %or
+}
+
+define i32 @test43_commuted_and(i32 %a, i32 %b) {
+; CHECK-LABEL: @test43_commuted_and(
+; CHECK-NEXT: [[OR:%.*]] = xor i32 %a, %b
+; CHECK-NEXT: ret i32 [[OR]]
+;
+ %neg = xor i32 %b, -1
+ %and = and i32 %neg, %a
+ %xor = xor i32 %a, %b
+ %or = or i32 %and, %xor
+ ret i32 %or
+}
+
+; Commute operands of the 'or'.
+; (A ^ B) | (A & ~B) -> A ^ B
+
+define i32 @test44(i32 %a, i32 %b) {
+; CHECK-LABEL: @test44(
+; CHECK-NEXT: [[OR:%.*]] = xor i32 %a, %b
+; CHECK-NEXT: ret i32 [[OR]]
+;
+ %xor = xor i32 %a, %b
+ %neg = xor i32 %b, -1
+ %and = and i32 %a, %neg
+ %or = or i32 %xor, %and
+ ret i32 %or
+}
+
+define i32 @test44_commuted_and(i32 %a, i32 %b) {
+; CHECK-LABEL: @test44_commuted_and(
+; CHECK-NEXT: [[OR:%.*]] = xor i32 %a, %b
+; CHECK-NEXT: ret i32 [[OR]]
+;
+ %xor = xor i32 %a, %b
+ %neg = xor i32 %b, -1
+ %and = and i32 %neg, %a
+ %or = or i32 %xor, %and
+ ret i32 %or
+}
+