[davidm@azstarnet.com: Re: gcc-2.7.1 bug]

David Mosberger-Tang (davidm@azstarnet.com)
Mon, 25 Mar 1996 15:43:10 -0700


Here is a detailed description (and a small test program that
reproduces the problem) of the gcc bug I mentioned earlier today.
Richard Kenner determined that the latest gcc still has this problem.
It's apparently due to a bug in `combine' (not the instruction
scheduler as I guessed). Since Richard won't be able to fix it
immediately, I thought I'd forward this to the mailing lists so people
know what exactly goes wrong. Of course, if somebody could find a
fix, I'm sure Richard wouldn't mind receiving a patch either... :-)

--david

------- Start of forwarded message -------
Return-Path: davidm
Date: Mon, 25 Mar 1996 13:01:18 -0700
From: David Mosberger-Tang <davidm@azstarnet.com>
To: kenner@vlsi1.ultra.nyu.edu, davidm
In-reply-to: <9603251224.AA13984@vlsi1.ultra.nyu.edu>
(kenner@vlsi1.ultra.nyu.edu)
Subject: Re: gcc-2.7.1 bug

Just ran into another bug. This time it's a code generation bug (it
looks like the instruction scheduler is overly aggressive). Given
the code:

long
XGetRGBColormaps (dpy, w, stdcmap, count, property)
void *dpy;
long w;
long **stdcmap;
int *count;
long property;
{
long *data = 0;
int actual_format;
unsigned long nitems;
unsigned long actual_type, leftover;

if (XGetWindowProperty (dpy, w, property, 0L, 1000000L, 0,
27, &actual_type, &actual_format,
&nitems, &leftover, (unsigned char **)&data)
!= 0)
return 0;
return 1;
}

If I translate this with gcc-2.7.1 with options -O2 -S, I get:

.align 3
.globl XGetRGBColormaps
.ent XGetRGBColormaps
XGetRGBColormaps:
ldgp $29,0($27)
XGetRGBColormaps..ng:
lda $30,-112($30)
.frame $30,112,$26,0
stq $26,48($30)
.mask 0x4000000,-64
.prologue 1
lda $20,16960 # <--------- overwrites a4
bis $31,27,$1
addq $30,72,$2
addq $30,80,$3
stq $31,96($30)
addq $30,88,$4
stq $1,0($30)
addq $30,96,$1
addq $30,64,$5
stq $5,8($30)
bis $31,$31,$19
stq $2,16($30)
bis $31,$31,$21
stq $3,24($30)
bis $20,$20,$18 # <- attempt to move old value of a4 into a2
stq $4,32($30)
ldah $20,15($20) # <- finish loading constant 100000L into a4
stq $1,40($30)
jsr $26,XGetWindowProperty

So it looks like the "lda $20,16960" instruction incorrectly got moved
before the instruction that moves a4 into a2.

Correct code is generated if -O is used.

Can you reproduce this?

--david

------- End of forwarded message -------