[OPTIM] GCC4's builtin_expect() is suboptimal
authorWilly Tarreau <w@1wt.eu>
Sun, 27 Jan 2008 01:21:53 +0000 (02:21 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 14 Feb 2008 22:14:33 +0000 (23:14 +0100)
commit70bcfb77a7f7aaac6c37f292f1a01ea272d25871
tree7e4121e73b5fa4dacb495172554f298d09ee6a00
parente69eada05773a86cc69edcc773262e9863ff501a
[OPTIM] GCC4's builtin_expect() is suboptimal

GCC4 is stupid (unbelievable news!).

When some code uses __builtin_expect(x != 0, 1), it really performs
the check of x != 0 then tests that the result is not zero! This is
a double check when only one was expected. Some performance drops
of 10% in the HTTP parser code have been observed due to this bug.

GCC 3.4 is fine though.

A solution consists in expecting that the tested value is 1. In
this case, it emits the correct code, but it's still not optimal
it seems. Finally the best solution is to ignore likely() and to
pray for the compiler to emit correct code. However, we still have
to fix unlikely() to remove the test there too, and to fix all
code which passed pointers overthere to pass integers instead.
include/common/ebtree.h
include/common/standard.h
include/proto/task.h
src/backend.c
src/ev_epoll.c
src/task.c