public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Mikael Morin <mikael@gcc.gnu.org>
To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org
Cc: Richard Biener <rguenther@suse.de>
Subject: [PATCH 0/4]  Use pointer arithmetic for array references [PR102043]
Date: Sat, 16 Apr 2022 18:56:14 +0200	[thread overview]
Message-ID: <20220416165618.236666-1-mikael@gcc.gnu.org> (raw)

Hello,

this is a fix for PR102043, which is a wrong code bug caused by the
middle-end concluding from array indexing that the array index is
non-negative.  This is a wrong assumption for "reversed arrays",
that is arrays whose descriptor makes accesses to the array from
last element to first element.  More generally the wrong cases are
arrays with a descriptor having a negative stride for at least one 
dimension.

I have been trying to fix this by stopping the front-end from generating
bogus code, by either stripping array-ness from descriptor data
pointers, or by changing the initialization of data pointers to point
to the first element in memory order instead of the first element in
access order (which is the last in memory order for reversed arrays).
Both ways are very impacting changes to the frontend and I haven’t
been able to eliminate all the regressions in time using either way.

However, Richi showed with a patch attached to the PR that array
references are crucial for the problem to appear, and everything works
if array indexing is replaced with pointer arithmetic.  This is
much simpler and doesn’t imply invasive changes to the frontend.

I have built on top of his patch to keep the array indexing in cases
where the change to pointer arithmetic is not necessary, either because
the array is not a fortran array with a descriptor, or because it’s
known to be contiguous.  This has the benefit of reducing the churn
in the dumped code patterns used in the testsuite.  It also avoids
ICE regression such as interface_12.f90 or result_in_spec.f90, but
I can’t exclude that those could be a real problem made latent.

Patches 1 to 3 are preliminary changes to avoid regressions.  The main
change is number 4, the last in the series.

Regression tested on x86_64-pc-linux-gnu.  OK for master?

Mikael Morin (4):
  fortran: Pre-evaluate string pointers. [PR102043]
  fortran: Update index extraction code. [PR102043]
  fortran: Generate an array temporary reference [PR102043]
  fortran: Use pointer arithmetic to index arrays [PR102043]

 gcc/fortran/trans-array.cc                    |  60 +++++-
 gcc/fortran/trans-expr.cc                     |   9 +-
 gcc/fortran/trans-io.cc                       |  48 ++++-
 gcc/fortran/trans.cc                          |  42 +++-
 gcc/fortran/trans.h                           |   4 +-
 .../gfortran.dg/array_reference_3.f90         | 195 ++++++++++++++++++
 gcc/testsuite/gfortran.dg/c_loc_test_22.f90   |   4 +-
 gcc/testsuite/gfortran.dg/dependency_49.f90   |   3 +-
 gcc/testsuite/gfortran.dg/finalize_10.f90     |   2 +-
 .../gfortran.dg/negative_stride_1.f90         |  25 +++
 .../gfortran.dg/vector_subscript_8.f90        |  16 ++
 .../gfortran.dg/vector_subscript_9.f90        |  21 ++
 12 files changed, 401 insertions(+), 28 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/array_reference_3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/negative_stride_1.f90
 create mode 100644 gcc/testsuite/gfortran.dg/vector_subscript_8.f90
 create mode 100644 gcc/testsuite/gfortran.dg/vector_subscript_9.f90

-- 
2.35.1


             reply	other threads:[~2022-04-16 16:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-16 16:56 Mikael Morin [this message]
2022-04-16 16:56 ` [PATCH 1/4] fortran: Pre-evaluate string pointers. [PR102043] Mikael Morin
2022-04-16 16:56 ` [PATCH 2/4] fortran: Update index extraction code. [PR102043] Mikael Morin
2022-04-16 16:56 ` [PATCH 3/4] fortran: Generate an array temporary reference [PR102043] Mikael Morin
2022-04-16 16:56 ` [PATCH 4/4] fortran: Use pointer arithmetic to index arrays [PR102043] Mikael Morin
2022-04-19 15:05 ` [PATCH 0/4] Use pointer arithmetic for array references [PR102043] Richard Biener
2022-04-22 11:09 ` *PING* " Mikael Morin
2022-04-22 13:59   ` Thomas Koenig
2022-04-24  1:57     ` Jerry D
2022-04-26 14:40     ` Hans-Peter Nilsson
2022-04-27  5:48       ` Thomas Koenig
2022-05-02  7:16       ` Stefan Schulze Frielinghaus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220416165618.236666-1-mikael@gcc.gnu.org \
    --to=mikael@gcc.gnu.org \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).