public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/57396] New: Wrong code with -fpredictive-commoning in Fortran double-loop
@ 2013-05-24 10:16 bugs at stellardeath dot org
  2013-05-24 10:17 ` [Bug tree-optimization/57396] " bugs at stellardeath dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: bugs at stellardeath dot org @ 2013-05-24 10:16 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-08-29 13:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-24 10:16 [Bug tree-optimization/57396] New: Wrong code with -fpredictive-commoning in Fortran double-loop bugs at stellardeath dot org
2013-05-24 10:17 ` [Bug tree-optimization/57396] " bugs at stellardeath dot org
2013-05-24 11:21 ` [Bug tree-optimization/57396] [4.7/4.8/4.9 Regression] " rguenth at gcc dot gnu.org
2013-05-24 11:52 ` rguenth at gcc dot gnu.org
2013-05-24 11:55 ` dominiq at lps dot ens.fr
2013-05-24 12:01 ` [Bug tree-optimization/57396] [4.8/4.9 " rguenth at gcc dot gnu.org
2013-05-27  7:56 ` [Bug tree-optimization/57396] [4.8 " rguenth at gcc dot gnu.org
2013-08-29 13:11 ` jakub at gcc dot gnu.org
2013-08-29 13:17 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).