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

           Summary: Unnecessary function evaluations in arguments to size
                    and ubound
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: fortran
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: tkoe...@gcc.gnu.org


ig25@linux-fd1f:~/Krempel/Size> cat size.f90
subroutine foo(a,b,n,m,k, i)
  implicit none
  integer, intent(in) :: n
  real, dimension(n,n) :: a,b
  integer, intent(out) :: m,k,i
  m = size(matmul(a,b))
  k = size(sum(a,1))
  i = size(maxloc(a,1))
  m = ubound(matmul(a,b),1)
  k = ubound(sum(a,1),1)
  i = ubound(maxloc(a,1),1)
end
ig25@linux-fd1f:~/Krempel/Size> gfortran -S -O -fdump-tree-optimized size.f90
ig25@linux-fd1f:~/Krempel/Size> grep _gfortran size.s
        call    _gfortran_matmul_r4
        call    _gfortran_size0
        call    _gfortran_sum_r4
        call    _gfortran_maxloc1_4_r4
        call    _gfortran_matmul_r4
        call    _gfortran_sum_r4
        call    _gfortran_maxloc1_4_r4

None of the function calls is needed to calculate the size; this
could be done during simplification or optimization.

Reply via email to