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

GCC optimization oddity


Hello all,

The attached gcc-bug.c file is a file from busybox source. It has been 
passed through the preprocessor for X86, and hence macros, etc. are 
defined already.

Two compilation scenarios:

i.  gcc -S gcc-bug.c -Os -DHAHA; md5sum gcc-bug.s
ii. gcc -S gcc-bug.c -Os -DHAHA -DBLAH -DAKS -DJKAHSD; md5sum gcc-bug.s 

As you can tell, the -D macros are bogus, and I would expect the md5sums 
from each compile to match. But they dont. The diff of the resulting 
assembly is as follows:

pniyogi@buildwookie:~$ diff -urN bug-preprocess.s bug-preprocess.s.1
--- bug-preprocess.s    2005-10-11 17:04:07.367667230 -0500
+++ bug-preprocess.s.1  2005-10-11 17:03:13.872321122 -0500
@@ -5931,13 +5931,14 @@
        je      .L959
        cmpb    %cl, %al
        je      .L959
+       addl    $2, %edx
 .L962:
-       movl    -32(%ebp), %edx
-       leal    1(%edx), %eax
+       movl    %edx, -32(%ebp)
+       movl    %edx, %eax
+       incl    %edx
        cmpl    %ebx, %eax
-       movl    %eax, -32(%ebp)
        jae     .L959
-       movzbl  1(%edx), %eax
+       movzbl  -1(%edx), %eax
        cmpb    $10, %al
        je      .L959
        cmpb    %cl, %al
pniyogi@buildwookie:~$ gcc --version
gcc (GCC) 3.3.5 (Debian 1:3.3.5-13)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR 
PURPOSE.


Can anyone explain why this is happening? It appears on all gcc-3.3.x 
versions, including latest gcc-3.3.6. Originally, I thought there may be 
some kind of overflow occuring in the command line, but on second thought, 
that would lead to a much bigger diff is some optimization flag was 
getting crushed.  I do not think that bogus macro definitions should 
affect something like that described here. But I am a novice. Any 
thoughts/leads would be appreciated.

Thanks,


Prosun Niyogi



Attachment: gcc-bug.c
Description: Binary data


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