I wonder if Graphite can do this one (or is planned to be able to):
Another loop optimization that suggests itself
is the following, trying to eliminate unnecessary
loop constructs:
\begin{verbatim}
SUBROUTINE SUB(A, B, C, N, M)
REAL A(N, M), B(N, M), C(N, M)
DO J = 1, M
DO I = 1, N
C(I, J) = A(I, J) + B(I, J)
ENDDO
ENDDO
END
\end{verbatim}
If we could generate code that looks like what is
written below, we would have nothing but
{\em one} loop.
\begin{verbatim}
DO K = 1, M*N
C(K, 1) = A(K, 1) + B(K, 1)
ENDDO
\end{verbatim}
In this case, this transformation can be done
because the tuple $(i,j)$ forms an induction
variable $i+n*(j-1)$ in its own right
(replaced by $k$ in the {\em collapsed} loop).
This is the latex from a set of slides I used in my LinuxExpo '99 talk
(22nd of May 1999).
These loop nests result quite naturally from whole array expressions in
Fortran.
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/
Progress of GNU Fortran: http://gcc.gnu.org/gcc-4.5/changes.html