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

Chris Lattner lattner at cs.uiuc.edu
Tue Dec 9 17:14:01 PST 2003


Changes in directory llvm/lib/Transforms/Scalar:

LoopSimplify.cpp updated: 1.26 -> 1.27

---
Log message:

Do not insert one entry PHI nodes in split exit blocks!


---
Diffs of the changes:  (+23 -13)

Index: llvm/lib/Transforms/Scalar/LoopSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.26 llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.27
--- llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.26	Fri Nov 21 10:52:01 2003
+++ llvm/lib/Transforms/Scalar/LoopSimplify.cpp	Tue Dec  9 17:12:55 2003
@@ -162,21 +162,31 @@
   // incoming edges in BB into new PHI nodes in NewBB.
   //
   if (!Preds.empty()) {  // Is the loop not obviously dead?
-    for (BasicBlock::iterator I = BB->begin();
-         PHINode *PN = dyn_cast<PHINode>(I); ++I) {
-      
-      // Create the new PHI node, insert it into NewBB at the end of the block
-      PHINode *NewPHI = new PHINode(PN->getType(), PN->getName()+".ph", BI);
+    if (Preds.size() == 1) {
+      // No need to insert one operand PHI nodes!  Instead, just update the
+      // incoming block ID's.
+      for (BasicBlock::iterator I = BB->begin();
+           PHINode *PN = dyn_cast<PHINode>(I); ++I) {
+        unsigned i = PN->getBasicBlockIndex(Preds[0]);
+        PN->setIncomingBlock(i, NewBB);
+      }
+    } else {
+      for (BasicBlock::iterator I = BB->begin();
+           PHINode *PN = dyn_cast<PHINode>(I); ++I) {
+        
+        // Create the new PHI node, insert it into NewBB at the end of the block
+        PHINode *NewPHI = new PHINode(PN->getType(), PN->getName()+".ph", BI);
+        
+        // Move all of the edges from blocks outside the loop to the new PHI
+        for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
+          Value *V = PN->removeIncomingValue(Preds[i]);
+          NewPHI->addIncoming(V, Preds[i]);
+        }
         
-      // Move all of the edges from blocks outside the loop to the new PHI
-      for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
-        Value *V = PN->removeIncomingValue(Preds[i]);
-        NewPHI->addIncoming(V, Preds[i]);
+        // Add an incoming value to the PHI node in the loop for the preheader
+        // edge.
+        PN->addIncoming(NewPHI, NewBB);
       }
-      
-      // Add an incoming value to the PHI node in the loop for the preheader
-      // edge
-      PN->addIncoming(NewPHI, NewBB);
     }
     
     // Now that the PHI nodes are updated, actually move the edges from





More information about the llvm-commits mailing list