[llvm-commits] [llvm] r164692 - /llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp

Hans Wennborg hans at hanshq.net
Wed Sep 26 04:07:38 PDT 2012


Author: hans
Date: Wed Sep 26 06:07:37 2012
New Revision: 164692

URL: http://llvm.org/viewvc/llvm-project?rev=164692&view=rev
Log:
Address Duncan's comments on r164682:

- Finish assert messages with exclamation mark
- Move overflow checking into ShouldBuildLookupTable.

Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=164692&r1=164691&r2=164692&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Wed Sep 26 06:07:37 2012
@@ -3302,8 +3302,8 @@
                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 @@
   // 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 @@
   }
 
   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;





More information about the llvm-commits mailing list