public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-8708] Do not replace variable op variable in I/O implied DO loop replacement.
@ 2021-07-08 21:09 Thomas König
  0 siblings, 0 replies; only message in thread
From: Thomas König @ 2021-07-08 21:09 UTC (permalink / raw)
  To: gcc-cvs

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-08 21:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08 21:09 [gcc r11-8708] Do not replace variable op variable in I/O implied DO loop replacement Thomas König

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).