summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorMichael Gottesman <mgottesman@apple.com>2013-10-21 05:20:11 +0000
committerMichael Gottesman <mgottesman@apple.com>2013-10-21 05:20:11 +0000
commit63c63ac21ebd0d70b6e4c10ce8520934f4b3b26e (patch)
tree5b4cfb25a6a77fae1d0bc740b1ca69036e382d2b /llvm/lib/Transforms/Utils/SimplifyCFG.cpp
parent535351305825b1896ce3970d606680addaa0942c (diff)
downloadbcm5719-llvm-63c63ac21ebd0d70b6e4c10ce8520934f4b3b26e.tar.gz
bcm5719-llvm-63c63ac21ebd0d70b6e4c10ce8520934f4b3b26e.zip
Fix the predecessor removal logic in r193045.
Additionally some small comment/stylistic fixes are included as well. llvm-svn: 193068
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index ad3b92a7147..61c44fc4b2e 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3741,18 +3741,20 @@ static bool SwitchToLookupTable(SwitchInst *SI,
// Compute the maximum table size representable by the integer type we are
// switching upon.
- const unsigned CaseSize = MinCaseVal->getType()->getPrimitiveSizeInBits();
- const uint64_t MaxTableSize = CaseSize > 63? UINT64_MAX : 1ULL << CaseSize;
+ unsigned CaseSize = MinCaseVal->getType()->getPrimitiveSizeInBits();
+ uint64_t MaxTableSize = CaseSize > 63? UINT64_MAX : 1ULL << CaseSize;
assert(MaxTableSize >= TableSize &&
"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 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 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.
const bool GeneratingCoveredLookupTable = MaxTableSize == TableSize;
if (GeneratingCoveredLookupTable) {
Builder.CreateBr(LookupBB);
+ SI->getDefaultDest()->removePredecessor(SI->getParent());
} else {
Value *Cmp = Builder.CreateICmpULT(TableIndex, ConstantInt::get(
MinCaseVal->getType(), TableSize));
@@ -3786,14 +3788,10 @@ static bool SwitchToLookupTable(SwitchInst *SI,
Builder.CreateBr(CommonDest);
// Remove the switch.
- for (unsigned i = 0; i < SI->getNumSuccessors(); ++i) {
+ for (unsigned i = 0, e = SI->getNumSuccessors(); i < e; ++i) {
BasicBlock *Succ = SI->getSuccessor(i);
- // If we are not generating a covered lookup table, we will have a
- // conditional branch from SI's parent BB to SI's default destination if our
- // input value lies outside of our case range. Thus in that case leave the
- // default destination BB as a predecessor of SI's parent BB.
- if (Succ == SI->getDefaultDest() && !GeneratingCoveredLookupTable)
+ if (Succ == SI->getDefaultDest())
continue;
Succ->removePredecessor(SI->getParent());
}
OpenPOWER on IntegriCloud