GCC Bugzilla – Bug 45058
GCC doesn't create functions with multiple entry points.
Last modified: 2010-07-24 18:13:27 UTC
A possible optimization in some cases is to construct a function with multiple entry points. This can save in both size and speed in certain cases.
/* Example function that does something complex enough not to be optimized away */
static foo(int x)
int j = x;
for (i = 0; i < 1024; i++)
j += printf("%d%d%d\n", i);
/* Since foo is static and whose address is never taken, foo1 can have the same address as foo. */
int foo1(int x)
/* This function could point to an "add $1, %rdi" instruction immediately before foo. (Giving foo two entry points.) */
int foo2(int x)
return foo(x + 1);
At the moment, GCC will at -O3 construct two cloned versions of foo for foo1 and foo2. At -Os, it will jump to foo in foo1 and foo2. With multiple entry points, the code can be as fast as generated for -O3 but be half the size, slightly smaller than the current -Os.