[FORTRAN PATCH] Generalize constant array construction to multiple dimensions

Roger Sayle roger@eyesopen.com
Mon Feb 12 04:36:00 GMT 2007


The following patch is a generalization of my recent constant array
constructor improvements to avoid creating/copying temporary arrays when
using EXPR_ARRAYs with rank greater than one.  Previously, we'd avoid the
need for a temporary only for one dimensional arrays, but the with a
little effort this can be generalized to matrices, grids, etc.. that
result from using the RESHAPE intrinsic.

This enhancement greatly simplifies the code we generate for:

  integer :: x(2,2)
  if (any(x(:,:) .ne. reshape ((/ 3, 1, 4, 1 /), (/ 2, 2 /))))
    call abort ()

[Whilst I was there I also noticed the above ANY intrinsic was generating
generic of the form "(x[i] != A[i]) != 0", which is caused by not folding
the comparison against zero.  This is also fixed in the patch below.]

The following patch has been tested 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-02-11  Roger Sayle  <roger@eyesopen.com>

        * trans-array.c (gfc_build_constant_array_constructor): When the
        shape of the constructor is known, use that to construct the
        gfc_array_spec.
        (gfc_trans_constant_array_constructor): Initialize the "info"
        information for all of the dimensions of the array constructor.
        (constant_array_constructor_loop_size): New function.
        (gfc_trans_array_constructor): Use it to determine whether a
        loop is suitable for "constant array constructor" optimization.

        * trans-intrinsic.c (gfc_conv_intrinsic_anyall): Use fold_build2
        instead of build2, to avoid conditions like "(a != b) != 0".

        * gfortran.dg/array_constructor_15.f90: New test case.

Roger
--
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patchf.txt
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070212/f167fd32/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: array_constructor_15.f90
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070212/f167fd32/attachment.f90>


More information about the Fortran mailing list