From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5126 invoked by alias); 24 May 2013 10:16:42 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 5040 invoked by uid 48); 24 May 2013 10:16:35 -0000 From: "bugs at stellardeath dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/57396] New: Wrong code with -fpredictive-commoning in Fortran double-loop Date: Fri, 24 May 2013 10:16:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bugs at stellardeath dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-05/txt/msg01709.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57396 Bug ID: 57396 Summary: Wrong code with -fpredictive-commoning in Fortran double-loop Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: bugs at stellardeath dot org Created attachment 30182 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30182&action=edit Small test case The following example program produces incorrect output when compiled with -O3, but remains correct with -O3 -fno-predictive-commining: > cat test.f90 module testmod implicit none contains subroutine foo(n) integer, intent(in) :: n real :: r(0:n,-n:n), a(0:n,-n:n), dj integer :: k, j ! initialize with some dummy values do j = -n, n a(:, j) = j r(:,j) = j + 1 end do ! here be dragons do k = 0, n dj = r(k, k - 2) * a(k, k - 2) r(k,k) = a(k, k - 1) * dj enddo print *, r(0,0) end subroutine end module program test use testmod implicit none call foo(5) end program > gfortran -O3 test.f90 > ./a.out -3.00000000 > > gfortran -O3 -fno-predictive-commoning test.f90 > ./a.out -2.00000000 > This only happens with gfortran 4.8, with 4.7.2 it produces the correct output (-2.0). My specific version is: > gfortran --version GNU Fortran (GCC) 4.9.0 20130517 (experimental) Copyright (C) 2013 Free Software Foundation, Inc. GNU Fortran comes with NO WARRANTY, to the extent permitted by law. You may redistribute copies of GNU Fortran under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING