Don't eliminate blocks that are only reachable by unwind_to.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48106 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 8e99dcc..6783607 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -10796,11 +10796,15 @@
 
     // Recursively visit successors.  If this is a branch or switch on a
     // constant, only visit the reachable successor.
+    if (BB->getUnwindDest())
+      Worklist.push_back(BB->getUnwindDest());
     TerminatorInst *TI = BB->getTerminator();
     if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
       if (BI->isConditional() && isa<ConstantInt>(BI->getCondition())) {
         bool CondVal = cast<ConstantInt>(BI->getCondition())->getZExtValue();
-        Worklist.push_back(BI->getSuccessor(!CondVal));
+        BasicBlock *ReachableBB = BI->getSuccessor(!CondVal);
+        if (ReachableBB != BB->getUnwindDest())
+          Worklist.push_back(ReachableBB);
         continue;
       }
     } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
@@ -10808,7 +10812,9 @@
         // See if this is an explicit destination.
         for (unsigned i = 1, e = SI->getNumSuccessors(); i != e; ++i)
           if (SI->getCaseValue(i) == Cond) {
-            Worklist.push_back(SI->getSuccessor(i));
+            BasicBlock *ReachableBB = SI->getSuccessor(i);
+            if (ReachableBB != BB->getUnwindDest())
+              Worklist.push_back(ReachableBB);
             continue;
           }