[patch, fortran] PR20923 gfortran slow for large array constructors
Jerry DeLisle
jvdelisle@verizon.net
Wed Dec 9 13:54:00 GMT 2009
Ping
On 12/04/2009 09:05 PM, Jerry DeLisle wrote:
> Hi folks,
>
> This patch cuts the compilation time for some programs with large array
> constructors in half. It does this by traversing the constructor and
> only calling the more complicated expand_constructor for expression
> types that are EXPR_ARRAY.
>
> Since gfc_constant_ac can be called recursively, this simplification
> indeed has significant benefit.
>
> I do not see a real need for another test case since all it would
> accomplish is lengthen the time it takes to run the test suite. One
> interesting side effect of this was an ICE in
> gfc_conv_array_constructor_expr, at fortran/trans-expr.c:3832. This
> occurs with the following test case where the limit of 65535 is exceeded.
>
> integer, parameter :: n=65536
> integer, parameter :: i(n)=(/(mod(k,2),k=1,n)/)
> integer, parameter :: m(n)=i(n:1:-1)
> print *, i(1), m(1), i(n), m(n)
> end
>
> This takes several minutes before hitting the error:
>
> integer, parameter :: i(n)=(/(mod(k,2),k=1,n)/)
> 1
> Error: The number of elements in the array constructor at (1) requires
> an increase of the allowed 65535 upper limit. See
> -fmax-array-constructor option
>
> The ICE occurs after the error message.
>
> I tried several ways to avoid the ICE with no avail. I opted to change
> the error to a gfc_fatal_error. If one thinks about it, this really is a
> fatal error.
>
> The test case which shows the improvement is:
>
> program sel
> implicit none
> integer,parameter :: n=1000
> integer :: i,j
> real,dimension(n*n) :: vect
> vect(:) = (/ ((( (i+j+3)),i=1,n),j=1,n) /)
> end
>
> $ time gfc44 pr20923.f90
>
> real 0m18.616s
> user 0m17.173s
> sys 0m0.063s
>
> $ time gfc pr20923.f90
>
> real 0m9.467s
> user 0m8.764s
> sys 0m0.044s
>
> Regression tested on x86-64=linux-gnu. OK for trunk? Is this sufficient
> to close the PR or shall I leave it open?
>
> Regards,
>
> Jerry
>
> 2009-12-04 Jerry DeLisle <jvdelisle@gcc.gnu.org>
>
> PR fortran/20923
> * trans-array.c (gfc_conv_array_initializer): Change gfc_error_now to
> gfc_fatal_error.
> * array.c (count_elements): Whitespace. (extract_element): Whitespace.
> (is_constant_element): Changed name from constant_element.
> (gfc_constant_element): Only use expand_construuctor for expression
> types of EXPR_ARRAY. If expression type is EXPR_CONSTANT, no need to
> call gfc_is_constant_expr.
More information about the Fortran
mailing list