This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
constant folding with constant function pointers in GCC 4.1.x
- From: "Frankel, Bob" <bios-bob at ti dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Thu, 5 Apr 2007 13:25:53 -0500
- Subject: constant folding with constant function pointers in GCC 4.1.x
consider the following two examples, both of which optimize as expected
using the new whole-program optimization feature of GCC 4.1.x. (i am
currently running a Mingw 4.1.0 compiler under windows)
/*
* ======== ex1.c ========
*/
const int flag = 1;
volatile int OUT;
int main()
{
OUT = flag ? 100 : 200; /* optimized to OUT = 100; */
return 0;
}
/*
* ======== ex2.c ========
*/
volatile int OUT;
void foo()
{
OUT = 100;
}
int main()
{
foo(); /* optimized to OUT = 100; */
return 0;
}
now, consider a third example which calls function foo() via a const
function pointer:
/*
* ======== ex3.c ========
*/
volatile int OUT;
void foo()
{
OUT = 100;
}
void (*const FOOPTR)() = foo;
int main()
{
FOOPTR(); /* remains an indirect call to foo */
return 0;
}
i would have expected the indirect call to fold away into an assignment
of 100 to OUT, as in the other examples. i have seen this optimization
occur on other compilers supporting whole-program optimization, and was
wondering if there is something else i need to add to either my source
file and/or my makefile (where i am already passing -O3 and
-fwhole-program)
thanks,
bob frankel