constant folding with constant function pointers in GCC 4.1.x

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux