TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Tulipant Gergely
from: Jasen Betts
date: 2003-05-27 21:58:40
subject: gcc -O

Hi Tulipant.

25-May-03 17:08:33, Tulipant Gergely wrote to All


 TG>   Can y'all tell me how to figure out exactly what optimizations the
 TG> different -O[1-3] options switch on? I tried the options the man/info
 TG> mentions (e.g. "When you specify `-O', the two options
 TG> `-fthread-jumps' and `-fdefer-pop' are turned on"), but with those,
 TG> gcc compiles differently

 TG> I used gcc-2.96-113.i386.rpm with the below l'art pour l'art code (O.c).

 TG> long add (long a, void *ptr, int type) {
 TG>   if (type == 0)
 TG>     return a + *(int *) ptr;
 TG>   else
 TG>     return a + *(long *) ptr;
 TG> }

first off I'll point out that in that environment  int  and  long  are the
same type so the  if(type==0) is meaningless,

O1 seems to notice that the two brances have identical code ans that the if
achieves nothing and drops the testing of type entirely

O2 and O3 manage to merge the two branches of the  if into a single block
but for some reason test the the value of type but ignore the result.

 it looks like a bug to me
 ~~~~~~~~~~~~~~~~~~~~~~~~~

 TG>   It does make sense helping the compiler as Ulrich Drepper recommends:

 TG>   if (sizeof(int) == sizeof(long) || type == 0)

 TG>   This way -O2 makes as good a translation as -O1. :)

but O0 is worsened....

It may be better to do a #if using something from values.h
but you may loose POSIX compatibility that way.

 -=> Bye <=-

---
* Origin: As King Arthur said: Some days it all seems so feudal. (3:640/1042)
SEEN-BY: 633/267 270
@PATH: 640/1042 531 954 774/605 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.