summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-03-10 18:24:17 +0000
committerChris Lattner <sabre@nondot.org>2003-03-10 18:24:17 +0000
commit1bbb7b6f19571bb150e3ad70082426ecc42c5ce1 (patch)
tree7b978f1c1a94e210bbf2e30ce4910c79230761b7 /llvm/lib/Transforms
parent96c4dd94ef854becaa608485d05e37e6eda86d02 (diff)
downloadbcm5719-llvm-1bbb7b6f19571bb150e3ad70082426ecc42c5ce1.tar.gz
bcm5719-llvm-1bbb7b6f19571bb150e3ad70082426ecc42c5ce1.zip
Implement: (A|B)^B == A & (~B)
llvm-svn: 5728
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 890f1fb6051..0dfb235d892 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/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<Instruction>(Op1))
+ if (Op1I->getOpcode() == Instruction::Or)
+ if (Op1I->getOperand(0) == Op0) { // B^(B|A) == (A|B)^B
+ cast<BinaryOperator>(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<Instruction>(Op0))
+ if (Op0I->getOpcode() == Instruction::Or && Op0I->use_size() == 1) {
+ if (Op0I->getOperand(0) == Op1) // (B|A)^B == (A|B)^B
+ cast<BinaryOperator>(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<Instruction>(NotB));
+ return BinaryOperator::create(Instruction::And, Op0I->getOperand(0),
+ NotB);
+ }
+ }
+
return Changed ? &I : 0;
}
OpenPOWER on IntegriCloud