[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Fri Jun 18 01:15:02 PDT 2004
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.213 -> 1.214
---
Log message:
Implement Transforms/InstCombine/and.ll:test17, a common case that
occurs due to unordered comparison macros in math.h
---
Diffs of the changes: (+15 -3)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.213 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.214
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.213 Thu Jun 17 13:16:02 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Jun 18 01:07:51 2004
@@ -1130,6 +1130,9 @@
Value *Op0NotVal = dyn_castNotVal(Op0);
Value *Op1NotVal = dyn_castNotVal(Op1);
+ if (Op0NotVal == Op1 || Op1NotVal == Op0) // A & ~A == ~A & A == 0
+ return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
+
// (~A & ~B) == (~(A | B)) - Demorgan's Law
if (Op0NotVal && Op1NotVal && isOnlyUse(Op0) && isOnlyUse(Op1)) {
Instruction *Or = BinaryOperator::createOr(Op0NotVal, Op1NotVal,
@@ -1138,9 +1141,6 @@
return BinaryOperator::createNot(Or);
}
- if (Op0NotVal == Op1 || Op1NotVal == Op0) // A & ~A == ~A & A == 0
- return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
-
// (setcc1 A, B) & (setcc2 A, B) --> (setcc3 A, B)
if (SetCondInst *RHS = dyn_cast<SetCondInst>(I.getOperand(1)))
if (Instruction *R = AssociativeOpt(I, FoldSetCCLogical(*this, RHS)))
@@ -1271,6 +1271,18 @@
ConstantInt::get(I.getType(), 1));
return BinaryOperator::createAdd(Op0I->getOperand(1), ConstantRHS);
}
+
+ // ~(~X & Y) --> (X | ~Y)
+ if (Op0I->getOpcode() == Instruction::And && RHS->isAllOnesValue()) {
+ if (dyn_castNotVal(Op0I->getOperand(1))) Op0I->swapOperands();
+ if (Value *Op0NotVal = dyn_castNotVal(Op0I->getOperand(0))) {
+ Instruction *NotY =
+ BinaryOperator::createNot(Op0I->getOperand(1),
+ Op0I->getOperand(1)->getName()+".not");
+ InsertNewInstBefore(NotY, I);
+ return BinaryOperator::createOr(Op0NotVal, NotY);
+ }
+ }
if (ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand(1)))
switch (Op0I->getOpcode()) {
More information about the llvm-commits
mailing list