This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[FORTRAN PATCH] Improve compute_overall_iter_number


The following patch is a further improvement to the way the gfortran
front-end translates nested FORALL statements.  One aspect of this
translation is the calculation of the number of times the body of a loop
nest will be executed.
This is done by trans-stmt.c:compute_overall_iter_number which contains a
TODO comment with the words "optimize the computing process".  By default,
the current implementation is to expand a complete copy of the loop nest,
incrementing a counter in the body to determine the size at run-time.

The patch below tackles the common/simple case of unconditional loop nests
with constant bounds.  In this case, the body is executed
bound1*bound2*...
boundN times.

Unfortunately, I've not provided a testcase for this optimization, as it's
tricky to test for and generated code is very likely to change in the near
future, but the benefits can be seen with the testcase below (contributed
to Steve Kargl's request for FORALL examples).

  integer a(100,100)
  outer: forall (i=1:100)
    inner: forall (j=1:100,i.ne.j)
      a(i,j) = a(j,i)
    end forall inner
  end forall outer
end

In this matrix transpose calculation we need to determine the number of
times "i .ne. j" is executed, to allocate a suitable execution mask for
it.  With the patch below, we can now establish at compile-time (in the
front-end) that the answer is 10,000 times, and allocate a suitable stack
temporary, rather than expand loops and call malloc.


The following patch has been tesed on x86_64-unknown-linux-gnu, with a
full "make bootstrap", including gfortran, and regression tested with a
top-level "make -k check" with no new failures.

Ok for mainline?


2007-01-16  Roger Sayle  <roger@eyesopen.com>

        * trans-stmt.c (compute_overall_iter_number): Enhance to precompute
        the number of interations in unconditional FORALL nests with constant
        bounds.

Roger
--

Attachment: patchf2.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]