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

Chris Lattner lattner at cs.uiuc.edu
Tue Aug 9 17:35:43 PDT 2005



Changes in directory llvm/lib/Transforms/Scalar:

LoopStrengthReduce.cpp updated: 1.45 -> 1.46
---
Log message:

Fix Regression/Transforms/LoopStrengthReduce/phi_node_update_multiple_preds.ll
by being more careful about updating PHI nodes


---
Diffs of the changes:  (+14 -7)

 LoopStrengthReduce.cpp |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)


Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.45 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.46
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.45	Tue Aug  9 18:39:36 2005
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp	Tue Aug  9 19:35:32 2005
@@ -423,21 +423,28 @@
   }
   
   // PHI nodes are more complex.  We have to insert one copy of the NewBase+Imm
-  // expression into each operand block that uses it.
+  // expression into each operand block that uses it.  Note that PHI nodes can
+  // have multiple entries for the same predecessor.  We use a map to make sure
+  // that a PHI node only has a single Value* for each predecessor (which also
+  // prevents us from inserting duplicate code in some blocks).
+  std::map<BasicBlock*, Value*> InsertedCode;
   PHINode *PN = cast<PHINode>(Inst);
   for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
     if (PN->getIncomingValue(i) == OperandValToReplace) {
       // FIXME: this should split any critical edges.
 
-      // Insert the code into the end of the predecessor block.
-      BasicBlock::iterator InsertPt = PN->getIncomingBlock(i)->getTerminator();
+      Value *&Code = InsertedCode[PN->getIncomingBlock(i)];
+      if (!Code) {
+        // Insert the code into the end of the predecessor block.
+        BasicBlock::iterator InsertPt =PN->getIncomingBlock(i)->getTerminator();
       
-      SCEVHandle NewValSCEV = SCEVAddExpr::get(NewBase, Imm);
-      Value *NewVal = Rewriter.expandCodeFor(NewValSCEV, InsertPt,
-                                             OperandValToReplace->getType());
+        SCEVHandle NewValSCEV = SCEVAddExpr::get(NewBase, Imm);
+        Code = Rewriter.expandCodeFor(NewValSCEV, InsertPt,
+                                      OperandValToReplace->getType());
+      }
       
       // Replace the use of the operand Value with the new Phi we just created.
-      PN->setIncomingValue(i, NewVal);
+      PN->setIncomingValue(i, Code);
       Rewriter.clear();
     }
   }






More information about the llvm-commits mailing list