public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: "Thomas König" <tkoenig@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-8708] Do not replace variable op variable in I/O implied DO loop replacement.
Date: Thu,  8 Jul 2021 21:09:17 +0000 (GMT)	[thread overview]
Message-ID: <20210708210917.B5582385BC23@sourceware.org> (raw)

https://gcc.gnu.org/g:ba58662d013aa14d408a0e7172765e3da707a9eb

commit r11-8708-gba58662d013aa14d408a0e7172765e3da707a9eb
Author: Thomas Koenig <tkoenig@gcc.gnu.org>
Date:   Tue Jul 6 07:04:09 2021 +0200

    Do not replace variable op variable in I/O implied DO loop replacement.
    
    This PR came about because index expressions of the form k+k in
    implied DO loops in I/O statements were considered for replacement
    by array slices.
    
    Fixed by only doing the transformation if the expression is of the
    type expr OP contastant.
    
    gcc/fortran/ChangeLog:
    
            PR fortran/100227
            * frontend-passes.c (traverse_io_block): Adjust test for
            when a variable is eligible for the transformation to
            array slice.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/100227
            * gfortran.dg/implied_do_io_7.f90: New test.
    
    (cherry picked from commit d7e3855d5dd8c001bb65dc7da1cda0249bfc2986)

Diff:
---
 gcc/fortran/frontend-passes.c                 |  4 ++--
 gcc/testsuite/gfortran.dg/implied_do_io_7.f90 | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c
index 213530e46e1..cc91fc95ee0 100644
--- a/gcc/fortran/frontend-passes.c
+++ b/gcc/fortran/frontend-passes.c
@@ -1299,8 +1299,8 @@ traverse_io_block (gfc_code *code, bool *has_reached, gfc_code *prev)
 		std::swap (start->value.op.op1, start->value.op.op2);
 	      gcc_fallthrough ();
 	    case INTRINSIC_MINUS:
-	      if ((start->value.op.op1->expr_type!= EXPR_VARIABLE
-		   && start->value.op.op2->expr_type != EXPR_CONSTANT)
+	      if (start->value.op.op1->expr_type!= EXPR_VARIABLE
+		  || start->value.op.op2->expr_type != EXPR_CONSTANT
 		  || start->value.op.op1->ref)
 		return false;
 	      if (!stack_top || !stack_top->iter
diff --git a/gcc/testsuite/gfortran.dg/implied_do_io_7.f90 b/gcc/testsuite/gfortran.dg/implied_do_io_7.f90
new file mode 100644
index 00000000000..63927aafea9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/implied_do_io_7.f90
@@ -0,0 +1,16 @@
+! { dg-do run }
+! PR 100227 - this was falsely optimized, leading to nonsense  results.
+! Original test case by "Mathieu".
+
+program p
+  implicit none
+  integer, parameter :: nbmode = 3
+  integer :: k
+  real    :: mass(nbmode*2)
+  character (len=80) :: line
+  do k = 1, nbmode*2
+     mass(k) = k
+  end do
+  write (unit=line,fmt='(*(F6.2))') (mass(k+k), k=1,nbmode)
+  if (line /= '  2.00  4.00  6.00') stop 1
+end program


                 reply	other threads:[~2021-07-08 21:09 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=20210708210917.B5582385BC23@sourceware.org \
    --to=tkoenig@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).