public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, fortran] Fix PR 100227, write with implied DO loop
@ 2021-07-04 16:09 Thomas Koenig
  2021-07-05 18:33 ` Jerry D
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Koenig @ 2021-07-04 16:09 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 870 bytes --]

Hello world,

after a bit of an absence, I am now back, at least for some regression
fixing (and for reviewing patches, if that is called for).

So, here's a regression fix to start with.

OK for trunk and affected branches (down to 9)?

Best regards

	Thomas

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.

[-- Attachment #2: p1.diff --]
[-- Type: text/x-patch, Size: 1394 bytes --]

diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c
index 72a4e0410b1..996dcc2e547 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] 3+ messages in thread

* Re: [patch, fortran] Fix PR 100227, write with implied DO loop
  2021-07-04 16:09 [patch, fortran] Fix PR 100227, write with implied DO loop Thomas Koenig
@ 2021-07-05 18:33 ` Jerry D
  2021-07-07  5:25   ` Thomas Koenig
  0 siblings, 1 reply; 3+ messages in thread
From: Jerry D @ 2021-07-05 18:33 UTC (permalink / raw)
  To: Thomas Koenig, fortran, gcc-patches

Looks OK Thomas,

Good for backport as well.

Regards,

Jerry

On 7/4/21 9:09 AM, Thomas Koenig via Fortran wrote:
> Hello world,
>
> after a bit of an absence, I am now back, at least for some regression
> fixing (and for reviewing patches, if that is called for).
>
> So, here's a regression fix to start with.
>
> OK for trunk and affected branches (down to 9)?
>
> Best regards
>
>     Thomas
>
> 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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch, fortran] Fix PR 100227, write with implied DO loop
  2021-07-05 18:33 ` Jerry D
@ 2021-07-07  5:25   ` Thomas Koenig
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Koenig @ 2021-07-07  5:25 UTC (permalink / raw)
  To: Jerry D, fortran, gcc-patches


Hi Jerry,

> Looks OK Thomas,
> 
> Good for backport as well.

Thanks.  Committed to trunk so far, will add a git worktree for
gcc11 next :-)

Best regards

	Thomas

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-07  5:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-04 16:09 [patch, fortran] Fix PR 100227, write with implied DO loop Thomas Koenig
2021-07-05 18:33 ` Jerry D
2021-07-07  5:25   ` Thomas Koenig

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