predict.c (tree_predict_by_opcode): Get the probability for builtin_expect from param...
authorRong Xu <xur@google.com>
Thu, 3 Oct 2013 17:13:50 +0000 (17:13 +0000)
committerRong Xu <xur@gcc.gnu.org>
Thu, 3 Oct 2013 17:13:50 +0000 (17:13 +0000)
        * predict.c (tree_predict_by_opcode): Get the probability
        for builtin_expect from param builtin_expect_probability.
        * params.def (BUILTIN_EXPECT_PROBABILITY): New parameter.
        * predict.def (PRED_BUILTIN_EXPECT_RELAXED): Fix comments.
        * doc/invoke.texi: Add documentation for builtin-expect-probability.
        * gcc.target/i386/cold-attribute-2.c: Fix the test by using original
        probability.
        * gcc.dg/tree-ssa/ipa-split-5.c: Ditto.
        * gcc.dg/tree-ssa/ipa-split-6.c: Ditto.

--This li (t)ene, and those below, will be ignored--

M    gcc/params.def
M    gcc/predict.def
M    gcc/ChangeLog
M    gcc/testsuite/gcc.dg/tree-ssa/ipa-split-5.c
M    gcc/testsuite/gcc.dg/tree-ssa/ipa-split-6.c
M    gcc/testsuite/gcc.target/i386/cold-attribute-2.c
M    gcc/predict.c
M    gcc/doc/invoke.texi

From-SVN: r203167

gcc/ChangeLog
gcc/doc/invoke.texi
gcc/params.def
gcc/predict.c
gcc/predict.def
gcc/testsuite/gcc.dg/tree-ssa/ipa-split-5.c
gcc/testsuite/gcc.dg/tree-ssa/ipa-split-6.c
gcc/testsuite/gcc.target/i386/cold-attribute-2.c

index e7e28363180f32e1ef50e157a08006d8960c92f3..c5ffb64ff05e91171e566df8f8155f0054875468 100644 (file)
@@ -1,3 +1,15 @@
+2013-10-03  Rong Xu  <xur@google.com>
+
+        * predict.c (tree_predict_by_opcode): Get the probability
+        for builtin_expect from param builtin_expect_probability.
+        * params.def (BUILTIN_EXPECT_PROBABILITY): New parameter.
+        * predict.def (PRED_BUILTIN_EXPECT_RELAXED): Fix comments.
+        * doc/invoke.texi: Add documentation for builtin-expect-probability.
+        * gcc.target/i386/cold-attribute-2.c: Fix the test by using original
+        probability.
+        * gcc.dg/tree-ssa/ipa-split-5.c: Ditto.
+        * gcc.dg/tree-ssa/ipa-split-6.c: Ditto.
+
 2013-10-03  Marc Glisse  <marc.glisse@inria.fr>
 
        PR c++/19476
index 6e3192f3cd08dc2aec05ee7ca38559b12bea22f1..0f32c24f15fd4e50538a141f85648de5ccf91212 100644 (file)
@@ -9491,6 +9491,11 @@ The known number of iterations is predicted correctly, while
 the unknown number of iterations average to roughly 10.  This means that the
 loop without bounds appears artificially cold relative to the other one.
 
+@item builtin-expect-probability
+Control the probability of the expression having the specified value. This
+parameter takes a percentage (i.e. 0 ... 100) as input.
+The default probability of 90 is obtained empirically.
+
 @item align-threshold
 
 Select fraction of the maximal frequency of executions of a basic block in
index 27491378d118d04d338c37f5050e63ce5ce7e34f..ff9ba9a8abcc6dc2148e498464aabd56096f7f0e 100644 (file)
@@ -398,6 +398,19 @@ DEFPARAM(PARAM_MAX_PREDICTED_ITERATIONS,
         "max-predicted-iterations",
         "The maximum number of loop iterations we predict statically",
         100, 0, 0)
+
+/* This parameter controls the probability of builtin_expect. The default
+   value is 90%. This empirical value is obtained through the weighted
+   probability of FDO counters (with the FDO count value as the weight)
+   in some real world programs:  
+   (1) Google performance test benchmarks: the probability is 0.9081.
+   (2) Linux 3.3 kernel running Google search workload: the probability
+   is 0.8717.  */
+
+DEFPARAM(BUILTIN_EXPECT_PROBABILITY,
+        "builtin-expect-probability",
+        "Set the estimated probability in percentage for builtin expect. The default value is 90% probability.",
+        90, 0, 100)
 DEFPARAM(TRACER_DYNAMIC_COVERAGE_FEEDBACK,
         "tracer-dynamic-coverage-feedback",
         "The percentage of function, weighted by execution frequency, that must be covered by trace formation. Used when profile feedback is available",
index 2909117ef6bd16a2f1b625f9c37b8e9f97a5004e..e6a4095acd151c3e8a149b961ba9693f42dc2d16 100644 (file)
@@ -2000,11 +2000,12 @@ tree_predict_by_opcode (basic_block bb)
   BITMAP_FREE (visited);
   if (val)
     {
+      int percent = PARAM_VALUE (BUILTIN_EXPECT_PROBABILITY);
+
+      gcc_assert (percent >= 0 && percent <= 100);
       if (integer_zerop (val))
-       predict_edge_def (then_edge, PRED_BUILTIN_EXPECT, NOT_TAKEN);
-      else
-       predict_edge_def (then_edge, PRED_BUILTIN_EXPECT, TAKEN);
-      return;
+        percent = 100 - percent;
+      predict_edge (then_edge, PRED_BUILTIN_EXPECT, HITRATE (percent));
     }
   /* Try "pointer heuristic."
      A comparison ptr == 0 is predicted as false.
index 0006233da35abb8174a6f1e33b2d19aba6b24c87..f8dba66e8718a7c1a409249306a56c230b11f085 100644 (file)
@@ -57,7 +57,10 @@ DEF_PREDICTOR (PRED_UNCONDITIONAL, "unconditional jump", PROB_ALWAYS,
 DEF_PREDICTOR (PRED_LOOP_ITERATIONS, "loop iterations", PROB_ALWAYS,
               PRED_FLAG_FIRST_MATCH)
 
-/* Hints dropped by user via __builtin_expect feature.  */
+/* Hints dropped by user via __builtin_expect feature.  Note: the
+   probability of PROB_VERY_LIKELY is now overwritten by param
+   builtin_expect_probability with a default value of HITRATE(90).
+   Refer to param.def for details.  */
 DEF_PREDICTOR (PRED_BUILTIN_EXPECT, "__builtin_expect", PROB_VERY_LIKELY,
               PRED_FLAG_FIRST_MATCH)
 
index abf1e07e2b84dd6636787d4d2791decbbf29960a..8fc1244e1ad6fc5aed4677183afe62dc6c39e3d8 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile { target nonpic } } */
-/* { dg-options "-O3 -fdump-tree-fnsplit -fdump-tree-optimized" } */
+/* { dg-options "-O3 -fdump-tree-fnsplit -fdump-tree-optimized --param=builtin-expect-probability=100" } */
 
 struct a {int a,b;};
 struct a make_me_big (int a);
index 12070fa3362fc35485f1da46ff7017d43397bd3d..fcdf79d7027adb71e4d03b700af46ce308eb56bd 100644 (file)
@@ -1,6 +1,6 @@
 /* PR tree-optimization/52019 */
 /* { dg-do compile } */
-/* { dg-options "-O3 -fno-tree-sra -fdump-tree-fnsplit -fdump-tree-optimized" } */
+/* { dg-options "-O3 -fno-tree-sra -fdump-tree-fnsplit -fdump-tree-optimized --param=builtin-expect-probability=100" } */
 
 #include "ipa-split-5.c"
 
index 93ea906614f4815134f80553e8f2cdd75da705cb..4b61b9d56d8f01d1aa675d8f5d5ddd0d7f7420c0 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2" } */
+/* { dg-options "-O2 --param=builtin-expect-probability=100" } */
 #include <string.h>
 t(int c)
 {