The following c/++ code generates assembly that favors the unlikely case with gcc 4.3 and 4.4: extern void likely(); extern void unlikely(); void test_expect(char * a, char *b, char *c, char *d) { if (__builtin_expect(!!(a == b && c == d), 1)) { likely(); } else { unlikely(); } } Compiled with g++44 -O2 -S -fverbose-asm -m32. (or -m64).
A few notes: gcc 4.1 seems to generate better assembly. If this code is code is compiled as c code and not C++ with gcc 4.4, the likely case is properly favored. Changing the if statement into "if (__builtin_expect(!!(a == b),1) && __builtin_expect(!!(c == d), 1))" fixes the problem as well. With this code, gcc generates better code for the likely case. -- Summary: c++ builtin_expect code generation regression Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: gmorin1 at bloomberg dot net http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42233