summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-02-17 20:51:26 +0000
committerChris Lattner <sabre@nondot.org>2008-02-17 20:51:26 +0000
commita70d1384571a104d5c9d1363c02d7b8689df6038 (patch)
tree5cf1cc42c7dc15940d29392299dd334ff4596196 /llvm/lib/Transforms
parent2de8c2d41f5b375cfa958aeafa6e78591ca1da9e (diff)
downloadbcm5719-llvm-a70d1384571a104d5c9d1363c02d7b8689df6038.tar.gz
bcm5719-llvm-a70d1384571a104d5c9d1363c02d7b8689df6038.zip
Split up subtracts into add+negate if they have a reassociable use or operand
that is also a subtract. This implements PR2047 and Transforms/Reassociate/subtest2.ll llvm-svn: 47241
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/Reassociate.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index d0537ea8c43..bec91dbe67c 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -399,13 +399,16 @@ static bool ShouldBreakUpSubtract(Instruction *Sub) {
return false;
// Don't bother to break this up unless either the LHS is an associable add or
- // if this is only used by one.
- if (isReassociableOp(Sub->getOperand(0), Instruction::Add))
+ // subtract or if this is only used by one.
+ if (isReassociableOp(Sub->getOperand(0), Instruction::Add) ||
+ isReassociableOp(Sub->getOperand(0), Instruction::Sub))
return true;
- if (isReassociableOp(Sub->getOperand(1), Instruction::Add))
+ if (isReassociableOp(Sub->getOperand(1), Instruction::Add) ||
+ isReassociableOp(Sub->getOperand(0), Instruction::Sub))
return true;
-
- if (Sub->hasOneUse() && isReassociableOp(Sub->use_back(), Instruction::Add))
+ if (Sub->hasOneUse() &&
+ (isReassociableOp(Sub->use_back(), Instruction::Add) ||
+ isReassociableOp(Sub->use_back(), Instruction::Sub)))
return true;
return false;
OpenPOWER on IntegriCloud