[llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Chris Lattner lattner at cs.uiuc.edu
Sun May 2 00:02:02 PDT 2004


Changes in directory llvm/lib/Transforms/Utils:

SimplifyCFG.cpp updated: 1.39 -> 1.40

---
Log message:

Do not infinitely "unroll" single BB loops.


---
Diffs of the changes:  (+4 -5)

Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.39 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.40
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.39	Sat May  1 20:00:44 2004
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp	Sun May  2 00:02:03 2004
@@ -804,12 +804,12 @@
       // If this basic block is ONLY a setcc and a branch, and if a predecessor
       // branches to us and one of our successors, fold the setcc into the
       // predecessor and use logical operations to pick the right destination.
+      BasicBlock *TrueDest  = BI->getSuccessor(0);
+      BasicBlock *FalseDest = BI->getSuccessor(1);
       if (Instruction *Cond = dyn_cast<Instruction>(BI->getCondition()))
         if (Cond->getParent() == BB && &BB->front() == Cond &&
-            Cond->getNext() == BI && Cond->hasOneUse()) {
-          BasicBlock *TrueDest  = BI->getSuccessor(0);
-          BasicBlock *FalseDest = BI->getSuccessor(1);
-
+            Cond->getNext() == BI && Cond->hasOneUse() &&
+            TrueDest != BB && FalseDest != BB)
           for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI!=E; ++PI)
             if (BranchInst *PBI = dyn_cast<BranchInst>((*PI)->getTerminator()))
               if (PBI->isConditional() && SafeToMergeTerminators(BI, PBI)) {
@@ -853,7 +853,6 @@
                   return SimplifyCFG(BB) | 1;
                 }
               }
-        }
 
       // If this block ends with a branch instruction, and if there is one
       // predecessor, see if the previous block ended with a branch on the same





More information about the llvm-commits mailing list