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

Chris Lattner sabre at nondot.org
Mon Oct 23 11:57:16 PDT 2006



Changes in directory llvm/lib/Transforms/Scalar:

SCCP.cpp updated: 1.134 -> 1.135
---
Log message:

Handle fallout from the recent branch-on-undef changes.  This fixes 
Prolangs-C/agrep and SCCP/2006-10-23-IPSCCP-Crash.ll


---
Diffs of the changes:  (+24 -1)

 SCCP.cpp |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/SCCP.cpp
diff -u llvm/lib/Transforms/Scalar/SCCP.cpp:1.134 llvm/lib/Transforms/Scalar/SCCP.cpp:1.135
--- llvm/lib/Transforms/Scalar/SCCP.cpp:1.134	Sun Oct 22 00:59:17 2006
+++ llvm/lib/Transforms/Scalar/SCCP.cpp	Mon Oct 23 13:57:02 2006
@@ -1360,7 +1360,30 @@
       while (!DeadBB->use_empty()) {
         Instruction *I = cast<Instruction>(DeadBB->use_back());
         bool Folded = ConstantFoldTerminator(I->getParent());
-        assert(Folded && "Didn't fold away reference to block!");
+        if (!Folded) {
+          // The constant folder may not have been able to fold the termiantor
+          // if this is a branch or switch on undef.  Fold it manually as a
+          // branch to the first successor.
+          if (BranchInst *BI = dyn_cast<BranchInst>(I)) {
+            assert(BI->isConditional() && isa<UndefValue>(BI->getCondition()) &&
+                   "Branch should be foldable!");
+          } else if (SwitchInst *SI = dyn_cast<SwitchInst>(I)) {
+            assert(isa<UndefValue>(SI->getCondition()) && "Switch should fold");
+          } else {
+            assert(0 && "Didn't fold away reference to block!");
+          }
+          
+          // Make this an uncond branch to the first successor.
+          TerminatorInst *TI = I->getParent()->getTerminator();
+          new BranchInst(TI->getSuccessor(0), TI);
+          
+          // Remove entries in successor phi nodes to remove edges.
+          for (unsigned i = 1, e = TI->getNumSuccessors(); i != e; ++i)
+            TI->getSuccessor(i)->removePredecessor(TI->getParent());
+          
+          // Remove the old terminator.
+          TI->eraseFromParent();
+        }
       }
 
       // Finally, delete the basic block.






More information about the llvm-commits mailing list