Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(988)

Issue 5504086: Static branch prediction: compare IV to loop bound variable

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 4 months ago by dehao
Modified:
12 years, 2 months ago
Reviewers:
davidxl
CC:
gcc-patches_gcc.gnu.org
Base URL:
svn+ssh://gcc.gnu.org/svn/gcc/trunk/
Visibility:
Public.

Description

In loop body, if a branch compares IV to a loop bound variable, or an expr that contains it, we could make more aggressive prediction.

Patch Set 1 #

Total comments: 16

Patch Set 2 : integrate David's reviews #

Total comments: 10

Patch Set 3 : Integrate David's reviews #

Patch Set 4 : add unit tests #

Patch Set 5 : fix the warnings #

Total comments: 6

Patch Set 6 : Add support for comparison with loop iv's initial value #

Unified diffs Side-by-side diffs Delta from patch set Stats (+555 lines, -0 lines) Patch
M gcc/ChangeLog View 1 2 3 4 5 1 chunk +12 lines, -0 lines 0 comments Download
M gcc/predict.c View 1 2 3 4 5 4 chunks +381 lines, -0 lines 0 comments Download
M gcc/predict.def View 1 2 3 4 5 1 chunk +4 lines, -0 lines 0 comments Download
M gcc/testsuite/ChangeLog View 1 2 3 4 5 1 chunk +10 lines, -0 lines 0 comments Download
A gcc/testsuite/gcc.dg/predict-1.c View 1 2 3 4 5 1 chunk +27 lines, -0 lines 0 comments Download
A gcc/testsuite/gcc.dg/predict-2.c View 1 2 3 4 5 1 chunk +27 lines, -0 lines 0 comments Download
A gcc/testsuite/gcc.dg/predict-3.c View 1 2 3 4 5 1 chunk +25 lines, -0 lines 0 comments Download
A gcc/testsuite/gcc.dg/predict-4.c View 1 2 3 4 5 1 chunk +19 lines, -0 lines 0 comments Download
A gcc/testsuite/gcc.dg/predict-5.c View 1 2 3 4 5 1 chunk +25 lines, -0 lines 0 comments Download
A gcc/testsuite/gcc.dg/predict-6.c View 1 2 3 4 5 1 chunk +25 lines, -0 lines 0 comments Download

Messages

Total messages: 9
davidxl
http://codereview.appspot.com/5504086/diff/1/gcc/predict.c File gcc/predict.c (right): http://codereview.appspot.com/5504086/diff/1/gcc/predict.c#newcode953 gcc/predict.c:953: find_ssa_name (tree t) Why is the function needed? bound ...
12 years, 4 months ago (2011-12-27 20:27:32 UTC) #1
dehao
Hi, David, I've updated the CL. Thanks, Dehao http://codereview.appspot.com/5504086/diff/1/gcc/predict.c File gcc/predict.c (right): http://codereview.appspot.com/5504086/diff/1/gcc/predict.c#newcode953 gcc/predict.c:953: find_ssa_name ...
12 years, 4 months ago (2011-12-28 03:19:25 UTC) #2
davidxl
http://codereview.appspot.com/5504086/diff/6/gcc/predict.c File gcc/predict.c (right): http://codereview.appspot.com/5504086/diff/6/gcc/predict.c#newcode999 gcc/predict.c:999: switch (TREE_OPERAND_LENGTH (t)) Can the expression 't' be something ...
12 years, 4 months ago (2011-12-28 07:03:55 UTC) #3
dehao
Hi, David, Thanks for reviewing. Dehao http://codereview.appspot.com/5504086/diff/6/gcc/predict.c File gcc/predict.c (right): http://codereview.appspot.com/5504086/diff/6/gcc/predict.c#newcode999 gcc/predict.c:999: switch (TREE_OPERAND_LENGTH (t)) ...
12 years, 4 months ago (2011-12-28 07:55:20 UTC) #4
davidxl
After more testing, you can submit it upstream for review.. David On Tue, Dec 27, ...
12 years, 4 months ago (2011-12-28 08:01:23 UTC) #5
dehao
Shall it go to trun/google branch? Dehao On Wed, Dec 28, 2011 at 4:01 PM, ...
12 years, 4 months ago (2011-12-28 08:12:41 UTC) #6
davidxl
Ok for google branches for now. thanks, David http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c File gcc/predict.c (right): http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c#newcode958 gcc/predict.c:958: find_qualified_ssa_name ...
12 years, 2 months ago (2012-01-31 01:25:42 UTC) #7
dehao
There are still some minor bugs in the current implementation, which is fixed by the ...
12 years, 2 months ago (2012-02-01 15:33:21 UTC) #8
davidxl
12 years, 2 months ago (2012-02-01 16:41:19 UTC) #9
ok.

thanks,

David

On Wed, Feb 1, 2012 at 7:33 AM, Dehao Chen <dehao@google.com> wrote:
> There are still some minor bugs in the current implementation, which
> is fixed by the attached patch:
>
> passed bootstrap/regression tests for both google-4_6 and google-main branch.
>
> ok for google branch?
>
> Thanks,
> Dehao
>
> gcc/ChangeLog.google-4_6
> 2012-01-31  Dehao Chen  <dehao@google.com>
>
>        * predict.c (predict_iv_comparison): Add new parameter, ensure that
>        the loop_iv_base and compare_base are identical.
>
> Index: gcc/predict.c
> ===================================================================
> --- gcc/predict.c       (revision 183783)
> +++ gcc/predict.c       (working copy)
> @@ -1126,8 +1126,8 @@
>  }
>
>  /* Predict branch probability of BB when BB contains a branch that compares
> -   an induction variable in LOOP to LOOP_BOUND_VAR. The loop exit is
> -   compared using LOOP_BOUND_CODE, with step of LOOP_BOUND_STEP.
> +   an induction variable with LOOP_IV_BASE_VAR in LOOP to LOOP_BOUND_VAR. The
> +   loop exit is compared using LOOP_BOUND_CODE, with step of LOOP_BOUND_STEP.
>
>    E.g.
>      for (int i = 0; i < bound; i++) {
> @@ -1142,6 +1142,7 @@
>  static void
>  predict_iv_comparison (struct loop *loop, basic_block bb,
>                       tree loop_bound_var,
> +                      tree loop_iv_base_var,
>                       enum tree_code loop_bound_code,
>                       int loop_bound_step)
>  {
> @@ -1184,7 +1185,8 @@
>       return;
>     }
>
> -  if (!expr_coherent_p (loop_bound_var, compare_var))
> +  if (!expr_coherent_p (loop_bound_var, compare_var)
> +      || loop_iv_base_var != compare_base)
>     return;
>
>   /* If loop bound, base and compare bound are all constents, we can
> @@ -1213,13 +1215,17 @@
>        compare_count ++;
>       if (loop_bound_code == LE_EXPR || loop_bound_code == GE_EXPR)
>        loop_count ++;
> +      if (compare_count < 0)
> +       compare_count = 0;
> +      if (loop_count < 0)
> +       loop_count = 0;
>
>       if (loop_count == 0)
>        probability = 0;
>       else if (compare_count > loop_count)
> -       probability = 1;
> +       probability = REG_BR_PROB_BASE;
>       else
> -       probability = REG_BR_PROB_BASE * compare_count / loop_count;
> +       probability = (double) REG_BR_PROB_BASE * compare_count / loop_count;
>       predict_edge (then_edge, PRED_LOOP_IV_COMPARE, probability);
>       return;
>     }
> @@ -1405,7 +1411,7 @@
>                  predict_edge (e, PRED_LOOP_EXIT, probability);
>            }
>          if (loop_bound_var)
> -           predict_iv_comparison (loop, bb, loop_bound_var,
> +           predict_iv_comparison (loop, bb, loop_bound_var, loop_iv_base,
>                                   loop_bound_code,
>                                   loop_bound_step);
>        }
>
> On Mon, Jan 30, 2012 at 5:25 PM,  <davidxl@google.com> wrote:
>> Ok for google branches for now.
>>
>> thanks,
>>
>> David
>>
>>
>> http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c
>> File gcc/predict.c (right):
>>
>> http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c#newcode958
>> gcc/predict.c:958: find_qualified_ssa_name (tree t1, tree t2)
>> Better change the name into 'strips_small_constant'
>>
>> http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c#newcode991
>> gcc/predict.c:991: Return NULL if T does not satisfy IV_COMPARE
>> condition.  */
>> Fix comment -- there is no IV_COMPARE used here.
>>
>> http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c#newcode995
>> gcc/predict.c:995: {
>> Better change the name into 'get_base_value (tree t)' because the method
>> basically strips the constant 'offset' away.
>>
>> http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c#newcode1102
>> gcc/predict.c:1102: a similar variable.  */
>> Fix the comments. Returns true if T1 and T2 are value coherent.
>>
>> http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c#newcode1106
>> gcc/predict.c:1106: {
>> May be changing the name to
>>
>> expr_coherent_p (tree t1, tree t2)
>>
>> http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c#newcode1206
>> gcc/predict.c:1206: && (compare_code == LT_EXPR || compare_code ==
>> LE_EXPR))
>> Fix indentation.
>>
>> http://codereview.appspot.com/5504086/
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b