This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

[Bug tree-optimization/66573] Unexpected change in static, branch-prediction cost from O1 to O2 in if-then-else.


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66573

--- Comment #8 from Segher Boessenkool <segher at gcc dot gnu.org> ---
(In reply to Joshua Green from comment #7)
> and I see no reason why expecting the "else" block should a priori be
> preferable in either case.

GCC does some fairly involved prediction (in predict.c).  It isn't
"a priori".

> (It's also not clear HOW this could be "faster
> on essentially all processors"

Fall-through is faster than branching in most cases.  Most CPUs have
some kind of pipelining on instruction fetch.

> Of course, the compiler is
> free to make whatever guess it wants, but it would be nice if the programmer
> had some portable way of expressing his/her own expectations,

There is __builtin_expect, if that is portable enough for you.  You
can wrap it with some macros if you need it to be more portable.

> and it seems
> that other compilers provide that by "agreeing" to expect the "if" block
> (as, indeed, various online articles recommend).

I much doubt such trivial heuristics work better.  Feel free to
prove me wrong :-)

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