[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Mon Mar 10 12:25:02 PST 2003
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.70 -> 1.71
---
Log message:
Implement: (A|B)^B == A & (~B)
---
Diffs of the changes:
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.70 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.71
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.70 Wed Mar 5 16:33:14 2003
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Mar 10 12:24:17 2003
@@ -493,6 +493,31 @@
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;
}
More information about the llvm-commits
mailing list