Related to some other missed-optimization PRs, but particularly simple.

  REAL, allocatable :: ot(:)
  integer :: time_steps

  call foo (ot) ! OK, no temporary
  call foo (ot(0:5:1)) ! Unnecessary temporary
  call foo (ot(0:time_steps)) ! Unnecessary temporary
  end

Note: ot is contiguous (as it is allocatable), stride = 1, and thus all
arguments are simple contiguous - unless the stride is non-unity or one has,
e.g., "ot( [1,3,5])".

Note 2: If one has an explicit-size array, it works - there is no temporary
for:
  REAL :: ot(5)
  integer :: time_steps
  call foo (ot(1:time_steps))
I think the issue is that one mixes up the (:) of an allocatable array with the
(:) of a non-allocatable, assumed-shape dummy argument or a pointer.

The temporary seems to be generated in trans-arrays.c's
gfc_conv_array_parameter; the issue seems to be that "full_array_var" is false
and then later there is either no_pack or contiguous set to false.


-- 
           Summary: Unnecessary array temporary: Passing contiguous array as
                    actual argument
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          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=43173

Reply via email to