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

Chris Lattner lattner at cs.uiuc.edu
Thu Sep 1 23:38:16 PDT 2005



Changes in directory llvm/lib/Transforms/Scalar:

Reassociate.cpp updated: 1.53 -> 1.54
---
Log message:

Avoid creating garbage instructions, just move the old add instruction
to where we need it when converting -(A+B+C) -> -A + -B + -C.


---
Diffs of the changes:  (+11 -9)

 Reassociate.cpp |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)


Index: llvm/lib/Transforms/Scalar/Reassociate.cpp
diff -u llvm/lib/Transforms/Scalar/Reassociate.cpp:1.53 llvm/lib/Transforms/Scalar/Reassociate.cpp:1.54
--- llvm/lib/Transforms/Scalar/Reassociate.cpp:1.53	Fri Sep  2 00:23:22 2005
+++ llvm/lib/Transforms/Scalar/Reassociate.cpp	Fri Sep  2 01:38:04 2005
@@ -318,16 +318,18 @@
   //
   if (Instruction *I = dyn_cast<Instruction>(V))
     if (I->getOpcode() == Instruction::Add && I->hasOneUse()) {
-      Value *RHS = NegateValue(I->getOperand(1), BI);
-      Value *LHS = NegateValue(I->getOperand(0), BI);
-
-      // We must actually insert a new add instruction here, because the neg
-      // instructions do not dominate the old add instruction in general.  By
-      // adding it now, we are assured that the neg instructions we just
-      // inserted dominate the instruction we are about to insert after them.
+      // Push the negates through the add.
+      I->setOperand(0, NegateValue(I->getOperand(0), BI));
+      I->setOperand(1, NegateValue(I->getOperand(1), BI));
+
+      // We must move the add instruction here, because the neg instructions do
+      // not dominate the old add instruction in general.  By moving it, we are
+      // assured that the neg instructions we just inserted dominate the 
+      // instruction we are about to insert after them.
       //
-      return BinaryOperator::create(Instruction::Add, LHS, RHS,
-                                    I->getName()+".neg", BI);
+      I->moveBefore(BI);
+      I->setName(I->getName()+".neg");
+      return I;
     }
 
   // Insert a 'neg' instruction that subtracts the value from zero to get the






More information about the llvm-commits mailing list