aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2012-09-26 11:07:37 +0000
committerHans Wennborg <hans@hanshq.net>2012-09-26 11:07:37 +0000
commit565df79b74126e1f2a2be8e2c55c5bb506270f26 (patch)
tree047c44b37634ebca9573ddbdc8e46ae5eda8bb05
parentd0ac06d18812dd1c20ad55f9324c550609138593 (diff)
downloadexternal_llvm-565df79b74126e1f2a2be8e2c55c5bb506270f26.zip
external_llvm-565df79b74126e1f2a2be8e2c55c5bb506270f26.tar.gz
external_llvm-565df79b74126e1f2a2be8e2c55c5bb506270f26.tar.bz2
Address Duncan's comments on r164682:
- Finish assert messages with exclamation mark - Move overflow checking into ShouldBuildLookupTable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164692 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp10
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 278292f..d7468a1 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3302,8 +3302,8 @@ SwitchLookupTable::SwitchLookupTable(Module &M,
const SmallVector<std::pair<ConstantInt*, Constant*>, 4>& Values,
Constant *DefaultValue,
const TargetData *TD) {
- assert(Values.size() && "Can't build lookup table without values.");
- assert(TableSize >= Values.size() && "Can't fit values in table.");
+ assert(Values.size() && "Can't build lookup table without values!");
+ assert(TableSize >= Values.size() && "Can't fit values in table!");
// If all values in the table are equal, this is that value.
SingleValue = Values.begin()->second;
@@ -3431,6 +3431,8 @@ static bool ShouldBuildLookupTable(SwitchInst *SI,
// 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;
@@ -3513,10 +3515,6 @@ static bool SwitchToLookupTable(SwitchInst *SI,
}
APInt RangeSpread = MaxCaseVal->getValue() - MinCaseVal->getValue();
- // Be careful to avoid overflow when TableSize is used in
- // ShouldBuildLookupTable.
- if (RangeSpread.zextOrSelf(64).ugt(UINT64_MAX / 4 - 1))
- return false;
uint64_t TableSize = RangeSpread.getLimitedValue() + 1;
if (!ShouldBuildLookupTable(SI, TableSize, TD, ResultTypes))
return false;