This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: disabling branch probability guessing (patch)


Aldy Hernandez <aldyh@redhat.com> writes:

> hi guys.
> 
> Here is a patch that adds an option to disable guessing of branch
> probabilities (-fno-guess-branch-probability).
> 
> One of our clients is trying to use __builtin_expect and is getting
> unexpected results because estimate_probability() in predict.c is 
> guessing the branch probability in an undetermined way.  This patch
> solves the problem by providing an option to disable the probability
> guessing altogether.

Cool. This is useful for the linux kernel too. I found out that the 
prediction guessing undoes some of the carefully crafted goto woods
to keep fast paths jumpless.


e.g.

f()
{
        int err = -EBLA; 
        if (unlikely error case) 
                goto error;
        ...


        err = 0; 
out:
        return err;
}
   
is turned by 2.97 when the error test isn't liked by predict.c 
into

f()
{
        if (error case) { 
                return -EBLA;   
        } 

        ...
} 
  
which involves a jump in the common path.


-Andi


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]