From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Nicolaescu To: gcc-gnats@gcc.gnu.org Subject: optimization/4163: aliasing regression in 3.x Date: Tue, 28 Aug 2001 21:36:00 -0000 Message-id: <20010829043334.29155.qmail@sourceware.cygnus.com> X-SW-Source: 2001-08/msg00710.html List-Id: >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 >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: