diff options
author | Evan Cheng <evan.cheng@apple.com> | 2012-11-30 02:02:42 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2012-11-30 02:02:42 +0000 |
commit | 40eef5fe361d8c528f764f66e311359d0da4d5b2 (patch) | |
tree | ec224ede67f35b9d89d8d87c5a73cd12cea6d19f /lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | a4eff77e37a59665b604cb8a644d66796b5622d4 (diff) |
Fix logic to determine whether to turn a switch into a lookup table. When
the tables cannot fit in registers (i.e. bitmap), do not emit the table
if it's using an illegal type.
rdar://12779436
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168970 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | lib/Transforms/Utils/SimplifyCFG.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 6c34eed13d..611e466719 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -3511,22 +3511,29 @@ bool SwitchLookupTable::WouldFitInRegister(const DataLayout *TD, static bool ShouldBuildLookupTable(SwitchInst *SI, uint64_t TableSize, const DataLayout *TD, + const TargetTransformInfo *TTI, const SmallDenseMap<PHINode*, Type*>& ResultTypes) { // The table density should be at least 40%. This is the same criterion as for // jump tables, see SelectionDAGBuilder::handleJTSwitchCase. // FIXME: Find the best cut-off. if (SI->getNumCases() > TableSize || TableSize >= UINT64_MAX / 10) return false; // TableSize overflowed, or mul below might overflow. - if (SI->getNumCases() * 10 >= TableSize * 4) - return true; // If each table would fit in a register, we should build it anyway. + bool AllFit = true; + bool HasIllegalType = false; for (SmallDenseMap<PHINode*, Type*>::const_iterator I = ResultTypes.begin(), E = ResultTypes.end(); I != E; ++I) { - if (!SwitchLookupTable::WouldFitInRegister(TD, TableSize, I->second)) - return false; + Type *Ty = I->second; + if (!TTI->getScalarTargetTransformInfo()->isTypeLegal(Ty)) + HasIllegalType = true; + if (!SwitchLookupTable::WouldFitInRegister(TD, TableSize, Ty)) { + AllFit = false; + break; + } } - return true; + + return AllFit || (!HasIllegalType && (SI->getNumCases() * 10 >= TableSize * 4)); } /// SwitchToLookupTable - If the switch is only used to initialize one or more @@ -3607,7 +3614,7 @@ static bool SwitchToLookupTable(SwitchInst *SI, APInt RangeSpread = MaxCaseVal->getValue() - MinCaseVal->getValue(); uint64_t TableSize = RangeSpread.getLimitedValue() + 1; - if (!ShouldBuildLookupTable(SI, TableSize, TD, ResultTypes)) + if (!ShouldBuildLookupTable(SI, TableSize, TD, TTI, ResultTypes)) return false; // Create the BB that does the lookups. |