Basic code optimisation

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

 



Hi,

I need your help because I can't make GCC (3.4.2 with
-O2 option) optimize a simple case.
Here it is:

"""
static const struct my_struct {
    const int a;
    const int b;
} foo = { .a = 2, .b = 3};

int main(int argc, char **argv)
{
     int volatile tmp;

     tmp = foo.a * foo.b;

     return 0;
}
"""

As you notice every things are constants, so GCC
need not to generate a "imult opcode".
Equivalent code should look like:

"""
....

int main(int argc, char **argv)
{
   volatile int tmp;

   tmp = 6;

   return 0;
}
"""

How can I make gcc generate the correct code ?

Thanks for suggestions,


     Francis.


	
	
		
Le nouveau Yahoo! Messenger est arrivé ! Découvrez toutes les nouveautés pour dialoguer instantanément avec vos amis. A télécharger gratuitement sur http://fr.messenger.yahoo.com

[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