The trunk version of this patch is submitted for review.

David: can we have this patch for google/gcc-4_8 branch first?
It tested with regression and google internal benchmarks.

Thanks,

-Rong
2013-10-11  Rong Xu  <x...@google.com>

        * predict.c (tree_predict_by_opcode): Bump the 
        estimiated probability if builtin_expect expression is
        in loop exit test.

Index: predict.c
===================================================================
--- predict.c   (revision 203462)
+++ predict.c   (working copy)
@@ -1951,7 +1951,31 @@ tree_predict_by_opcode (basic_block bb)
   if (val)
     {
       int percent = PARAM_VALUE (BUILTIN_EXPECT_PROBABILITY);
+      void **preds;
 
+      /* This handles the cases like
+           while (__builtin_expect (exp, 1)) { ... }
+         W/o builtin_expect, the default HITRATE is 91%.
+        It does not make sense to estimate a lower probability of 90%
+        (current default for builtin_expect) with the annotation.
+        So here, we bump the probability by a small amount.  */
+      preds = pointer_map_contains (bb_predictions, bb);
+      if (preds)
+        {
+          struct edge_prediction *pred;
+
+          for (pred = (struct edge_prediction *) *preds; pred;
+              pred = pred->ep_next)
+           {
+             if (pred->ep_predictor == PRED_LOOP_EXIT
+                 && predictor_info [(int) PRED_LOOP_EXIT].hitrate
+                    > HITRATE (percent))
+               percent += 4;
+             if (percent > 100)
+               percent = 100;
+           }
+       }
+
       gcc_assert (percent >= 0 && percent <= 100);
       if (integer_zerop (val))
         percent = 100 - percent;

Reply via email to