On Tuesday 26 February 2008 21:14, Jan Hubicka wrote: > Only cases we do so quite reliably IMO are: > 1) loop branches that are not interesting for cmov conversion > 2) branches leading to noreturn calls, also not interesting > 3) builtin_expect mentioned. > 4) when profile feedback is around to some degree (ie we know when the > branch is very likely or very unlikely. We don't simulate what > hardware will do on it).
Without profiler, we can estimate blindly that the simply loop branches can be predictable with the assumption of that we know that the loops (of many iterations) are potential enemies (they consume many cycles) of the CPU. For example, for this simple loop without profiler, human prediction is easy: for (;;) { /* it's predictable not-branch to the end of loop for */ start: ... // hundreds of iterations (e.g. 99% branching inside, <1% branching outside } /* or predictable branch to the start of loop for depending in code gen. */ end: But for this complex loop (mutually nested), the predictability without profiler is very hard! loop1: ... if (cond1) then goto loop2 else loop3 endif // to loop2 or loop3? prediction is very hard ... loop2: ... if (cond2) then goto loop1 else loop2 endif // to loop1 or loop2? prediction is very hard ... loop3: ... if (cond3) then goto loop1 else loop3 endif // to loop1 or loop2? prediction is very hard ... goto loop1 There are things that can be human predictable but human unpredictable too! Sincerely yours ;)