SamplePGO - Fix default threshold for hot callsites.
authorDiego Novillo <dnovillo@google.com>
Fri, 27 Nov 2015 23:14:49 +0000 (23:14 +0000)
committerDiego Novillo <dnovillo@google.com>
Fri, 27 Nov 2015 23:14:49 +0000 (23:14 +0000)
Based on testing of internal benchmarks, I'm lowering this threshold to
a value of 0.1%.  This means that SamplePGO will respect 99.9% of the
original inline decisions when following a profile.

The performance difference is noticeable in some tests. With the
previous threshold, the speedups over baseline -O2 was about 0.63%. With
the new default, the speedups are around 3% on average.

The point of this threshold is not to do more aggressive inlining. When
an inlined callsite crosses this threshold, SamplePGO will redo the
inline decision so that it can better apply the input profile.

By respecting most original inline decisions, we can apply more of the
input profile because the shape of the code follows the profile more
closely.

In the next series, I'll be looking at adding some inline hints for the
cold callsites and for toplevel functions that are hot/cold as well.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254211 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/SampleProfile.cpp

index 1f18fb76aea75c8a09e748fc52992e7686be824e..69194eac078557ba9f61f8b43a5e4b692b552443 100644 (file)
@@ -71,8 +71,8 @@ static cl::opt<unsigned> SampleProfileSampleCoverage(
     "sample-profile-check-sample-coverage", cl::init(0), cl::value_desc("N"),
     cl::desc("Emit a warning if less than N% of samples in the input profile "
              "are matched to the IR."));
-static cl::opt<unsigned> SampleProfileHotThreshold(
-    "sample-profile-inline-hot-threshold", cl::init(5), cl::value_desc("N"),
+static cl::opt<double> SampleProfileHotThreshold(
+    "sample-profile-inline-hot-threshold", cl::init(0.1), cl::value_desc("N"),
     cl::desc("Inlined functions that account for more than N% of all samples "
              "collected in the parent function, will be inlined again."));
 
@@ -262,7 +262,8 @@ bool callsiteIsHot(const FunctionSamples *CallerFS,
   if (CallsiteTotalSamples == 0)
     return false; // Callsite is trivially cold.
 
-  uint64_t PercentSamples = CallsiteTotalSamples * 100 / ParentTotalSamples;
+  double PercentSamples =
+      (double)CallsiteTotalSamples / (double)ParentTotalSamples * 100.0;
   return PercentSamples >= SampleProfileHotThreshold;
 }