User account creation filtered due to spam.

Bug 45058

Summary: GCC doesn't create functions with multiple entry points.
Product: gcc Reporter: Steven Fuerst <svfuerst>
Component: middle-endAssignee: Not yet assigned to anyone <unassigned>
Status: UNCONFIRMED ---    
Severity: enhancement CC: gcc-bugs
Priority: P3    
Version: 4.5.0   
Target Milestone: ---   
Host: x86_64-linux Target: x86_64-linux
Build: x86_64-linux Known to work:
Known to fail: Last reconfirmed:

Description Steven Fuerst 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.

#include <stdio.h>

/* Example function that does something complex enough not to be optimized away */
static foo(int x)
	int i;
	int j = x;
	for (i = 0; i < 1024; i++)
		j += printf("%d%d%d\n", i);
	return j;

/* Since foo is static and whose address is never taken, foo1 can have the same address as foo. */
int foo1(int x)
	return foo(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.