GCC optimization oddity

Prosun Niyogi pniyogi@us.ibm.com
Thu Oct 13 18:43:00 GMT 2005


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



-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-bug.c
Type: application/octet-stream
Size: 240665 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20051013/ed2555a3/attachment.obj>


More information about the Gcc mailing list