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

Reply via email to