This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
optimization/4163: aliasing regression in 3.x
- To: gcc-gnats at gcc dot gnu dot org
- Subject: optimization/4163: aliasing regression in 3.x
- From: Dan Nicolaescu <dann at godzilla dot ics dot uci dot edu>
- Date: 29 Aug 2001 04:33:34 -0000
- Reply-To: Dan Nicolaescu <dann at godzilla dot ics dot uci dot edu>
>Number: 4163
>Category: optimization
>Synopsis: aliasing regression in 3.x
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: pessimizes-code
>Submitter-Id: net
>Arrival-Date: Tue Aug 28 21:36:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Dan Nicolaescu <dann@godzilla.ics.uci.edu>
>Release: gcc-3.0
>Organization:
>Environment:
sparc-sun-solaris2.8
>Description:
On sparc-sun-solaris2.7 the following program:
struct {
float f[263169];
float p[263169];
float q[263169];
float d[263169];
} BLNK;
void
calc1 (int *n)
{
int i;
int limit = *n;
for (i = 0; i <= limit; ++i) {
BLNK.f[i] = BLNK.p[i] + BLNK.q[i];
BLNK.d[i] = BLNK.p[i] + BLNK.q[i];
BLNK.f[i] = BLNK.f[i] + BLNK.p[i] + BLNK.q[i];
}
}
The assembly for the loop when The assembly for the loop when
compiled with gcc-2.95.2 -O2 compiled with gcc-3.0 -O2
.LL6: .LL5:
ld [%o0+%o2], %f2 sll %g1, 2, %i0
addcc %o1, -1, %o1 add %i0, %o0, %i1
ld [%o0+%g3], %f4 add %i0, %o2, %i2
fadds %f2, %f4, %f3 ld [%i4+%i2], %f2
fadds %f3, %f2, %f2 add %i0, %o1, %i3
st %f3, [%o0+%g2] ld [%i5+%i1], %f3
fadds %f2, %f4, %f2 add %g1, 1, %g1
st %f2, [%o0] fadds %f3, %f2, %f3
bne .LL6 cmp %g1, %o7
add %o0, 4, %o0 st %f3, [%i4+%i0]
ld [%i4+%i2], %f3 <-
ld [%i5+%i1], %f2
fadds %f2, %f3, %f2
st %f2, [%i5+%i3]
ld [%i5+%i1], %f4 <*
ld [%i4+%i2], %f3
fadds %f4, %f3, %f4
ld [%i4+%i0], %f2
fadds %f2, %f4, %f2
ble .LL5
st %f2, [%i4+%i0]
It looks like 3.0 can't figure out that the loads and stores
don't alias.
2.95.2 did it correctly.
If you are wondering where does this code come from:
is generated by f2c (and edited a little) from the
following Fortran program:
SUBROUTINE CALC1(N)
PARAMETER (N1=263169)
COMMON F(N1), P(N1), Q(N1), D(N1)
INTEGER I
DO 100 I=0,N
F(I) = P(I) + Q(I)
D(I) = P(I) + Q(I)
F(I) = F(I) + P(I) + Q(I)
100 CONTINUE
RETURN
END
The funny thing is that both g77-2.95.2 and g77-3.0 generate exactly
the same code for this program, but both have an extra store ...
Does anybody have any idea how to fix this?
Or where to look for the problem?
>How-To-Repeat:
Compile the code above with -O2 and look at the assembly,
there should be 2 loads and 2 stores in the loop, not more.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: