forked from OSchip/llvm-project
Make ConstantFoldTerminator() handle switches with unreachable default.
Tested by Transforms/SimplifyCFG/switch-to-br.ll's @unreachable function. Differential Revision: http://reviews.llvm.org/D6471 llvm-svn: 227124
This commit is contained in:
parent
d4d2e9bd0e
commit
90b827cae2
|
@ -110,11 +110,17 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
|
|||
}
|
||||
|
||||
if (SwitchInst *SI = dyn_cast<SwitchInst>(T)) {
|
||||
// If we are switching on a constant, we can convert the switch into a
|
||||
// single branch instruction!
|
||||
// If we are switching on a constant, we can convert the switch to an
|
||||
// unconditional branch.
|
||||
ConstantInt *CI = dyn_cast<ConstantInt>(SI->getCondition());
|
||||
BasicBlock *TheOnlyDest = SI->getDefaultDest();
|
||||
BasicBlock *DefaultDest = TheOnlyDest;
|
||||
BasicBlock *DefaultDest = SI->getDefaultDest();
|
||||
BasicBlock *TheOnlyDest = DefaultDest;
|
||||
|
||||
// If the default is unreachable, ignore it when searching for TheOnlyDest.
|
||||
if (isa<UnreachableInst>(DefaultDest->getFirstNonPHIOrDbg()) &&
|
||||
SI->getNumCases() > 0) {
|
||||
TheOnlyDest = SI->case_begin().getCaseSuccessor();
|
||||
}
|
||||
|
||||
// Figure out which case it goes to.
|
||||
for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end();
|
||||
|
|
Loading…
Reference in New Issue