diff options
author | Hans Wennborg <hans@hanshq.net> | 2015-01-26 19:52:24 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2015-01-26 19:52:24 +0000 |
commit | 90b827cae2d3b94d8794874cfe01a9d8fbf7c55b (patch) | |
tree | e10faa4a9a828f8d62d26f80799096cde2dd7a36 /llvm/lib/Transforms | |
parent | d4d2e9bd0ec19cd7fc759d3179aa23d870568142 (diff) | |
download | bcm5719-llvm-90b827cae2d3b94d8794874cfe01a9d8fbf7c55b.tar.gz bcm5719-llvm-90b827cae2d3b94d8794874cfe01a9d8fbf7c55b.zip |
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
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index a6bdc7f7b83..b54c87ac319 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -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(); |