Recently, Thomas Koenig introduced an optimization in the Fortran Front End that enables it do determine that in:

subroutine foo(a,n,i,j)
  implicit none
  integer, intent(in) :: i,j,n
  real, dimension(20) :: a
  a(1:10) = a(i:j)
  ...
end subroutine foo

the assignment of a(i:j) to a(1:10) does not need a temporary array to store a(i:j), because i cannot be smaller than 1 (the lower bound of the array a, by its declaration as "real, dimension(20) :: a", which establishes a as an array of real, a(1:20).)

Because i cannot be legally smaller than 1, this assignment can be performed without a temporary (either it is a partial copy of an exactly overlapping array slice, or it copies from higher indices to lower).

However, two more observations can be drawn from the fact that both sides of the assignment have to be conformable (of the same shape):

1 <= i <= 11 (because a ten element copy can't arrive after element 11).
j = i + 9    (because the LHS is ten elements long, so the RHS).

Can this information be passed from the Front End to GIMPLE, for use in Value Range Propagation optimization ? If so, how ?

[ It might be hard to generalize this to multi-rank arrays, yet the
  opportunity is there ]

Cheers,

--
Toon Moene - e-mail: t...@moene.org - phone: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
At home: http://moene.org/~toon/; weather: http://moene.org/~hirlam/
Progress of GNU Fortran: http://gcc.gnu.org/gcc-4.5/changes.html#Fortran

Reply via email to