http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48997
Summary: Don't use allocatable arrays for function elimination Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: fortran AssignedTo: unassig...@gcc.gnu.org ReportedBy: tkoe...@gcc.gnu.org Blocks: 36854 After revision 173752, double occurrence of functions returning arrays within an expression are removed using an allocatable array as temporary. It would be better to use BLOCK variables. Example: Transform function optmatmul (a, b, ni, nj) implicit none integer, intent(in) :: ni, nj double precision :: optmatmul(ni, nj) double precision, intent(in) :: a(ni, nj), b(ni, nj) optmatmul = matmul(a, b) / (1 + matmul(a, b)) end function optmatmul (the test case from PR 22572) to function optmatmul (a, b, c, m, n, count) implicit none integer, intent(in) :: m, n, count double precision :: optmatmul(m, n) double precision, intent(in) :: a(m, count), b(count, n), c(m, n) block double precision, dimension(size(a,1), size(b,2)) :: tmp tmp = matmul(a,b) optmatmul = tmp / (1 + tmp) end block end function optmatmul We would probably need argument mapping for this. Issues to be resolved: - This is complicated, especially for intrinsics which take their return size from their arguments - Especially ugly: pack - Also not nice: dim=n arguments where n is a variable - We would need a way to handle functions in argument lists specifying return dimensions, which we have to keep from being evaluated twice (not a likely corner case, but we have to be correct...)