Index: lib/Transforms/Scalar/LoopUnswitch.cpp
===================================================================
--- lib/Transforms/Scalar/LoopUnswitch.cpp	(revision 153731)
+++ lib/Transforms/Scalar/LoopUnswitch.cpp	(working copy)
@@ -191,6 +191,10 @@
       loopHeader = currentLoop->getHeader();
       loopPreheader = currentLoop->getLoopPreheader();
     }
+    
+    /// HasIndirectBrsInPreds - Returns true if there are predecessors, that are
+    /// terminated with indirect branch instruction.    
+    bool HasIndirectBrsInPreds(const SmallVector<BasicBlock *, 8> &ExitBlocks);
 
     /// Split all of the edges from inside the loop to their exit blocks.
     /// Update the appropriate Phi nodes as we do so.
@@ -199,7 +203,7 @@
     bool UnswitchIfProfitable(Value *LoopCond, Constant *Val);
     void UnswitchTrivialCondition(Loop *L, Value *Cond, Constant *Val,
                                   BasicBlock *ExitBlock);
-    void UnswitchNontrivialCondition(Value *LIC, Constant *OnVal, Loop *L);
+    bool UnswitchNontrivialCondition(Value *LIC, Constant *OnVal, Loop *L);
 
     void RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC,
                                               Constant *Val, bool isEqual);
@@ -634,8 +638,7 @@
   if (OptimizeForSize || F->hasFnAttr(Attribute::OptimizeForSize))
     return false;
 
-  UnswitchNontrivialCondition(LoopCond, Val, currentLoop);
-  return true;
+  return UnswitchNontrivialCondition(LoopCond, Val, currentLoop);
 }
 
 /// CloneLoop - Recursively clone the specified loop and all of its children,
@@ -730,6 +733,23 @@
   ++NumTrivial;
 }
 
+/// HasIndirectBrsInPreds - Returns true if there are predecessors, that are
+/// terminated with indirect branch instruction.
+bool LoopUnswitch::HasIndirectBrsInPreds(
+    const SmallVector<BasicBlock *, 8> &ExitBlocks){
+  for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) {
+    BasicBlock *ExitBlock = ExitBlocks[i];
+    SmallVector<BasicBlock *, 4> Preds(pred_begin(ExitBlock),
+                                       pred_end(ExitBlock));
+    for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
+      // Cannot split an edge from an IndirectBrInst
+      if (isa<IndirectBrInst>(Preds[i]->getTerminator()))
+        return true;
+    }
+  }
+  return false;
+}
+
 /// SplitExitEdges - Split all of the edges from inside the loop to their exit
 /// blocks.  Update the appropriate Phi nodes as we do so.
 void LoopUnswitch::SplitExitEdges(Loop *L, 
@@ -755,7 +775,7 @@
 /// UnswitchNontrivialCondition - We determined that the loop is profitable 
 /// to unswitch when LIC equal Val.  Split it into loop versions and test the 
 /// condition outside of either loop.  Return the loops created as Out1/Out2.
-void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val, 
+bool LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val, 
                                                Loop *L) {
   Function *F = loopHeader->getParent();
   DEBUG(dbgs() << "loop-unswitch: Unswitching loop %"
@@ -779,6 +799,8 @@
 
   SmallVector<BasicBlock*, 8> ExitBlocks;
   L->getUniqueExitBlocks(ExitBlocks);
+  if (HasIndirectBrsInPreds(ExitBlocks))
+    return false;
 
   // Split all of the edges from inside the loop to their exit blocks.  Update
   // the appropriate Phi nodes as we do so.
@@ -893,6 +915,8 @@
   if (!LoopProcessWorklist.empty() && LoopProcessWorklist.back() == NewLoop &&
       LICHandle && !isa<Constant>(LICHandle))
     RewriteLoopBodyWithConditionConstant(NewLoop, LICHandle, Val, true);
+  
+  return true;
 }
 
 /// RemoveFromWorklist - Remove all instances of I from the worklist vector
