[llvm-commits] CVS: llvm/lib/Transforms/Scalar/Reassociate.cpp

Chris Lattner lattner at cs.uiuc.edu
Sun May 8 14:41:48 PDT 2005



Changes in directory llvm/lib/Transforms/Scalar:

Reassociate.cpp updated: 1.47 -> 1.48
---
Log message:

Implement Reassociate/mul-neg-add.ll


---
Diffs of the changes:  (+12 -0)

 Reassociate.cpp |   12 ++++++++++++
 1 files changed, 12 insertions(+)


Index: llvm/lib/Transforms/Scalar/Reassociate.cpp
diff -u llvm/lib/Transforms/Scalar/Reassociate.cpp:1.47 llvm/lib/Transforms/Scalar/Reassociate.cpp:1.48
--- llvm/lib/Transforms/Scalar/Reassociate.cpp:1.47	Sun May  8 16:33:47 2005
+++ llvm/lib/Transforms/Scalar/Reassociate.cpp	Sun May  8 16:41:35 2005
@@ -614,6 +614,18 @@
     // 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");
 






More information about the llvm-commits mailing list