diff options
author | Chris Lattner <sabre@nondot.org> | 2004-02-16 03:54:20 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-02-16 03:54:20 +0000 |
commit | 26ca7e145e076efb3dd5085099289347295993fe (patch) | |
tree | 6ae9f6e4f72eeb4c908cfa6ee53c9ef1c16dee64 /lib | |
parent | 72695f7bb7a79e6c43e6d0966f3dba5855026e7a (diff) | |
download | llvm-26ca7e145e076efb3dd5085099289347295993fe.tar.gz llvm-26ca7e145e076efb3dd5085099289347295993fe.tar.bz2 llvm-26ca7e145e076efb3dd5085099289347295993fe.tar.xz |
Teach LLVM to unravel the "swap idiom". This implements:
Regression/Transforms/InstCombine/xor.ll:test20
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11492 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 15c8945089..4deb4eda32 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -1086,7 +1086,7 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { ConstantIntegral::getAllOnesValue(I.getType())); if (Instruction *Op1I = dyn_cast<Instruction>(Op1)) - if (Op1I->getOpcode() == Instruction::Or) + if (Op1I->getOpcode() == Instruction::Or) { if (Op1I->getOperand(0) == Op0) { // B^(B|A) == (A|B)^B cast<BinaryOperator>(Op1I)->swapOperands(); I.swapOperands(); @@ -1094,7 +1094,13 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { } else if (Op1I->getOperand(1) == Op0) { // B^(A|B) == (A|B)^B I.swapOperands(); std::swap(Op0, Op1); - } + } + } else if (Op1I->getOpcode() == Instruction::Xor) { + if (Op0 == Op1I->getOperand(0)) // A^(A^B) == B + return ReplaceInstUsesWith(I, Op1I->getOperand(1)); + else if (Op0 == Op1I->getOperand(1)) // A^(B^A) == B + return ReplaceInstUsesWith(I, Op1I->getOperand(0)); + } if (Instruction *Op0I = dyn_cast<Instruction>(Op0)) if (Op0I->getOpcode() == Instruction::Or && Op0I->hasOneUse()) { @@ -1106,6 +1112,11 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { return BinaryOperator::create(Instruction::And, Op0I->getOperand(0), NotB); } + } else if (Op0I->getOpcode() == Instruction::Xor) { + if (Op1 == Op0I->getOperand(0)) // (A^B)^A == B + return ReplaceInstUsesWith(I, Op0I->getOperand(1)); + else if (Op1 == Op0I->getOperand(1)) // (B^A)^A == B + return ReplaceInstUsesWith(I, Op0I->getOperand(0)); } // (A & C1)^(B & C2) -> (A & C1)|(B & C2) iff C1^C2 == 0 |