https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79489
Bug ID: 79489 Summary: Strange static branch prediction for n != 0 Product: gcc Version: 7.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: glisse at gcc dot gnu.org Target Milestone: --- http://stackoverflow.com/q/41880779/1918193 extern void foo(); extern void bar(); int some_func(int n) { if (n) { foo(); } else { bar(); } return 0; } gcc's profile_estimate guesses (DS theory heuristics) that n is 0 with probability 54%. This seems strange, as other parts of the compiler predict == as more likely false (at least for types with precision > 1). Also, we may want to document somewhere that gcc tends to consider the "else" branch as more likely (or at least does not particularly favor the "then" branch), since there is quite a bit of information on the web that recommends writing conditions the other way around. But the heuristics are complicated enough that it is hard to come up with a statement that is true without being uselessly vague. (I won't be surprised if this ends up as invalid or wontfix, but it felt worth forwarding)