This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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] Use memcpy for array constructor assignments


The following patch builds upon the two previous patches to (1) use
statically initialized arrays to implement array constructors and (2) use
__builtin_memcpy when copying one array to another.  With this installment
we reuse the functionality of the previous two patches, to now use
__builtin_memcpy when assigning an array from a constant array
constructor.

Currently, the testcase below

  integer :: x(4)
  x(:) = (/ 3, 1, 4, 1 /)

is expanded as

  static int4 A.0[4] = {3, 1, 4, 1};

  {
    int8 S.1;

    S.1 = 1;
    while (1)
      {
        if (S.1 > 4) goto L.1;
        (*x)[S.1 + -1] = A.0[S.1 + -1];
        S.1 = S.1 + 1;
      }
    L.1:;
  }

but with this patch we now generate

  static int4 A.0[4] = {3, 1, 4, 1};
  (void) __builtin_memcpy ((void *) x, (void *) &A.0, 16);


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.  This change required one
minor bug-fix to dependency.c's full_array_ref_p, and an update to the
gfortran.dg/vect/vect-5.f90 testcase, which now contains one less loop to
vectorize.

Ok for mainline?


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

        * dependency.c (gfc_full_array_ref_p): Check that ref->next is NULL,
        i.e. that the ARRAY_REF doesn't mention components.
        * trans-array.c (gfc_constant_array_constructor_p): Export external
        function renamed from constant_array_constructor_p.
        (gfc_build_constant_array_constructor): Export.
        (gfc_trans_array_constructor): Update call to the renamed function
        constant_array_constructor_p.
        * trans-array.h (gfc_constant_array_constructor_p): Prototype here.
        (gfc_build_constant_array_constructor): Likewise.
        * trans-expr.c (gfc_build_memcpy_call): New helper function split
        out from gfc_trans_array_copy.
        (gfc_trans_array_copy): Use gfc_build_memcpy_call.
        (gfc_trans_array_constructor_copy): New function to optimize
        assigning an entire array from a constant array constructor.
        (gfc_trans_assignment): Call gfc_trans_array_constructor_copy
        when appropriate.

        * gfortran.dg/array_memcpy_3.f90: New test case.
        * gfortran.dg/vect/vect-5.f90: Update vectorized loop count.

Roger
--

Attachment: patchf3.txt
Description: Text document

Attachment: array_memcpy_3.f90
Description: Text document

Attachment: testf3.txt
Description: Text document


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