Bug 13037 - [3.3 regression] [gcse-lm] g77 generates incorrect code
Summary: [3.3 regression] [gcse-lm] g77 generates incorrect code
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.3.2
: P2 critical
Target Milestone: 3.3.3
Assignee: Roger Sayle
URL:
Keywords: wrong-code
: 12442 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-11-13 12:47 UTC by Kirill Smelkov
Modified: 2003-12-13 08:36 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2003-11-15 09:35:11


Attachments
full source attachment for bug 13037 (474 bytes, text/plain)
2003-11-13 12:49 UTC, Kirill Smelkov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kirill Smelkov 2003-11-13 12:47:16 UTC
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
Comment 1 Kirill Smelkov 2003-11-13 12:49:08 UTC
Created attachment 5129 [details]
full source attachment for bug 13037
Comment 2 Kirill Smelkov 2003-11-13 12:54:55 UTC
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 
 
Comment 3 bdavis9659 2003-11-14 04:41:16 UTC
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
Comment 4 Kirill Smelkov 2003-11-14 17:03:05 UTC
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! 
 
Comment 5 Andrew Pinski 2003-11-15 09:35:10 UTC
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.
Comment 6 Andrew Pinski 2003-11-15 09:38:09 UTC
It is gcse load motion which is causing this.
Comment 7 Andrew Pinski 2003-11-15 09:39:24 UTC
Related to bug 12442.
Comment 8 Kirill Smelkov 2003-11-15 09:50:54 UTC
Maybe it's worth adding it to g77 testcases? 
 
Comment 9 janis187 2003-12-02 00:29:40 UTC
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.
Comment 10 Eric Botcazou 2003-12-03 09:43:12 UTC
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.
Comment 11 roger 2003-12-09 11:49:11 UTC
There's a patch at http://gcc.gnu.org/ml/gcc-patches/2003-12/msg00668.html
that's still awaiting review :>
Comment 12 Eric Botcazou 2003-12-09 11:54:15 UTC
I'd almost qualify it as obvious.
Comment 13 Eric Botcazou 2003-12-11 11:26:18 UTC
*** Bug 12442 has been marked as a duplicate of this bug. ***
Comment 14 CVS Commits 2003-12-12 14:31:21 UTC
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

Comment 15 CVS Commits 2003-12-12 18:37:09 UTC
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

Comment 16 Eric Botcazou 2003-12-13 08:36:56 UTC
See the aforementioned patch.