From dbe14483606191307a800be681ccc78393bb2a6f Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 10 Apr 2017 06:53:28 +0000 Subject: [PATCH] [InstCombine] use m_c_And and m_c_Xor to handle commuted versions of a transform. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299837 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 4 ++-- test/Transforms/InstCombine/xor2.ll | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 71a7c92ec06..fa2631c9535 100644 --- a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2600,11 +2600,11 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { } // (A & B) ^ (A ^ B) -> (A | B) if (match(Op0, m_And(m_Value(A), m_Value(B))) && - match(Op1, m_Xor(m_Specific(A), m_Specific(B)))) + match(Op1, m_c_Xor(m_Specific(A), m_Specific(B)))) return BinaryOperator::CreateOr(A, B); // (A ^ B) ^ (A & B) -> (A | B) if (match(Op0, m_Xor(m_Value(A), m_Value(B))) && - match(Op1, m_And(m_Specific(A), m_Specific(B)))) + match(Op1, m_c_And(m_Specific(A), m_Specific(B)))) return BinaryOperator::CreateOr(A, B); } diff --git a/test/Transforms/InstCombine/xor2.ll b/test/Transforms/InstCombine/xor2.ll index ca93419681a..79e62723f14 100644 --- a/test/Transforms/InstCombine/xor2.ll +++ b/test/Transforms/InstCombine/xor2.ll @@ -147,9 +147,7 @@ define i32 @test9(i32 %b, i32 %c) { ; (A & B) ^ (B ^ A) -> (A | B) define i32 @test9b(i32 %b, i32 %c) { ; CHECK-LABEL: @test9b( -; CHECK-NEXT: [[AND:%.*]] = and i32 [[B:%.*]], [[C:%.*]] -; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[C]], [[B]] -; CHECK-NEXT: [[XOR2:%.*]] = xor i32 [[AND]], [[XOR]] +; CHECK-NEXT: [[XOR2:%.*]] = or i32 [[B:%.*]], [[C:%.*]] ; CHECK-NEXT: ret i32 [[XOR2]] ; %and = and i32 %b, %c @@ -173,9 +171,7 @@ define i32 @test10(i32 %b, i32 %c) { ; (A ^ B) ^ (A & B) -> (A | B) define i32 @test10b(i32 %b, i32 %c) { ; CHECK-LABEL: @test10b( -; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[B:%.*]], [[C:%.*]] -; CHECK-NEXT: [[AND:%.*]] = and i32 [[C]], [[B]] -; CHECK-NEXT: [[XOR2:%.*]] = xor i32 [[XOR]], [[AND]] +; CHECK-NEXT: [[XOR2:%.*]] = or i32 [[B:%.*]], [[C:%.*]] ; CHECK-NEXT: ret i32 [[XOR2]] ; %xor = xor i32 %b, %c -- 2.50.1