This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: optimizing inlined switch statements and -fPIC
- From: Jan Hubicka <jh at suse dot cz>
- To: David Mansfield <gcc at dm dot cobite dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 13 Dec 2001 10:37:42 +0100
- Subject: Re: optimizing inlined switch statements and -fPIC
- References: <Pine.LNX.4.33.0112121327110.5332-100000@admin>
>
> I noticed something really weird, and I need to find out if there's a way
> to correct this odd behavior.
>
> I've noticed this with egcs, gcc-2.96 from red hat 7.2, gcc-3.0.1 and
> gcc-3.0.2 (from source).
>
> I have an inline function which performs a switch statement, each switch
> returns a constant value. When this function is called with a constant
> value, the entire switch COULD be eliminated. But it isn't in some cases.
>
> 1) it works when -fPIC isn't specified
> 2) it works if there are 3 or less cases and -fPIC is specified
This is because up to upcoming 3.1 version, the inlining is done at lowlevel
RTL code, where eliminating of such switch statements is dificult, as PIC often
obfstructates thinks in a way gcc is no longer able to prove constantness of
the jump.
New gcc do inlining on tree level that should solve the problem you are seeing.
In case you want to get this with older gcc, I would recommend you to rewrite
switch to series of ifs in case the parameter is always constant. You can
using __builtin_constant_p trick in case it is not.
In case the switch is small, the rewriting to ifs is done automatically by gcc
that explains why you are not seeing the problem for small amount of cases.
Honza