aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/Reassociate.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-05-08 21:41:35 +0000
committerChris Lattner <sabre@nondot.org>2005-05-08 21:41:35 +0000
commit44b8c7d5d36561d1a685f8b5a95b71f939cce26e (patch)
tree3ba57bff7814f213d8f4a64685242d8924ad5094 /lib/Transforms/Scalar/Reassociate.cpp
parent22d06312a903be84ff9ec6ad64500e5ed24a0c94 (diff)
Implement Reassociate/mul-neg-add.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21788 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/Reassociate.cpp')
-rw-r--r--lib/Transforms/Scalar/Reassociate.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp
index 592df535af..af0c6118a2 100644
--- a/lib/Transforms/Scalar/Reassociate.cpp
+++ b/lib/Transforms/Scalar/Reassociate.cpp
@@ -614,6 +614,18 @@ void Reassociate::ReassociateBB(BasicBlock *BB) {
// sorted form, optimize it globally if possible.
OptimizeExpression(I->getOpcode(), Ops);
+ // We want to sink immediates as deeply as possible except in the case where
+ // this is a multiply tree used only by an add, and the immediate is a -1.
+ // In this case we reassociate to put the negation on the outside so that we
+ // can fold the negation into the add: (-X)*Y + Z -> Z-X*Y
+ if (I->getOpcode() == Instruction::Mul && I->hasOneUse() &&
+ cast<Instruction>(I->use_back())->getOpcode() == Instruction::Add &&
+ isa<ConstantInt>(Ops.back().Op) &&
+ cast<ConstantInt>(Ops.back().Op)->isAllOnesValue()) {
+ Ops.insert(Ops.begin(), Ops.back());
+ Ops.pop_back();
+ }
+
DEBUG(std::cerr << "RAOut:\t"; PrintOps(I->getOpcode(), Ops, BB);
std::cerr << "\n");