public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, fortran] Fix PR59345, repacking of a packed temporary array
@ 2019-01-10 20:17 Thomas Koenig
  2019-01-11  0:58 ` Steve Kargl
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Koenig @ 2019-01-10 20:17 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Hello world,

the attached patch fixes a rather bad missed optimization, where
the generated temporary array for

SUBROUTINE S1(A)
  REAL :: A(3)
  CALL S2(-A)
END SUBROUTINE


was packed and unpacked(!).

Regression-tested. OK for trunk?

Regards

	Thomas

2019-01-10  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/59345
         * trans-array.c (gfc_conv_parameter_array):  Temporary
         arrays generated for expressions do not need to be repacked.

2019-01-10  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/59345
         * gfortran.dg/internal_pack_16.f90: New test.

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

Index: trans-array.c
===================================================================
--- trans-array.c	(Revision 267737)
+++ trans-array.c	(Arbeitskopie)
@@ -7866,6 +7866,12 @@ gfc_conv_array_parameter (gfc_se * se, gfc_expr *
 
   no_pack = contiguous && no_pack;
 
+  /* If we have an expression, an array temporary will be
+     generated which does not need to be packed / unpacked
+     if passed to an explicit-shape dummy array.  */
+
+  no_pack = no_pack || (g77 && expr->expr_type == EXPR_OP);
+
   /* Array constructors are always contiguous and do not need packing.  */
   array_constructor = g77 && !this_array_result && expr->expr_type == EXPR_ARRAY;
 

[-- Attachment #3: internal_pack_16.f90 --]
[-- Type: text/x-fortran, Size: 328 bytes --]

! { dg-do compile }
! { dg-additional-options "-fdump-tree-original" }
! PR 59345 - pack/unpack was not needed here.
SUBROUTINE S1(A)
 REAL :: A(3)
 CALL S2(-A)
END SUBROUTINE
! { dg-final { scan-tree-dump-not "_gfortran_internal_pack" "original" } }
! { dg-final { scan-tree-dump-not "_gfortran_internal_unpack" "original" } }

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

* Re: [Patch, fortran] Fix PR59345, repacking of a packed temporary array
  2019-01-10 20:17 [Patch, fortran] Fix PR59345, repacking of a packed temporary array Thomas Koenig
@ 2019-01-11  0:58 ` Steve Kargl
  0 siblings, 0 replies; 2+ messages in thread
From: Steve Kargl @ 2019-01-11  0:58 UTC (permalink / raw)
  To: Thomas Koenig; +Cc: fortran, gcc-patches

On Thu, Jan 10, 2019 at 09:17:37PM +0100, Thomas Koenig wrote:
> 
> the attached patch fixes a rather bad missed optimization, where
> the generated temporary array for
> 
> SUBROUTINE S1(A)
>   REAL :: A(3)
>   CALL S2(-A)
> END SUBROUTINE
> 
> was packed and unpacked(!).
> 
> Regression-tested. OK for trunk?
> 

Yes.

-- 
Steve

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

end of thread, other threads:[~2019-01-11  0:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-10 20:17 [Patch, fortran] Fix PR59345, repacking of a packed temporary array Thomas Koenig
2019-01-11  0:58 ` Steve Kargl

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