[Bug fortran/41453] use INTENT(out) for optimization

2022-09-25 Thread tkoenig at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

--- Comment #16 from Thomas Koenig  ---
(In reply to Mikael Morin from comment #15)
> Status update:

A lot of progress :-)

> (In reply to Thomas Koenig from comment #5)
> > Still missing: To clobber
> > 
> > - variables passed by reference to the caller
> > - saved variables
> > - associated variables (there are passed as pointers to
> >   the associate blocsk)
> These have been done now.
> 
> Still missing: pointer or allocatable dummy.
> Seems doable, probably a low hanging fruit.

For an allocatable dummy, we have to deallocate on intent(out)
anyway, and we do this on the caller's side, so we should not clobber. 
For pointers, it could be an advantage.

> > - intent(out) variables on entry to the procedure.
> This remains to do.

Again, sounds doable


> Another case that could be handled is the case of arrays:
> when the full array is passed as argument, and it is contiguous, and maybe
> some other condition, we can clobber its decl.  The hard part is the "maybe
> some other condition".

Not sure what that other condition could be.  If we have a full array ref, as
per gfc_full_array_ref_p, and we pass this to an intent(out) argument,
then that should be enough.

> Not sure it's worth keeping this PR open.
> Surely the initial test works as expected, and has been working for a long
> time.

There are still a few open points in relation to this.  I would be in
favor of keeping this open (to not lose the discussion) until we have
them all fixed, or decide not to fix some or all of them.

[Bug fortran/41453] use INTENT(out) for optimization

2022-09-25 Thread mikael at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

Mikael Morin  changed:

   What|Removed |Added

 CC||mikael at gcc dot gnu.org

--- Comment #15 from Mikael Morin  ---
Status update:

(In reply to Thomas Koenig from comment #5)
> Still missing: To clobber
> 
> - variables passed by reference to the caller
> - saved variables
> - associated variables (there are passed as pointers to
>   the associate blocsk)
These have been done now.

Still missing: pointer or allocatable dummy.
Seems doable, probably a low hanging fruit.

> - intent(out) variables on entry to the procedure.
This remains to do.

(In reply to Thomas Koenig from comment #7)
> Also still to do: Do some more precise clobbering for
> the case of PR88364, i.e. for
> 
> call foo(a)
> 
> clobber a%x, which is currently not done.

This is impossible for now on the caller side because of lack of middle-end
support: only full variable declarations can be clobbered, or pointer targets.
There was a patch to handle the case above, but it was dropped for that reason.
See: https://gcc.gnu.org/pipermail/fortran/2022-September/058181.html
Maybe part of that patch can be resurrected, but restricted to the case of
allocatable or pointer components.

Another case that could be handled is the case of arrays:
when the full array is passed as argument, and it is contiguous, and maybe some
other condition, we can clobber its decl.  The hard part is the "maybe some
other condition".

Not sure it's worth keeping this PR open.
Surely the initial test works as expected, and has been working for a long
time.

[Bug fortran/41453] use INTENT(out) for optimization

2022-09-25 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

--- Comment #13 from CVS Commits  ---
The master branch has been updated by Mikael Morin :

https://gcc.gnu.org/g:95375ffb3dd59f51e79408dd3b2b620dc1af71b1

commit r13-2840-g95375ffb3dd59f51e79408dd3b2b620dc1af71b1
Author: Mikael Morin 
Date:   Thu Sep 1 11:27:36 2022 +0200

fortran: Support clobbering of allocatables and pointers [PR41453]

This adds support for clobbering of allocatable and pointer scalar
variables passed as actual argument to a subroutine when the associated
dummy has the INTENT(OUT) attribute.
Support was explicitly disabled (since the beginning for pointers, since
r11-7315-g2df374b337a5f6cf5528e91718e4e12e4006b7ae for allocatables),
but the clobber generation code seems to support it well, as
demonstrated by the newly added testcase.

PR fortran/41453
PR fortran/99169

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_conv_procedure_call): Remove conditions
on ALLOCATABLE and POINTER attributes guarding clobber
generation.

gcc/testsuite/ChangeLog:

* gfortran.dg/intent_optimize_9.f90: New test.

[Bug fortran/41453] use INTENT(out) for optimization

2022-09-25 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

--- Comment #14 from CVS Commits  ---
The master branch has been updated by Mikael Morin :

https://gcc.gnu.org/g:77bbf69d2981dafc2ef3e59bfbefb645d88bab9d

commit r13-2841-g77bbf69d2981dafc2ef3e59bfbefb645d88bab9d
Author: Mikael Morin 
Date:   Thu Sep 1 12:35:07 2022 +0200

fortran: Support clobbering of derived types [PR41453]

This adds support for clobbering of non-polymorphic derived type
variables, when they are passed as actual argument whose associated
dummy has the INTENT(OUT) attribute.

We avoid to play with non-constant type sizes or class descriptors by
requiring that the types are derived (not class) and strictly matching,
and by excluding parameterized derived types.

Types that are used in the callee are also excluded: they are types with
allocatable components (the components will be deallocated), and
finalizable types or types with finalizable components (they will be
passed to finalization routines).

PR fortran/41453

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_conv_procedure_call): Allow strictly
matching derived types.

gcc/testsuite/ChangeLog:

* gfortran.dg/intent_optimize_10.f90: New test.

[Bug fortran/41453] use INTENT(out) for optimization

2022-09-25 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

--- Comment #12 from CVS Commits  ---
The master branch has been updated by Mikael Morin :

https://gcc.gnu.org/g:d5e1935b09fa05093e31d7ce5e21b7e71957c103

commit r13-2839-gd5e1935b09fa05093e31d7ce5e21b7e71957c103
Author: Mikael Morin 
Date:   Wed Aug 31 11:58:08 2022 +0200

fortran: Support clobbering of ASSOCIATE variables [PR41453]

This is in spirit a revert of:
r9-3051-gc109362313623d83fe0a5194bceaf994cf0c6ce0

That commit added a condition to avoid generating ICE with clobbers
of ASSOCIATE variables.
The test added at that point continues to pass if we remove that
condition now.

PR fortran/41453
PR fortran/87401

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_conv_procedure_call): Remove condition
disabling clobber generation for ASSOCIATE variables.

gcc/testsuite/ChangeLog:

* gfortran.dg/intent_optimize_8.f90: New test.

[Bug fortran/41453] use INTENT(out) for optimization

2022-09-25 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

--- Comment #10 from CVS Commits  ---
The master branch has been updated by Mikael Morin :

https://gcc.gnu.org/g:51c9480f9f0a80ef112ba2aed040b0b2ad0fc2a2

commit r13-2837-g51c9480f9f0a80ef112ba2aed040b0b2ad0fc2a2
Author: Mikael Morin 
Date:   Mon Aug 29 13:27:02 2022 +0200

fortran: Support clobbering of reference variables [PR41453]

This adds support for clobbering of variables passed by reference,
when the reference is forwarded to a subroutine as actual argument
whose associated dummy has the INTENT(OUT) attribute.
This was explicitly disabled by a condition added with
r9-3032-gee7fb0588c6361b4d77337ab0f7527be64fcdde2 and removing that
condition seems to work, as demonstrated by the new testcase.

PR fortran/41453
PR fortran/87395

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_conv_procedure_call): Remove condition
disabling clobber generation for dummy variables.  Remove
obsolete comment.

gcc/testsuite/ChangeLog:

* gfortran.dg/intent_optimize_6.f90: New test.

[Bug fortran/41453] use INTENT(out) for optimization

2022-09-25 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

--- Comment #11 from CVS Commits  ---
The master branch has been updated by Mikael Morin :

https://gcc.gnu.org/g:467ef2c40dbaf9d1219d9642e90df77dc61f4fae

commit r13-2838-g467ef2c40dbaf9d1219d9642e90df77dc61f4fae
Author: Mikael Morin 
Date:   Wed Aug 31 11:54:47 2022 +0200

fortran: Support clobbering of SAVE variables [PR41453]

This removes a condition added in:
r9-3032-gee7fb0588c6361b4d77337ab0f7527be64fcdde2.

That commit added a condition to avoid generating ICE with clobbers
of variables with the SAVE attribute.
The test added at that point continues to pass if we remove that
condition now.

PR fortran/41453
PR fortran/87395

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_conv_procedure_call): Remove condition
on SAVE attribute guarding clobber generation.

gcc/testsuite/ChangeLog:

* gfortran.dg/intent_optimize_7.f90: New test.

[Bug fortran/41453] use INTENT(out) for optimization

2022-08-25 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

anlauf at gcc dot gnu.org changed:

   What|Removed |Added

  Component|middle-end  |fortran

--- Comment #9 from anlauf at gcc dot gnu.org ---
Changing component to fortran.