On Sat, Aug 7, 2010 at 8:44 PM, Toon Moene <t...@moene.org> wrote: > 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 could already infer it if we'd infer value-ranges from general operations based on when they'd invoke undefined behavior (thus, out-of-bound array accesses). But no, the frontend cannot currently communicate such things. This would, btw, also disable array-bounds warnings - as that does rely on "true" value ranges being used, like for int a[3]; for (i = 0; i < 10; ++i) tem += a[i]; if we'd infer [0, 2] for i from a[i] we'd no longer warn that you access a out-of-bounds. So I'm not sure it would be a good idea. It's better to communicate object sizes to the middle-end (in case your example would have used an allocatable array). Richard. > [ 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 >