From: Craig Topper Date: Mon, 10 Apr 2017 06:53:21 +0000 (+0000) Subject: [InstCombine] Make the (A|B)^B -> A & ~B transform code consistent with the very... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a4cc6a638b20aeecf51cbed5bad0d278f5bd51c;p=llvm [InstCombine] Make the (A|B)^B -> A & ~B transform code consistent with the very similar (A&B)^B -> ~A & B code. This should be NFC except for the addition of hasOneUse check. I think this code is still overly complicated and should use matchers, but first I wanted to make it consistent. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299834 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 5b2dbd9d1f3..091c80daef6 100644 --- a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2504,12 +2504,12 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { BinaryOperator *Op1I = dyn_cast(Op1); if (Op1I) { Value *A, *B; - if (match(Op1I, m_Or(m_Value(A), m_Value(B)))) { - if (A == Op0) { // B^(B|A) == (A|B)^B + if (match(Op1I, m_OneUse(m_Or(m_Value(A), m_Value(B))))) { + if (A == Op0) { // A^(A|B) == A^(B|A) Op1I->swapOperands(); - I.swapOperands(); - std::swap(Op0, Op1); - } else if (B == Op0) { // B^(A|B) == (A|B)^B + std::swap(A, B); + } + if (B == Op0) { // A^(B|A) == (B|A)^A I.swapOperands(); // Simplified below. std::swap(Op0, Op1); }