This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch, fortran] PR64952 - Missing temporary in assignment from elemental function
- From: Dominique d'Humières <dominiq at lps dot ens dot fr>
- To: Paul Richard Thomas <paul dot richard dot thomas at gmail dot com>
- Cc: Mikael Morin <mikael dot morin at sfr dot fr>, "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>, Tobias Burnus <burnus at net-b dot de>
- Date: Wed, 11 Feb 2015 17:38:55 +0100
- Subject: Re: [Patch, fortran] PR64952 - Missing temporary in assignment from elemental function
- Authentication-results: sourceware.org; auth=none
- References: <CAGkQGiLg9VKL2BOGmW0GKC3viE9hDoEJG1FLzFbce-QT12cO4w at mail dot gmail dot com> <CAGkQGiL2g=jxdr5vGtshfqHjpCf+SeQL0OyMYjpeXsmf1UeuEQ at mail dot gmail dot com> <54D79C70 dot 5010002 at sfr dot fr> <CAGkQGiJ5V5MQe4d+b_fXwe-X4tQ2YOn5AVkbTzujubaQGOxxjg at mail dot gmail dot com> <CAGkQGiK2iVXjjRnxg6H5QOkXBmCG2YHP6W+6EP841=HQQmSh3Q at mail dot gmail dot com>
Dear Paul,
The patch works as advertised! I have two remarks:
(1) AFAIU there is no need for a temporary for
PROGRAM Main
INTEGER :: i, index(5) = (/ (i, i = 1,5) /)
REAL :: tmp(5), array(5) = (/ (i+0.0, i = 1,5) /)
tmp = Fred(index,array)
array = tmp
PRINT *, array
CONTAINS
ELEMENTAL FUNCTION Fred (n, x)
REAL :: Fred
INTEGER, INTENT(IN) :: n
REAL, INTENT(IN) :: x
! In general, this would be in an external procedure
Fred = x+SUM(array(:n-1))+SUM(array(n+1:))
END FUNCTION Fred
END PROGRAM Main
However I get
[Book15] f90/bug% gfc elemental_weird_db_2.f90 -Warray-temporaries
elemental_weird_db_2.f90:4:10:
tmp = Fred(index,array)
1
Warning: Creating array temporary at (1) [-Warray-temporaries]
(2) You wrote: « However, this works and has no perceivable effect on Polyhedron timings. ». This is hardly a surprise since the Polyhedron tests don’t use any elemental procedure.
Thanks,
Dominique
> Le 10 févr. 2015 à 23:35, Paul Richard Thomas <paul.richard.thomas@gmail.com> a écrit :
>
> Dear Mikael, dear all,
>
> Thank you for the previous review. I believe that the attached
> responds to all of your comments and correctly compiles the three
> testcases that you provided. Two of these have been included in the
> original testcase and the third appears separately.
>
> Bootstrapped and reg
> tested on FC21/x86_64 - OK for trunk?
>
> Cheers
>
> Paul
>
> 2015-02-10 Paul Thomas <pault@gcc.gnu.org>
>
> PR fortran/64952
> * gfortran.h : Add 'array_outer_dependency' to symbol_attr.
> * trans.h : Add 'array_outer_dependency' to gfc_ss_info.
> * module.c : Add AB_ARRAY_OUTER_DEPENDENCY to ab_attribute.
> Add same to attr_bits.
> (mio_symbol_attribute): Handle 'array_outer_dependency' attr
> in module read and write.
> * resolve.c (resolve_function): If an elemental function is
> referenced that is marked as having an external array reference
> and the current namespace is that of an elemental function,
> mark the containing function likewise.
> (resolve_variable): Mark elemental function symbol
> as 'array_outer_dependency' if it has an array reference from
> outside its own namespace.
> * trans-array.c (gfc_conv_resolve_dependencies): If any ss is
> marked as 'array_outer_dependency' generate a temporary.
> (gfc_walk_function_expr): If the function is marked as
> 'array_outer_dependency', likewise mark the head gfc_ss.
>
> 2015-02-10 Paul Thomas <pault@gcc.gnu.org>
>
> PR fortran/64952
> * gfortran.dg/elemental_dependency_4.f90: New test
> * gfortran.dg/elemental_dependency_5.f90: New test