aliasing regression in 3.0

Dan Nicolaescu dann@godzilla.ICS.UCI.EDU
Fri Aug 17 13:27:00 GMT 2001


Hi!

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.

The C code 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? 

Thanks.
        --dan



More information about the Gcc mailing list