mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-28 06:32:09 +00:00
Fix the predecessor removal logic in r193045.
Additionally some small comment/stylistic fixes are included as well. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193068 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3e033f2923
commit
6701bb7283
@ -3741,18 +3741,20 @@ static bool SwitchToLookupTable(SwitchInst *SI,
|
|||||||
|
|
||||||
// Compute the maximum table size representable by the integer type we are
|
// Compute the maximum table size representable by the integer type we are
|
||||||
// switching upon.
|
// switching upon.
|
||||||
const unsigned CaseSize = MinCaseVal->getType()->getPrimitiveSizeInBits();
|
unsigned CaseSize = MinCaseVal->getType()->getPrimitiveSizeInBits();
|
||||||
const uint64_t MaxTableSize = CaseSize > 63? UINT64_MAX : 1ULL << CaseSize;
|
uint64_t MaxTableSize = CaseSize > 63? UINT64_MAX : 1ULL << CaseSize;
|
||||||
assert(MaxTableSize >= TableSize &&
|
assert(MaxTableSize >= TableSize &&
|
||||||
"It is impossible for a switch to have more entries than the max "
|
"It is impossible for a switch to have more entries than the max "
|
||||||
"representable value of its input integer type's size.");
|
"representable value of its input integer type's size.");
|
||||||
|
|
||||||
// If we have a covered lookup table, unconditionally branch to the lookup table
|
// If we have a fully covered lookup table, unconditionally branch to the
|
||||||
// BB. Otherwise, check if the condition value is within the case range. If it
|
// lookup table BB. Otherwise, check if the condition value is within the case
|
||||||
// is so, branch to the new BB. Otherwise branch to SI's default destination.
|
// range. If it is so, branch to the new BB. Otherwise branch to SI's default
|
||||||
|
// destination.
|
||||||
const bool GeneratingCoveredLookupTable = MaxTableSize == TableSize;
|
const bool GeneratingCoveredLookupTable = MaxTableSize == TableSize;
|
||||||
if (GeneratingCoveredLookupTable) {
|
if (GeneratingCoveredLookupTable) {
|
||||||
Builder.CreateBr(LookupBB);
|
Builder.CreateBr(LookupBB);
|
||||||
|
SI->getDefaultDest()->removePredecessor(SI->getParent());
|
||||||
} else {
|
} else {
|
||||||
Value *Cmp = Builder.CreateICmpULT(TableIndex, ConstantInt::get(
|
Value *Cmp = Builder.CreateICmpULT(TableIndex, ConstantInt::get(
|
||||||
MinCaseVal->getType(), TableSize));
|
MinCaseVal->getType(), TableSize));
|
||||||
@ -3786,14 +3788,10 @@ static bool SwitchToLookupTable(SwitchInst *SI,
|
|||||||
Builder.CreateBr(CommonDest);
|
Builder.CreateBr(CommonDest);
|
||||||
|
|
||||||
// Remove the switch.
|
// 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);
|
BasicBlock *Succ = SI->getSuccessor(i);
|
||||||
|
|
||||||
// If we are not generating a covered lookup table, we will have a
|
if (Succ == SI->getDefaultDest())
|
||||||
// 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)
|
|
||||||
continue;
|
continue;
|
||||||
Succ->removePredecessor(SI->getParent());
|
Succ->removePredecessor(SI->getParent());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user