I've discovered a bug (incorrect code generation) in g77 from gcc-3.3.2 bug symptom: zeta(kkzc) seems to reference to zeta(kkzc-1) instead with gcc-3.2.2 it is OK, so it is a regression. subroutine bug1(expnt) implicit none double precision zeta common /bug1_area/zeta(3) double precision expnt(3) integer k, kkzc kkzc=0 do k=1,3 kkzc = kkzc + 1 zeta(kkzc) = expnt(k) enddo c the following line activates the bug call bug1_activator(kkzc) end full bug1.f source is in attachment
Created attachment 5129 [details] full source attachment for bug 13037
forgot to include gcc info: [kirr@roro tmini]$ g77 -v Reading specs from /mnt/tmini/kirr/local/gcc-3.3.2/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/specs Configured with: ../gcc-3.3.2/configure --prefix=/mnt/tmini/kirr/local/gcc-3.3.2 --with-gnu-as --with-gnu-ld --enable-threads=posix --enable-languages=c,c++,f77 --enable-checking --disable-nls Thread model: posix gcc version 3.3.2
Not too sure exactly what the problem is. Please take your code snippet and make it into an example that compiles and executes, then we can see exactly what the problem is. I took the liberty of creating one from your code snippets: subroutine bug1(expnt) implicit none double precision zeta common /bug1_area/zeta(3) double precision expnt(3) integer k, kkzc kkzc=0 do k=1,3 kkzc = kkzc + 1 zeta(kkzc) = expnt(k) enddo print*,'kkzc = ',kkzc print*,'zeta = (',(zeta(k),k=1,3),')' print*,'expnt = (',(expnt(k),k=1,3),')' return end c the following line activates the bug program test implicit none double precision kkzc(3) kkzc(1) = 1 kkzc(2) = 2 kkzc(3) = 3 call bug1(kkzc) end and then show a run of the program: [bdavis@localhost ~]$ ./a.out kkzc = 3 zeta = ( 1. 2. 3.) expnt = ( 1. 2. 3.) regards, bud davis
Ok, i swear i'll never provide examples as attachment! :) here it is: ---bug1.f--- c g77 -O2 bug1.f -o bug1 c ./bug1 c c long story: I've discovered a bug (incorrect code generation) in g77 from gcc-3.3.2 c bug symptom: zeta(kkzc) seems to reference to zeta(kkzc-1) instead c with gcc-3.2.2 it is OK, so it is a regression. c subroutine bug1(expnt) implicit none double precision zeta common /bug1_area/zeta(3) double precision expnt(3) integer k, kkzc kkzc=0 do k=1,3 kkzc = kkzc + 1 zeta(kkzc) = expnt(k) enddo c the following line activates the bug call bug1_activator(kkzc) end c dummy subroutine subroutine bug1_activator(inum) implicit none integer inum end c test driver program test_bug1 implicit none double precision zeta common /bug1_area/zeta(3) double precision expnt(3) zeta(1) = 0.0d0 zeta(2) = 0.0d0 zeta(3) = 0.0d0 expnt(1) = 1.0d0 expnt(2) = 2.0d0 expnt(3) = 3.0d0 call bug1(expnt) write(*,*) zeta(1), zeta(2), zeta(3) if (zeta(1).ne.1) then write(*,*) 'BUG!' call exit(1) endif end --- end of bug1.f--- [kirr@roro /mnt/tmini]$ ./bug1 2. 3. 0. BUG!
I can confirm this but it is fixed on the mainline already but since this is a regression, keeping open untill the 3.3 branch gets fixed.
It is gcse load motion which is causing this.
Related to bug 12442.
Maybe it's worth adding it to g77 testcases?
The regression in PR 13037 was fixed on the mainline with this patch: 2003-04-18 Hans-Peter Nilsson <hp@bitrange.com> * gcse.c (compute_ld_motion_mems): For MEM destinations, only consider those to be movable where the source matches want_to_gcse_p. (update_ld_motion_stores): In comment, refer to compute_ld_motion_mems for validity of replacement. Roger Sayle asked me to identify the fix on the mainline so he can port it to the 3.3 branch.
Roger, it appears that you already took a look at this one and are considering a backport patch from mainline, so I take the liberty to assign it to you. Let me know if you disagree.
There's a patch at http://gcc.gnu.org/ml/gcc-patches/2003-12/msg00668.html that's still awaiting review :>
I'd almost qualify it as obvious.
*** Bug 12442 has been marked as a duplicate of this bug. ***
Subject: Bug 13037 CVSROOT: /cvs/gcc Module name: gcc Changes by: sayle@gcc.gnu.org 2003-12-12 14:31:18 Modified files: gcc : ChangeLog loop.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g77.f-torture/execute: 13037.f Log message: PR optimization/13037 * loop.c (update_giv_derive): Ignore redundant sets of a biv when calculating how to derive a giv from a biv. * g77.f-torture/execute/13037.f: New test case. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.1986&r2=2.1987 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/loop.c.diff?cvsroot=gcc&r1=1.478&r2=1.479 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3247&r2=1.3248 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g77.f-torture/execute/13037.f.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 13037 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: sayle@gcc.gnu.org 2003-12-12 18:37:07 Modified files: gcc : ChangeLog loop.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g77.f-torture/execute: 13037.f Log message: PR optimization/13037 * loop.c (update_giv_derive): Ignore redundant sets of a biv when calculating how to derive a giv from a biv. * g77.f-torture/execute/13037.f: New test case. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.842&r2=1.16114.2.843 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/loop.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.433.2.10&r2=1.433.2.11 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.334&r2=1.2261.2.335 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g77.f-torture/execute/13037.f.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1
See the aforementioned patch.