Index: lib/Transforms/Utils/LowerSwitch.cpp =================================================================== --- lib/Transforms/Utils/LowerSwitch.cpp +++ lib/Transforms/Utils/LowerSwitch.cpp @@ -78,7 +78,7 @@ typedef std::vector CaseVector; typedef std::vector::iterator CaseItr; private: - void processSwitchInst(SwitchInst *SI, SmallVectorImpl &DeleteList); + void processSwitchInst(SwitchInst *SI, SmallPtrSetImpl &DeleteList); BasicBlock *switchConvert(CaseItr Begin, CaseItr End, ConstantInt *LowerBound, ConstantInt *UpperBound, @@ -116,11 +116,17 @@ bool LowerSwitch::runOnFunction(Function &F) { bool Changed = false; - SmallVector DeleteList; + SmallPtrSet DeleteList; for (Function::iterator I = F.begin(), E = F.end(); I != E; ) { BasicBlock *Cur = I++; // Advance over block so we don't traverse new blocks + // If the block is a dead Default block that will be deleted later, don't + // waste time processing it. + if (DeleteList.count(Cur)) { + continue; + } + if (SwitchInst *SI = dyn_cast(Cur->getTerminator())) { Changed = true; processSwitchInst(SI, DeleteList); @@ -402,7 +408,7 @@ // processSwitchInst - Replace the specified switch instruction with a sequence // of chained if-then insts in a balanced binary search. // -void LowerSwitch::processSwitchInst(SwitchInst *SI, SmallVectorImpl &DeleteList) { +void LowerSwitch::processSwitchInst(SwitchInst *SI, SmallPtrSetImpl &DeleteList) { BasicBlock *CurBlock = SI->getParent(); BasicBlock *OrigBlock = CurBlock; Function *F = CurBlock->getParent(); @@ -525,5 +531,5 @@ // If the Default block has no more predecessors just add it to DeleteList. if (pred_begin(OldDefault) == pred_end(OldDefault)) - DeleteList.push_back(OldDefault); + DeleteList.insert(OldDefault); }