From cb40a3749aa30b7b8a80d0e2d264379c331b1ae2 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 10 Mar 2003 18:24:17 +0000 Subject: [PATCH] Implement: (A|B)^B == A & (~B) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5728 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Scalar/InstructionCombining.cpp | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 890f1fb6051..0dfb235d892 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -493,6 +493,31 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { return ReplaceInstUsesWith(I, ConstantIntegral::getAllOnesValue(I.getType())); + + + if (Instruction *Op1I = dyn_cast(Op1)) + if (Op1I->getOpcode() == Instruction::Or) + if (Op1I->getOperand(0) == Op0) { // B^(B|A) == (A|B)^B + cast(Op1I)->swapOperands(); + I.swapOperands(); + std::swap(Op0, Op1); + } else if (Op1I->getOperand(1) == Op0) { // B^(A|B) == (A|B)^B + I.swapOperands(); + std::swap(Op0, Op1); + } + + if (Instruction *Op0I = dyn_cast(Op0)) + if (Op0I->getOpcode() == Instruction::Or && Op0I->use_size() == 1) { + if (Op0I->getOperand(0) == Op1) // (B|A)^B == (A|B)^B + cast(Op0I)->swapOperands(); + if (Op0I->getOperand(1) == Op1) { // (A|B)^B == A & ~B + Value *NotB = BinaryOperator::createNot(Op1, Op1->getName()+".not", &I); + WorkList.push_back(cast(NotB)); + return BinaryOperator::create(Instruction::And, Op0I->getOperand(0), + NotB); + } + } + return Changed ? &I : 0; }