summaryrefslogtreecommitdiffstats
path: root/llvm/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
commitdf3332660f55e32cbc20a457e13cdb8dc2fbaecf (patch)
treea0105a7d01ebc762fab0837990c0965a0970d35f /llvm/lib/Transforms/Scalar/Reassociate.cpp
parentce7d145b20c422e52af4e4d8b8c98a4a229fd6e9 (diff)
downloadbcm5719-llvm-df3332660f55e32cbc20a457e13cdb8dc2fbaecf.tar.gz
bcm5719-llvm-df3332660f55e32cbc20a457e13cdb8dc2fbaecf.zip
Implement Reassociate/mul-neg-add.ll
llvm-svn: 21788
Diffstat (limited to 'llvm/lib/Transforms/Scalar/Reassociate.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/Reassociate.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index 592df535af7..af0c6118a27 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/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");
OpenPOWER on IntegriCloud