summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-05-08 22:46:53 +0000
committerChris Lattner <sabre@nondot.org>2002-05-08 22:46:53 +0000
commit147e975c438c27b2faca3a5674bc97a563ef89e3 (patch)
tree2f9946178dcc17fe8833b5ae1c53eeb78b09d016 /llvm/lib/Transforms
parent90f5d5a5b1337075f16ef57c5553cb8a7a2b2001 (diff)
downloadbcm5719-llvm-147e975c438c27b2faca3a5674bc97a563ef89e3.tar.gz
bcm5719-llvm-147e975c438c27b2faca3a5674bc97a563ef89e3.zip
* Combine: A-(-B) -> A + B
* Bugfix: A + -B and -A + B llvm-svn: 2561
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 9fce3cf1ff2..a77bcb95864 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -128,13 +128,13 @@ Instruction *InstCombiner::visitAdd(BinaryOperator *I) {
return I;
}
- // -B + A --> A - B
+ // -A + B --> B - A
if (Value *V = dyn_castNegInst(LHS))
- return BinaryOperator::create(Instruction::Sub, RHS, LHS);
+ return BinaryOperator::create(Instruction::Sub, RHS, V);
// A + -B --> A - B
if (Value *V = dyn_castNegInst(RHS))
- return BinaryOperator::create(Instruction::Sub, LHS, RHS);
+ return BinaryOperator::create(Instruction::Sub, LHS, V);
// Simplify add instructions with a constant RHS...
if (Constant *Op2 = dyn_cast<Constant>(RHS)) {
@@ -176,13 +176,9 @@ Instruction *InstCombiner::visitSub(BinaryOperator *I) {
if (Constant *RHS = *Constant::getNullValue(I->getType()) - *Op2) // 0 - RHS
return BinaryOperator::create(Instruction::Add, Op0, RHS, I->getName());
- // If this is a 'C = -B', check to see if 'B = -A', so that C = A...
- if (Op0 == Constant::getNullValue(I->getType()))
- if (Value *V = dyn_castNegInst(Op1)) {
- AddUsesToWorkList(I); // Add all modified instrs to worklist
- I->replaceAllUsesWith(V);
- return I;
- }
+ // If this is a 'C = x-B', check to see if 'B = -A', so that C = x+A...
+ if (Value *V = dyn_castNegInst(Op1))
+ return BinaryOperator::create(Instruction::Add, Op0, V);
return 0;
}
OpenPOWER on IntegriCloud