summaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar
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
commit5c4afb9034b3dd784620977e67991043a312ae60 (patch)
treef85e7c656c795a444415ee07f43d599c274fc157 /lib/Transforms/Scalar
parent44f87aca32be07fe3c8dfc1a0bbb178554d1e7d6 (diff)
downloadexternal_llvm-5c4afb9034b3dd784620977e67991043a312ae60.zip
external_llvm-5c4afb9034b3dd784620977e67991043a312ae60.tar.gz
external_llvm-5c4afb9034b3dd784620977e67991043a312ae60.tar.bz2
* Combine: A-(-B) -> A + B
* Bugfix: A + -B and -A + B git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2561 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 9fce3cf..a77bcb9 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/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;
}