This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, fortran] PR40472 - Simplification of spread intrinsic takes a long time


Dear All,

This is another obvious one - at the moment, SPREAD has the ability to
simplify an array to any size.  This is clearly not right.  As a
simplifying (excuse the pun) assumption, I have supposed that
gfc_simplify_spread should not try to emit an array of larger than
gfc_option.flag_max_array_constructor.

Bootstraps and regtests on FC9/x86_64 - OK for trunk and 4.4?

Paul

2009-06-21  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/40472
	* simplify.c (gfc_simplify_spread): Restrict the result size to
	the limit for an array constructor.

2009-06-21  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/40472
	* gfortran.dg/spread_size_limit.f90: New test.
Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c	(revision 148730)
+++ gcc/fortran/simplify.c	(working copy)
@@ -5099,6 +5099,7 @@
 {
   gfc_expr *result = 0L;
   int i, j, dim, ncopies;
+  mpz_t size;
 
   if ((!gfc_is_constant_expr (source)
        && !is_constant_array_expr (source))
@@ -5114,6 +5115,12 @@
   gfc_extract_int (ncopies_expr, &ncopies);
   ncopies = MAX (ncopies, 0);
 
+  /* Do not allow the array size to exceed the limit for an array
+     constructor.  */
+  gfc_array_size (source, &size);
+  if (mpz_get_si (size)*ncopies > gfc_option.flag_max_array_constructor)
+    return NULL;
+
   if (source->expr_type == EXPR_CONSTANT)
     {
       gcc_assert (dim == 0);
Index: gcc/testsuite/gfortran.dg/spread_size_limit.f90
===================================================================
--- gcc/testsuite/gfortran.dg/spread_size_limit.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/spread_size_limit.f90	(revision 0)
@@ -0,0 +1,15 @@
+! { dg-do compile }
+! { dg-options "-fdump-tree-original" }
+!
+! Test the fix for PR40472 in which simplify_spread had mo limit on the
+! siz that it would try to expand to.
+!
+! Contributed by Philippe Marguinaud <philippe.marguinaud@meteo.fr>
+!
+REAL, DIMENSION(720,360)          :: ZLON_MASK
+ZLON_MASK(:,:)= SPREAD( (/ (JLON , JLON=1,720) /) , DIM=2, NCOPIES=360 )
+print *, zlon_mask(100,100)
+END
+! { dg-final { scan-tree-dump-times "_gfortran_spread" 1 "original" } }
+! { dg-final { cleanup-tree-dump "original" } }
+

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]