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]

Different results with `gcc' and `gcc -O3' - really a bug ?


Hello,

consider the following program:

main ()
{
  int x = 1, y;
  y = ++x + ++x;
  printf ("y = %d, x = %d\n", y, x);
}

On our SPARC Ultra-Enterprise 3000 with gcc 2.95.2:

[antipov@toxic work]# cat qq1.c 
main ()
{
  int x = 1, y;
  y = ++x + ++x;
  printf ("y = %d, x = %d\n", y, x);
}
[antipov@toxic work]# gcc qq1.c 
[antipov@toxic work]# ./a.out 
y = 5, x = 3
[antipov@toxic work]# gcc -O3 qq1.c 
[antipov@toxic work]# ./qq1 
y = 6, x = 3

On Intel/Linux, there are no such problem (always y = 6, x = 3). 
Native C compiler (Sun WorkShop 6 2000/04/07 C 5.1) also always 
generate code that prints y = 6, x = 3.

Is this really a compiler problem ? Please sorry if not.

Our stuff is:
`uname -a': 
SunOS toxic 5.8 Generic sun4u sparc SUNW,Ultra-Enterprise
`gcc -v': 
Reading specs from
/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2/specs
gcc version 2.95.2 19991024 (release)

Assembler code for both cases:

[antipov@toxic work]# gcc -S -fverbose-asm qq1.c -o -
        .file   "qq1.c"
! GNU C version 2.95.2 19991024 (release) (sparc-sun-solaris2.8)
compiled by GNU C version 2.95.2 19991024 (release).
! options passed:  -fverbose-asm
! options enabled:  -fpeephole -ffunction-cse -fkeep-static-consts
! -fpcc-struct-return -fsched-interblock -fsched-spec -fcommon
! -fverbose-asm -fgnu-linker -fargument-alias -fident -mepilogue
-mapp-regs

gcc2_compiled.:
.section        ".rodata"
        .align 8
.LLC0:
        .asciz  "y = %d, x = %d\n"
.section        ".text"
        .align 4
        .global main
        .type    main,#function
        .proc   04
main:
        !#PROLOGUE# 0
        save    %sp, -120, %sp
        !#PROLOGUE# 1
        mov     1, %o0
        st      %o0, [%fp-20]
        ld      [%fp-20], %o0
        add     %o0, 1, %o1
        mov     %o1, %o0
        st      %o0, [%fp-20]
        ld      [%fp-20], %o2
        add     %o2, 1, %o1
        mov     %o1, %o2
        st      %o2, [%fp-20]
        add     %o0, %o2, %o0
        st      %o0, [%fp-24]
        sethi   %hi(.LLC0), %o1
        or      %o1, %lo(.LLC0), %o0
        ld      [%fp-24], %o1
        ld      [%fp-20], %o2
        call    printf, 0
         nop
.LL2:
        ret
        restore
.LLfe1:
        .size    main,.LLfe1-main
        .ident  "GCC: (GNU) 2.95.2 19991024 (release)"

[antipov@toxic work]# gcc -O3 -S -fverbose-asm qq1.c -o -
        .file   "qq1.c"
! GNU C version 2.95.2 19991024 (release) (sparc-sun-solaris2.8)
compiled by GNU C version 2.95.2 19991024 (release).
! options passed:  -O3 -fverbose-asm
! options enabled:  -fdefer-pop -fomit-frame-pointer -fcse-follow-jumps
! -fcse-skip-blocks -fexpensive-optimizations -fthread-jumps
! -fstrength-reduce -fpeephole -fforce-mem -ffunction-cse
! -finline-functions -finline -fkeep-static-consts -fcaller-saves
! -fpcc-struct-return -fdelayed-branch -fgcse -frerun-cse-after-loop
! -frerun-loop-opt -fschedule-insns -fschedule-insns2 -fsched-interblock
! -fsched-spec -fcommon -fverbose-asm -fgnu-linker -fregmove
! -foptimize-register-move -fargument-alias -fident -mepilogue
-mapp-regs

gcc2_compiled.:
.section        ".rodata"
        .align 8
.LLC0:
        .asciz  "y = %d, x = %d\n"
.section        ".text"
        .align 4
        .global main
        .type    main,#function
        .proc   04
main:
        !#PROLOGUE# 0
        save    %sp, -112, %sp
        !#PROLOGUE# 1
        sethi   %hi(.LLC0), %o0
        or      %o0, %lo(.LLC0), %o0
        mov     6, %o1
        call    printf, 0
        mov     3, %o2
        ret
        restore
.LLfe1:
        .size    main,.LLfe1-main
        .ident  "GCC: (GNU) 2.95.2 19991024 (release)"


Thanks, 
-- 
Dmitry Antipov <antipov@rosnet.ru> 
RosNet (ICQ UIN:70767592)

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