]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fortran: delinearize multi-dimensional array accesses
authorSandra Loosemore <sandra@codesourcery.com>
Tue, 16 Nov 2021 15:09:51 +0000 (16:09 +0100)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Tue, 21 Jun 2022 13:11:42 +0000 (14:11 +0100)
commit39a8c371fda6136cf77c74895a00b136409e0ba3
tree6905e50a6c26dc94951a07849d480bc05b34352a
parenta89c485b5d148bf153d5db48c3c5c02d5f3890e9
Fortran: delinearize multi-dimensional array accesses

The Fortran front end presently linearizes accesses to
multi-dimensional arrays by combining the indices for the various
dimensions into a series of explicit multiplies and adds with
refactoring to allow CSE of invariant parts of the computation.
Unfortunately this representation interferes with Graphite-based loop
optimizations.  It is difficult to recover the original
multi-dimensional form of the access by the time loop optimizations
run because parts of it have already been optimized away or into a
form that is not easily recognizable, so it seems better to have the
Fortran front end produce delinearized accesses to begin with, a set
of nested ARRAY_REFs similar to the existing behavior of the C and C++
front ends.  This is a long-standing problem that has previously been
discussed e.g. in PR 14741 and PR61000.

This patch is an initial implementation for explicit array accesses
only; it doesn't handle the accesses generated during scalarization of
whole-array or array-section operations, which follow a different code
path.

        gcc/
        * expr.cc (get_inner_reference): Handle NOP_EXPR like
        VIEW_CONVERT_EXPR.

        gcc/fortran/
        * lang.opt (-param=delinearize=): New.
        * trans-array.cc (get_class_array_vptr): New, split from...
        (build_array_ref): ...here.
        (get_array_lbound, get_array_ubound): New, split from...
        (gfc_conv_array_ref): ...here.  Additional code refactoring
        plus support for delinearization of the array access.

        gcc/testsuite/
        * gfortran.dg/assumed_type_2.f90: Adjust patterns.
        * gfortran.dg/goacc/kernels-loop-inner.f95: Likewise.
        * gfortran.dg/graphite/block-3.f90: Remove xfails.
        * gfortran.dg/graphite/block-4.f90: Likewise.
        * gfortran.dg/inline_matmul_24.f90: Adjust patterns.
        * gfortran.dg/no_arg_check_2.f90: Likewise.
        * gfortran.dg/pr32921.f: Likewise.
        * gfortran.dg/reassoc_4.f: Disable delinearization for this test.

Co-Authored-By: Tobias Burnus <tobias@codesourcery.com>
16 files changed:
gcc/ChangeLog.omp
gcc/expr.cc
gcc/fortran/ChangeLog.omp
gcc/fortran/lang.opt
gcc/fortran/trans-array.cc
gcc/testsuite/ChangeLog.omp
gcc/testsuite/gfortran.dg/assumed_type_2.f90
gcc/testsuite/gfortran.dg/goacc/kernels-loop-inner.f95
gcc/testsuite/gfortran.dg/graphite/block-2.f
gcc/testsuite/gfortran.dg/graphite/block-3.f90
gcc/testsuite/gfortran.dg/graphite/block-4.f90
gcc/testsuite/gfortran.dg/graphite/id-9.f
gcc/testsuite/gfortran.dg/inline_matmul_24.f90
gcc/testsuite/gfortran.dg/no_arg_check_2.f90
gcc/testsuite/gfortran.dg/pr32921.f
gcc/testsuite/gfortran.dg/reassoc_4.f