This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Basic code optimisation


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]