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]

Re: [patch, gcc doc + fortran] Make -Ofast honor -fmax-stack-var-size


Am 04.08.2017 um 14:09 schrieb Thomas Koenig:
Hello world,

the attached patch

This time, really attached, even with ChangeLog!

Regards

	Thomas

2017-08-04  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/68829
        * doc/invoke.texi: Document change in behvaior for -Ofast for
        Fortran.

2017-08-04  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/68829
        PR fortran/81701
        * options.c: Make -Ofast honor -fmax-stack-var-size.
        * invoke.texi: Document change.

2017-08-04  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/68829
        PR fortran/81701
        * gfortran.dg/o_fast_stacksize.90:  New test.


makes -Ofast honor -fmax-stack-var-size, and adjusts
the documentation in the gcc and fortran directories accordingly.
This is done to alleviate PR 68829, to make it possible to run -Ofast
with less stack usage.  I have also taken the opportunity to make
it a bit clearer what -fstack-arrays actually does.

I intend to close PR 68829 once this is committed.

Regression-tested, plus doc changes tested with "make pdf" and
"make dvi".

OK for trunk for

- the fortran subdirectory changes
- the gcc doc changes (if the one above is approved)

?

Regards

     Thomas


Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi	(Revision 250720)
+++ doc/invoke.texi	(Arbeitskopie)
@@ -7278,7 +7278,8 @@
 @option{-O3} optimizations.  It also enables optimizations that are not
 valid for all standard-compliant programs.
 It turns on @option{-ffast-math} and the Fortran-specific
-@option{-fno-protect-parens} and @option{-fstack-arrays}.
+@option{-fstack-arrays}, unless @option{-fmax-stack-var-size} is
+specified, and @option{-fno-protect-parens}.
 
 @item -Og
 @opindex Og
Index: fortran/invoke.texi
===================================================================
--- fortran/invoke.texi	(Revision 250791)
+++ fortran/invoke.texi	(Arbeitskopie)
@@ -1570,13 +1570,13 @@
 
 @item -fstack-arrays
 @opindex @code{fstack-arrays}
-Adding this option will make the Fortran compiler put all local arrays,
-even those of unknown size onto stack memory.  If your program uses very
+Adding this option will make the Fortran compiler put all arrays of
+unknown size and array temporaries onto stack memory.  If your program uses very
 large local arrays it is possible that you will have to extend your runtime
 limits for stack memory on some operating systems. This flag is enabled
-by default at optimization level @option{-Ofast}.
+by default at optimization level @option{-Ofast} unless
+@option{-fmax-stack-var-size} is specified.
 
-
 @item -fpack-derived
 @opindex @code{fpack-derived}
 @cindex structure packing
Index: fortran/options.c
===================================================================
--- fortran/options.c	(Revision 250720)
+++ fortran/options.c	(Arbeitskopie)
@@ -235,7 +235,9 @@
   if (flag_protect_parens == -1)
     flag_protect_parens = !optimize_fast;
 
-  if (flag_stack_arrays == -1)
+  /* -Ofast sets implies -fstack-arrays unless an explicit size is set for
+     stack arrays.  */
+  if (flag_stack_arrays == -1 && flag_max_stack_var_size == -2)
     flag_stack_arrays = optimize_fast;
 
   /* By default, disable (re)allocation during assignment for -std=f95,
@@ -380,6 +382,10 @@
       flag_max_stack_var_size = -1;
     }
 
+  /* Set flag_stack_arrays correctly.  */
+  if (flag_stack_arrays == -1)
+    flag_stack_arrays = 0;
+
   /* Set default.  */
   if (flag_max_stack_var_size == -2)
     flag_max_stack_var_size = 32768;
! { dg-do compile }
! { dg-options "-Ofast -fmax-stack-var-size=100 -fdump-tree-original" }
MODULE foo
CONTAINS
  SUBROUTINE mysum(a)
    INTEGER :: a(:)
    WRITE(6,*) SUM(a)
  END SUBROUTINE
END MODULE foo

USE foo
INTEGER, ALLOCATABLE :: a(:)
INTEGER, PARAMETER :: N=2**26 ! 256Mb array
ALLOCATE(a(N)) ; a=1
CALL mysum(a*a)
END
! { dg-final { scan-tree-dump-times "__builtin_malloc" 2 "original" } }

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