diff mbox series

[fortran] Fix PR59345, repacking of a packed temporary array

Message ID 0f159bf9-42ab-5692-d6f5-dcb8c789410d@netcologne.de
State New
Headers show
Series [fortran] Fix PR59345, repacking of a packed temporary array | expand

Commit Message

Thomas Koenig Jan. 10, 2019, 8:17 p.m. UTC
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.

Comments

Steve Kargl Jan. 11, 2019, 12:58 a.m. UTC | #1
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.
diff mbox series

Patch

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;