[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Apr 7 09:15:41 PDT 2005
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.317 -> 1.318
---
Log message:
Transform X-(X+Y) == -Y and X-(Y+X) == -Y
---
Diffs of the changes: (+11 -2)
InstructionCombining.cpp | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.317 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.318
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.317 Tue Mar 29 00:37:47 2005
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Thu Apr 7 11:15:25 2005
@@ -792,7 +792,15 @@
return NV;
}
- if (BinaryOperator *Op1I = dyn_cast<BinaryOperator>(Op1))
+ if (BinaryOperator *Op1I = dyn_cast<BinaryOperator>(Op1)) {
+ if (Op1I->getOpcode() == Instruction::Add &&
+ !Op0->getType()->isFloatingPoint()) {
+ if (Op1I->getOperand(0) == Op0) // X-(X+Y) == -Y
+ return BinaryOperator::createNeg(Op1I->getOperand(1), I.getName());
+ else if (Op1I->getOperand(1) == Op0) // X-(Y+X) == -Y
+ return BinaryOperator::createNeg(Op1I->getOperand(0), I.getName());
+ }
+
if (Op1I->hasOneUse()) {
// Replace (x - (y - z)) with (x + (z - y)) if the (y - z) subexpression
// is not used by anyone else...
@@ -822,7 +830,7 @@
// -(X sdiv C) -> (X sdiv -C)
if (Op1I->getOpcode() == Instruction::Div)
if (ConstantSInt *CSI = dyn_cast<ConstantSInt>(Op0))
- if (CSI->getValue() == 0)
+ if (CSI->isNullValue())
if (Constant *DivRHS = dyn_cast<Constant>(Op1I->getOperand(1)))
return BinaryOperator::createDiv(Op1I->getOperand(0),
ConstantExpr::getNeg(DivRHS));
@@ -835,6 +843,7 @@
return BinaryOperator::createMul(Op0, CP1);
}
}
+ }
if (BinaryOperator *Op0I = dyn_cast<BinaryOperator>(Op0))
if (Op0I->getOpcode() == Instruction::Add)
More information about the llvm-commits
mailing list