This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/30374] New: aliasing amoung dummy arguments: possibly missing optimization


The following program is (more or less) well-defined for the human reader, but
non-standard Fortran (which cannot be easily detected at compile time, cf. PR
30373).

gfortran outputs:
            1           1           1
while ifort, NAG f95 and sunf95 output the expected:
            4           5           6

program test
  implicit none
  integer, dimension(3,3) :: n
  n(:,1)=(/1,2,3/)
  n(:,2)=(/1,2,3/)
  n(:,3)=(/1,2,3/)
  call sub(n(1,:),n(1,:))
  write(6,*) n(1,:)
contains
  subroutine sub(a,b)
    implicit none
    integer, dimension(3), intent(inout) :: a
    integer, dimension(3), intent(in) :: b
    a=(/4,5,6/)
  end subroutine
end program test

Expected:

- Give same result as the other compilers ?

- Check, whether one could do some code-generation improvements; Richard Main
wrote:

"in this particular case, there is are simple optimizations that would avoid
problems. Some compilers might do variants of those optimizations. In
particular, passing a non-contiguous array slice (such as a row) here is likely
to cause copy-in/copy-out. Such copy-in/copy-out is one of the things that
the standard is explicitly written to allow; it is also sometimes the source of
behavior that can be surprising. (Or conversely, in other situations, the lack
of copy-in/copy-out can result in behavior that might seem surprising to some.)

"I suspect that some compilers avoid the copy out here, possibly because of the
intent(in), or possibly because of b being unused (in which case, even the copy
in could be avoided). It seems an obvious enough optimization provided that the
compiler has the right information at the right time to do it. However, the
standard does *NOT* require this optimization. Failure to do the optimization
does not constitute a compiler bug in terms of implementing the standard
(though it might indicate that the compiler has room to improve its
optimization)."

http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/2b4df0a44e704b7f/70c44bc5ea8cafb0


-- 
           Summary: aliasing amoung dummy arguments: possibly missing
                    optimization
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30374


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]