summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-04-07 16:15:25 +0000
committerChris Lattner <sabre@nondot.org>2005-04-07 16:15:25 +0000
commita9be4490d894f0a5bb3447e9be3b49ecbd3c23a8 (patch)
treea414531f82ff24b5e951d11d6b25fcd54c5e5526 /llvm/lib
parent05e51d92e006bb2c7493cc36972e4f6e8fba1014 (diff)
downloadbcm5719-llvm-a9be4490d894f0a5bb3447e9be3b49ecbd3c23a8.tar.gz
bcm5719-llvm-a9be4490d894f0a5bb3447e9be3b49ecbd3c23a8.zip
Transform X-(X+Y) == -Y and X-(Y+X) == -Y
llvm-svn: 21134
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 40088ba06be..9e40dc3239f 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -792,7 +792,15 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
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 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
// -(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 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
return BinaryOperator::createMul(Op0, CP1);
}
}
+ }
if (BinaryOperator *Op0I = dyn_cast<BinaryOperator>(Op0))
if (Op0I->getOpcode() == Instruction::Add)
OpenPOWER on IntegriCloud