[llvm-commits] [llvm] r159451 - /llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp

Duncan Sands baldrick at free.fr
Fri Jun 29 12:03:05 PDT 2012


Author: baldrick
Date: Fri Jun 29 14:03:05 2012
New Revision: 159451

URL: http://llvm.org/viewvc/llvm-project?rev=159451&view=rev
Log:
Rework this to clarify where the removal of nodes from the queue is
really happening.  No intended functionality change.

Modified:
    llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp?rev=159451&r1=159450&r2=159451&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp Fri Jun 29 14:03:05 2012
@@ -667,15 +667,13 @@
   /// the new expression into.
   SmallVector<BinaryOperator*, 8> NodesToRewrite;
   unsigned Opcode = I->getOpcode();
-  NodesToRewrite.push_back(I);
+  BinaryOperator *Op = I;
 
   // ExpressionChanged - Non-null if the rewritten expression differs from the
   // original in some non-trivial way, requiring the clearing of optional flags.
   // Flags are cleared from the operator in ExpressionChanged up to I inclusive.
   BinaryOperator *ExpressionChanged = 0;
   for (unsigned i = 0; ; ++i) {
-    BinaryOperator *Op = NodesToRewrite.pop_back_val();
-
     // The last operation (which comes earliest in the IR) is special as both
     // operands will come from Ops, rather than just one with the other being
     // a subexpression.
@@ -746,7 +744,7 @@
     // from the original expression then just rewrite the rest of the expression
     // into it.
     if (BinaryOperator *BO = isReassociableOp(Op->getOperand(0), Opcode)) {
-      NodesToRewrite.push_back(BO);
+      Op = BO;
       continue;
     }
 
@@ -757,19 +755,22 @@
     // hard (finding the mimimal number of multiplications needed to realize a
     // multiplication expression is NP-complete).  Whatever the reason, smart or
     // stupid, create a new node if there are none left.
+    BinaryOperator *NewOp;
     if (NodesToRewrite.empty()) {
       Constant *Undef = UndefValue::get(I->getType());
-      BinaryOperator *N = BinaryOperator::Create(Instruction::BinaryOps(Opcode),
-                                                 Undef, Undef, "", I);
-      NodesToRewrite.push_back(N);
+      NewOp = BinaryOperator::Create(Instruction::BinaryOps(Opcode),
+                                     Undef, Undef, "", I);
+    } else {
+      NewOp = NodesToRewrite.pop_back_val();
     }
 
     DEBUG(dbgs() << "RA: " << *Op << '\n');
-    Op->setOperand(0, NodesToRewrite.back());
+    Op->setOperand(0, NewOp);
     DEBUG(dbgs() << "TO: " << *Op << '\n');
     ExpressionChanged = Op;
     MadeChange = true;
     ++NumChanged;
+    Op = NewOp;
   }
 
   // If the expression changed non-trivially then clear out all subclass data





More information about the llvm-commits mailing list