Patchwork [GOOGLE] tune loop scale factor for AutoFDO

login
register
mail settings
Submitter Dehao Chen
Date Nov. 8, 2013, 2:23 p.m.
Message ID <CAO2gOZWm0yPV6zQjDGKrr6s2EwYEJYacK1EYHe62VOTy8FyCRQ@mail.gmail.com>
Download mbox | patch
Permalink /patch/289845/
State New
Headers show

Comments

Dehao Chen - Nov. 8, 2013, 2:23 p.m.
AutoFDO sometimes has 0 profile in the loop's entry block because the
debug info are lost and unrecoverable.

E.g.

if (a)
  if (b)
    for () {}

This patch checks if the scale factor is 0, then use the normal scale.

Bootstrapped and passed regression test and performance test.

OK for google-4_8?

Thanks,
Dehao
Xinliang David Li - Nov. 8, 2013, 5:32 p.m.
On Fri, Nov 8, 2013 at 6:23 AM, Dehao Chen <dehao@google.com> wrote:
> AutoFDO sometimes has 0 profile in the loop's entry block because the
> debug info are lost and unrecoverable.

Is that a separate problem to track and fix?


Also is it better to do a round of loop profiling smoothing after auto
profile annotation to eliminate the insanity?

David


>
> E.g.
>
> if (a)
>   if (b)
>     for () {}
>
> This patch checks if the scale factor is 0, then use the normal scale.
>
> Bootstrapped and passed regression test and performance test.
>
> OK for google-4_8?
>
> Thanks,
> Dehao
>
> Index: gcc/cfgloopmanip.c
> ===================================================================
> --- gcc/cfgloopmanip.c (revision 204568)
> +++ gcc/cfgloopmanip.c (working copy)
> @@ -1262,6 +1262,8 @@ duplicate_loop_to_header_edge (struct loop *loop,
>   }
>        for (i = 0; i < ndupl; i++)
>   gcc_assert (scale_step[i] >= 0 && scale_step[i] <= REG_BR_PROB_BASE);
> +      if (flag_auto_profile && scale_main == 0)
> + scale_main = REG_BR_PROB_BASE;
>        gcc_assert (scale_main >= 0 && scale_main <= REG_BR_PROB_BASE
>     && scale_act >= 0  && scale_act <= REG_BR_PROB_BASE);
>      }
Dehao Chen - Nov. 8, 2013, 9:23 p.m.
As discussed offline, will commit this patch first, and think of other
smoothing algorithm to prevent profile insanity.

Dehao

On Fri, Nov 8, 2013 at 9:32 AM, Xinliang David Li <davidxl@google.com> wrote:
> On Fri, Nov 8, 2013 at 6:23 AM, Dehao Chen <dehao@google.com> wrote:
>> AutoFDO sometimes has 0 profile in the loop's entry block because the
>> debug info are lost and unrecoverable.
>
> Is that a separate problem to track and fix?
>
>
> Also is it better to do a round of loop profiling smoothing after auto
> profile annotation to eliminate the insanity?
>
> David
>
>
>>
>> E.g.
>>
>> if (a)
>>   if (b)
>>     for () {}
>>
>> This patch checks if the scale factor is 0, then use the normal scale.
>>
>> Bootstrapped and passed regression test and performance test.
>>
>> OK for google-4_8?
>>
>> Thanks,
>> Dehao
>>
>> Index: gcc/cfgloopmanip.c
>> ===================================================================
>> --- gcc/cfgloopmanip.c (revision 204568)
>> +++ gcc/cfgloopmanip.c (working copy)
>> @@ -1262,6 +1262,8 @@ duplicate_loop_to_header_edge (struct loop *loop,
>>   }
>>        for (i = 0; i < ndupl; i++)
>>   gcc_assert (scale_step[i] >= 0 && scale_step[i] <= REG_BR_PROB_BASE);
>> +      if (flag_auto_profile && scale_main == 0)
>> + scale_main = REG_BR_PROB_BASE;
>>        gcc_assert (scale_main >= 0 && scale_main <= REG_BR_PROB_BASE
>>     && scale_act >= 0  && scale_act <= REG_BR_PROB_BASE);
>>      }

Patch

Index: gcc/cfgloopmanip.c
===================================================================
--- gcc/cfgloopmanip.c (revision 204568)
+++ gcc/cfgloopmanip.c (working copy)
@@ -1262,6 +1262,8 @@  duplicate_loop_to_header_edge (struct loop *loop,
  }
       for (i = 0; i < ndupl; i++)
  gcc_assert (scale_step[i] >= 0 && scale_step[i] <= REG_BR_PROB_BASE);
+      if (flag_auto_profile && scale_main == 0)
+ scale_main = REG_BR_PROB_BASE;
       gcc_assert (scale_main >= 0 && scale_main <= REG_BR_PROB_BASE
    && scale_act >= 0  && scale_act <= REG_BR_PROB_BASE);
     }