public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-9652] Fortran: do not frontend-optimize MINLOC/MAXLOC for character arrays
Date: Sun, 13 Mar 2022 20:44:31 +0000 (GMT)	[thread overview]
Message-ID: <20220313204431.C66E03858C27@sourceware.org> (raw)

https://gcc.gnu.org/g:47f89da89eb0ddc9ed87192886ff633a790fe08c

commit r11-9652-g47f89da89eb0ddc9ed87192886ff633a790fe08c
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Tue Mar 8 21:47:04 2022 +0100

    Fortran: do not frontend-optimize MINLOC/MAXLOC for character arrays
    
    gcc/fortran/ChangeLog:
    
            PR fortran/104811
            * frontend-passes.c (optimize_minmaxloc): Do not attempt
            frontend-optimization of MINLOC/MAXLOC for character arrays, as
            there is no suitable code yet for inline expansion.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/104811
            * gfortran.dg/minmaxloc_16.f90: New test.
    
    (cherry picked from commit e3e369dad6cbecb1b490b3f3b154c600fba5a6f3)

Diff:
---
 gcc/fortran/frontend-passes.c              |  1 +
 gcc/testsuite/gfortran.dg/minmaxloc_16.f90 | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c
index b58cc249f23..ad1ba397803 100644
--- a/gcc/fortran/frontend-passes.c
+++ b/gcc/fortran/frontend-passes.c
@@ -2276,6 +2276,7 @@ optimize_minmaxloc (gfc_expr **e)
   if (fn->rank != 1
       || fn->value.function.actual == NULL
       || fn->value.function.actual->expr == NULL
+      || fn->value.function.actual->expr->ts.type == BT_CHARACTER
       || fn->value.function.actual->expr->rank != 1)
     return;
 
diff --git a/gcc/testsuite/gfortran.dg/minmaxloc_16.f90 b/gcc/testsuite/gfortran.dg/minmaxloc_16.f90
new file mode 100644
index 00000000000..099248df2e3
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/minmaxloc_16.f90
@@ -0,0 +1,14 @@
+! { dg-do run }
+! { dg-options "-fdump-tree-original" }
+! PR fortran/104811
+! Frontend-optimization mis-optimized minloc/maxloc of character arrays
+
+program p
+  character(1) :: str(3)
+  str = ["a", "c", "a"]
+  if (any (maxloc (str) /= 2)) stop 1
+  if (minloc (str,dim=1) /= 1) stop 2
+end
+
+! { dg-final { scan-tree-dump-times "_gfortran_maxloc0_4_s1" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_minloc2_4_s1" 1 "original" } }


                 reply	other threads:[~2022-03-13 20:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220313204431.C66E03858C27@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).