[patch, fortran] Inline packing for array temporaries

Thomas Koenig tkoenig@netcologne.de
Sun Apr 28 12:19:00 GMT 2019


Hello world,

going back a patch which was not included in gcc-9 because it was too
late in the development cycle, here is a patch which, when optimizing
and not optimizing for size, does inline packing for an argument.
As you can see from the code and the test cases, there is provision
for optional arguments.  It was necessary to split some test cases
to take account for the new pack inline / pack in the library split.

I did regression-testing on x86_64-pc-linux-gnu, in 64-bit mode.
(Dominique, could you tell us again what the magic incantation for
32-bit mode is?)

OK for trunk?  (Not for backporting)

Regards

	Thomas

2019-04-28  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/88821
         * expr.c (gfc_is_simply_contiguous): Return true for
         an EXPR_ARRAY.
         * trans-array.c (is_pointer): New function.
         (gfc_conv_array_parameter): Call gfc_conv_subref_array_arg
         when not optimizing and not optimizing for size if the formal
         arg is passed by reference.
         * trans-expr.c (gfc_conv_subref_array_arg): Add arguments
         fsym, proc_name and sym.  Add run-time warning for temporary
         array creation.  Wrap argument if passing on an optional
         argument to an optional argument.
         * trans.h (gfc_conv_subref_array_arg): Add optional arguments
         fsym, proc_name and sym to prototype.

2019-04-28  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/88821
         * gfortran.dg/alloc_comp_auto_array_3.f90: Add -O0 to dg-options
         to make sure the test for internal_pack is retained.
         * gfortran.dg/assumed_type_2.f90: Split compile and run time
         tests into this and
         * gfortran.dg/assumed_type_2a.f90: New file.
         * gfortran.dg/c_loc_test_22.f90: Likewise.
         * gfortran.dg/contiguous_3.f90: Likewise.
         * gfortran.dg/internal_pack_11.f90: Likewise.
         * gfortran.dg/internal_pack_12.f90: Likewise.
         * gfortran.dg/internal_pack_16.f90: Likewise.
         * gfortran.dg/internal_pack_17.f90: Likewise.
         * gfortran.dg/internal_pack_18.f90: Likewise.
         * gfortran.dg/internal_pack_4.f90: Likewise.
         * gfortran.dg/internal_pack_5.f90: Add -O0 to dg-options
         to make sure the test for internal_pack is retained.
         * gfortran.dg/internal_pack_6.f90: Split compile and run time
         tests into this and
         * gfortran.dg/internal_pack_6a.f90: New file.
         * gfortran.dg/internal_pack_8.f90: Likewise.
         * gfortran.dg/missing_optional_dummy_6: Split compile and run time
         tests into this and
         * gfortran.dg/missing_optional_dummy_6a.f90: New file.
         * gfortran.dg/no_arg_check_2.f90: Split compile and run time tests
         into this and
         * gfortran.dg/no_arg_check_2a.f90: New file.
         * gfortran.dg/typebound_assignment_5.f90: Split compile and run 
time
         tests into this and
         * gfortran.dg/typebound_assignment_5a.f90: New file.
         * gfortran.dg/typebound_assignment_6.f90: Split compile and run 
time
         tests into this and
         * gfortran.dg/typebound_assignment_6a.f90: New file.
         * gfortran.dg/internal_pack_19.f90: New file.
         * gfortran.dg/internal_pack_20.f90: New file.
         * gfortran.dg/internal_pack_21.f90: New file.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: internal_pack_21.f90
Type: text/x-fortran
Size: 659 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190428/0977d1a8/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: internal_pack_20.f90
Type: text/x-fortran
Size: 537 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190428/0977d1a8/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: internal_pack_19.f90
Type: text/x-fortran
Size: 539 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190428/0977d1a8/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: missing_optional_dummy_6a.f90
Type: text/x-fortran
Size: 1622 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190428/0977d1a8/attachment-0003.bin>
-------------- next part --------------
! { dg-do compile }
! { dg-options "-O0 -fdump-tree-original" }
!
! PR fortran/56136
! ICE on defined assignment with class arrays.
!
! Original testcase by Alipasha <alipash.celeris@gmail.com>

      MODULE A_TEST_M
        TYPE :: A_TYPE
          INTEGER :: I
          CONTAINS
          GENERIC :: ASSIGNMENT (=) => ASGN_A
          PROCEDURE, PRIVATE :: ASGN_A
        END TYPE

        CONTAINS

        ELEMENTAL SUBROUTINE ASGN_A (A, B)
          CLASS (A_TYPE), INTENT (INOUT) :: A
          CLASS (A_TYPE), INTENT (IN) :: B
          A%I = B%I
        END SUBROUTINE
      END MODULE A_TEST_M
      
      PROGRAM ASGN_REALLOC_TEST
        USE A_TEST_M
        TYPE (A_TYPE), ALLOCATABLE :: A(:)
        INTEGER :: I, J

        ALLOCATE (A(100))
        A = (/ (A_TYPE(I), I=1,SIZE(A)) /)
        A(1:50) = A(51:100)
        IF (ANY(A%I /= (/ ((50+I, I=1,SIZE(A)/2), J=1,2) /))) STOP 1
        A(::2) = A(1:50)        ! pack/unpack
        IF (ANY(A( ::2)%I /= (/ (50+I, I=1,SIZE(A)/2) /))) STOP 2
        IF (ANY(A(2::2)%I /= (/ ((50+2*I, I=1,SIZE(A)/4), J=1,2) /))) STOP 3
      END PROGRAM

! { dg-final { scan-tree-dump-times "_gfortran_internal_pack" 1 "original" } }
! { dg-final { scan-tree-dump-times "_gfortran_internal_unpack" 1 "original" } }

-------------- next part --------------
! { dg-do run }
!
! PR fortran/49074
! ICE on defined assignment with class arrays.

      module foo
        type bar
          integer :: i

          contains

          generic :: assignment (=) => assgn_bar
          procedure, private :: assgn_bar
        end type bar

        contains

        elemental subroutine assgn_bar (a, b)
          class (bar), intent (inout) :: a
          class (bar), intent (in) :: b

          select type (b)
          type is (bar)
            a%i = b%i
          end select

          return
        end subroutine assgn_bar
      end module foo

      program main
        use foo

        type (bar), allocatable :: foobar(:)

        allocate (foobar(2))
        foobar = [bar(1), bar(2)]
        if (any(foobar%i /= [1, 2])) STOP 1
      end program
-------------- next part --------------
A non-text attachment was scrubbed...
Name: no_arg_check_2a.f90
Type: text/x-fortran
Size: 3477 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190428/0977d1a8/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: internal_pack_6a.f90
Type: text/x-fortran
Size: 1217 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190428/0977d1a8/attachment-0005.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: assumed_type_2a.f90
Type: text/x-fortran
Size: 4362 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190428/0977d1a8/attachment-0006.bin>


More information about the Gcc-patches mailing list