This is the mail archive of the gcc-bugs@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]

Optimization missed


Code :

int main()
{
 unsigned A;
 if (A > -5) return 12;
}

schon@lightyear:~/C/warn 70 uname -a
SunOS lightyear 5.6 Generic_105181-06 sun4u sparc
schon@lightyear:~/C/warn 71 gcc -v
Reading specs from 
/net/overflow/schon/gcc2.9/install/lib/gcc-lib/sparc-sun-solaris2.6/gcc-2.95/spe
cs
gcc version gcc-2.95 19990616 (prerelease)

schon@lightyear:~/C/warn 72 gcc -W -O9 -c a.c
a.c: In function `main':
a.c:4: warning: comparison between signed and unsigned
a.c:3: warning: `A' might be used uninitialized in this function

It's nice to see that the compiler warns about the comparison between signed and 
unsigned.  Why does the generated code not dispose of the comparison all 
together?  The comparison will be optimized away if the variable A is given a 
value but why is this necessary?  Clearly an unsigned value is always greater 
than a negative constant.

schon@lightyear:~/C/warn 75 objdump -D a.o

a.o:     file format elf32-sparc

Disassembly of section .text:

00000000 <main>:
   0:   80 a0 bf fb     cmp  %g2, -5
   4:   38 80 00 02     bgu,a   c <main+0xc>
   8:   90 10 20 0c     mov  0xc, %o0
   c:   81 c3 e0 08     retl 
  10:   01 00 00 00     nop 

Thanks.

Jason Schonberg
schon@mips.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]