diff mbox

[fortran] PR46331 Compilation time long with simple function in array constructor

Message ID 4CD76320.8090201@frontier.com
State New
Headers show

Commit Message

Jerry DeLisle Nov. 8, 2010, 2:40 a.m. UTC
Hi all,

The problem here is that we are expanding a large array constructor that 
contains a function that does not reduce (ie. rand(0)). The solution is a small 
adjustment to gfc_is_constant_expr which is used to determine whether or not to 
expand a constructor.  In this case, simply treating an non pure function as not 
constant.

For the test case, without the patch, compile time is approximately 19 seconds. 
With the patch, compilation is about 0.1 seconds.

I don't think a new test case is needed.

Ok for trunk?

Regards,

Jerry

2010-11-07  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/46331
	* expr.c (gfc_is_constant_expr): Treat intrinsic functions that are not
	pure as not constant.

Comments

Mikael Morin Nov. 8, 2010, 12:13 p.m. UTC | #1
On Monday 08 November 2010 03:40:32 Jerry DeLisle wrote:
> Hi all,
> 
> The problem here is that we are expanding a large array constructor that
> contains a function that does not reduce (ie. rand(0)). The solution is a
> small adjustment to gfc_is_constant_expr which is used to determine
> whether or not to expand a constructor.  In this case, simply treating an
> non pure function as not constant.
> 
Hello,

I think it may miss some simplification opportunities. 
For example, transformational functions and inquiry functions are not marked 
pure as far as I know. But some of them have simplification functions. 
As the klass is not saved anywhere in intrinsic.c's add_sym (at least not in 
the CLASS_IMPURE case), maybe would it work to check the presence of a 
simplification function pointer ? Or maybe gfc_intrinsic_sym's flags !pure && 
!inquiry && !transformational would match CLASS_IMPURE ?

Mikael

PS: Is it expected that the and/or/xor procedures are marked as CLASS_IMPURE ?
Tobias Burnus Nov. 8, 2010, 12:52 p.m. UTC | #2
On 11/08/2010 01:13 PM, Mikael Morin wrote:
> PS: Is it expected that the and/or/xor procedures are marked as CLASS_IMPURE

The CLASS_* names come from the Fortran standard (where the term 
"impure" is a F2008 addition). Well, looking at the standard you find:

13.7.10 ALL (MASK [, DIM])
Class. Transformational function.

The procedures "OR" and "XOR" are GNU extensions; the manual does not 
tell which kind of functions they are, but the standard Fortran "IOR" 
and "IEOR", which are the Fortran-standard replacements, are "elemental 
functions". If one changes OR and XOR to elemental, one also needs to 
update the documentation, cf. 
http://gcc.gnu.org/onlinedocs/gfortran/OR.html and 
http://gcc.gnu.org/onlinedocs/gfortran/XOR.html

Tobias
diff mbox

Patch

Index: expr.c
===================================================================
--- expr.c	(revision 166382)
+++ expr.c	(working copy)
@@ -923,7 +923,8 @@  gfc_is_constant_expr (gfc_expr *e)
 	return 1;
 
       /* Call to intrinsic with at least one argument.  */
-      if (e->value.function.isym && e->value.function.actual)
+      if (e->symtree && e->symtree->n.sym->attr.pure
+	  && e->value.function.isym && e->value.function.actual)
 	{
 	  for (arg = e->value.function.actual; arg; arg = arg->next)
 	    if (!gfc_is_constant_expr (arg->expr))