diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-06-26 20:32:52 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-06-26 20:32:52 +0000 | 
| commit | 08bbd35a80bf7765fe0d3043f9eb5a2f2786b649 (patch) | |
| tree | 80108f0f128657f8623f8f66ad9735b4d88e7b47 /lib/Analysis/InlineCost.cpp | |
| parent | 7c7aba6e5fef47a01a136be655b0a92cfd7090f6 (diff) | |
Notes
Diffstat (limited to 'lib/Analysis/InlineCost.cpp')
| -rw-r--r-- | lib/Analysis/InlineCost.cpp | 16 | 
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/Analysis/InlineCost.cpp b/lib/Analysis/InlineCost.cpp index 6ff5938a3175a..77ad6f1e166fd 100644 --- a/lib/Analysis/InlineCost.cpp +++ b/lib/Analysis/InlineCost.cpp @@ -1022,12 +1022,15 @@ bool CallAnalyzer::visitSwitchInst(SwitchInst &SI) {    // inlining those. It will prevent inlining in cases where the optimization    // does not (yet) fire. +  // Maximum valid cost increased in this function. +  int CostUpperBound = INT_MAX - InlineConstants::InstrCost - 1; +    // Exit early for a large switch, assuming one case needs at least one    // instruction.    // FIXME: This is not true for a bit test, but ignore such case for now to    // save compile-time.    int64_t CostLowerBound = -      std::min((int64_t)INT_MAX, +      std::min((int64_t)CostUpperBound,                 (int64_t)SI.getNumCases() * InlineConstants::InstrCost + Cost);    if (CostLowerBound > Threshold) { @@ -1044,7 +1047,8 @@ bool CallAnalyzer::visitSwitchInst(SwitchInst &SI) {    if (JumpTableSize) {      int64_t JTCost = (int64_t)JumpTableSize * InlineConstants::InstrCost +                       4 * InlineConstants::InstrCost; -    Cost = std::min((int64_t)INT_MAX, JTCost + Cost); + +    Cost = std::min((int64_t)CostUpperBound, JTCost + Cost);      return false;    } @@ -1068,10 +1072,12 @@ bool CallAnalyzer::visitSwitchInst(SwitchInst &SI) {      Cost += NumCaseCluster * 2 * InlineConstants::InstrCost;      return false;    } -  int64_t ExpectedNumberOfCompare = 3 * (uint64_t)NumCaseCluster / 2 - 1; -  uint64_t SwitchCost = + +  int64_t ExpectedNumberOfCompare = 3 * (int64_t)NumCaseCluster / 2 - 1; +  int64_t SwitchCost =        ExpectedNumberOfCompare * 2 * InlineConstants::InstrCost; -  Cost = std::min((uint64_t)INT_MAX, SwitchCost + Cost); + +  Cost = std::min((int64_t)CostUpperBound, SwitchCost + Cost);    return false;  }  | 
