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]

wrong alias-analysis and strange x86-code


Hi,

I'm not following gcc-development and have no idea whether the following
behaviour is known and still in the current gcc, so I'm sending it to this
list. Judging from a recent article in Dr. Dobbs which actually gives an
example of this problem, however, I assume that it is not already known.

First, gcc 2.95 seems to do overly optimistic type-based alias-analysis. In
the example attached to this mail it apparently assumes that an expression
p[x] cannot alias certain objects and generates wrong code. I've verified
this problem also with the PPC-backend and -O or -O2. p[0] and *p seem to
be handled better.

Second, the x86-backend generates very strange code with unnecessary
building/destroying of stack-frames for this example.

egcs 2.91.66 does not show any of these problems.

Volker


16:15 linux0130:/tmp 1598> cat c2.c
int x,*p=&x;

main()
{
 int i=0;
 x=1;
 p[i]=2;
 printf("%d\n",x);
}

16:15 linux0130:/tmp 1599> gcc -v
Reading specs from /usr/lib/gcc-lib/i486-suse-linux/2.95.2/specs
gcc version 2.95.2 19991024 (release)
16:15 linux0130:/tmp 1600> gcc -S -O3 -fomit-frame-pointer c2.c
16:15 linux0130:/tmp 1601> cat c2.s
        .file   "c2.c"
        .version        "01.01"
gcc2_compiled.:
.globl p
.data
        .align 4
        .type    p,@object
        .size    p,4
p:
        .long x
.section        .rodata
.LC0:
        .string "%d\n"
        .comm   x,4,4
.text
        .align 16
.globl main
        .type    main,@function
main:
        subl $12,%esp
        movl $1,x
        movl p,%eax
        movl $2,(%eax)
        addl $-8,%esp
        pushl $1
        pushl $.LC0
        call printf
        addl $16,%esp
        addl $12,%esp
        ret
.Lfe1:
        .size    main,.Lfe1-main
        .ident  "GCC: (GNU) 2.95.2 19991024 (release)"


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