diff options
author | Hans Wennborg <hans@hanshq.net> | 2015-01-26 19:52:34 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2015-01-26 19:52:34 +0000 |
commit | b64cb271dced24f1cabf7a33c29240a551b888d4 (patch) | |
tree | 5472d3061ec62611c84e9db5c0bd520496d8184f /llvm/lib/Transforms/Utils | |
parent | 6800008f049f4c33ec42acfd7055b82ed38d7559 (diff) | |
download | bcm5719-llvm-b64cb271dced24f1cabf7a33c29240a551b888d4.tar.gz bcm5719-llvm-b64cb271dced24f1cabf7a33c29240a551b888d4.zip |
SimplifyCFG: Omit range checks for switch lookup tables when default is unreachable
The range check would get optimized away later, but we might as well not emit
them in the first place.
http://reviews.llvm.org/D6471
llvm-svn: 227126
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 0b9568b91dc..364eeca70d7 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -4182,19 +4182,20 @@ static bool SwitchToLookupTable(SwitchInst *SI, "It is impossible for a switch to have more entries than the max " "representable value of its input integer type's size."); - // If we have a fully covered lookup table, unconditionally branch to the - // lookup table BB. Otherwise, check if the condition value is within the case - // range. If it is so, branch to the new BB. Otherwise branch to SI's default - // destination. + // If the default destination is unreachable, or if the lookup table covers + // all values of the conditional variable, branch directly to the lookup table + // BB. Otherwise, check that the condition is within the case range. + const bool DefaultIsReachable = + !isa<UnreachableInst>(SI->getDefaultDest()->getFirstNonPHIOrDbg()); + const bool GeneratingCoveredLookupTable = (MaxTableSize == TableSize); BranchInst *RangeCheckBranch = nullptr; - const bool GeneratingCoveredLookupTable = MaxTableSize == TableSize; - if (GeneratingCoveredLookupTable) { + if (!DefaultIsReachable || GeneratingCoveredLookupTable) { Builder.CreateBr(LookupBB); // We cached PHINodes in PHIs, to avoid accessing deleted PHINodes later, // do not delete PHINodes here. SI->getDefaultDest()->removePredecessor(SI->getParent(), - true/*DontDeleteUselessPHIs*/); + /*DontDeleteUselessPHIs=*/true); } else { Value *Cmp = Builder.CreateICmpULT(TableIndex, ConstantInt::get( MinCaseVal->getType(), TableSize)); |