public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/41453] use INTENT(out) for optimization
       [not found] <bug-41453-4@http.gcc.gnu.org/bugzilla/>
@ 2012-06-29 14:26 ` Joost.VandeVondele at mat dot ethz.ch
  2013-03-29  9:04 ` Joost.VandeVondele at mat dot ethz.ch
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2012-06-29 14:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2012-06-29

--- Comment #1 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> 2012-06-29 14:25:46 UTC ---
still happens on  4.8 trunk


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/41453] use INTENT(out) for optimization
       [not found] <bug-41453-4@http.gcc.gnu.org/bugzilla/>
  2012-06-29 14:26 ` [Bug middle-end/41453] use INTENT(out) for optimization Joost.VandeVondele at mat dot ethz.ch
@ 2013-03-29  9:04 ` Joost.VandeVondele at mat dot ethz.ch
  2022-08-25 19:31 ` anlauf at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2013-03-29  9:04 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2012-06-29 00:00:00         |2013-03-29
                 CC|                            |Joost.VandeVondele at mat
                   |                            |dot ethz.ch

--- Comment #2 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> 2013-03-29 09:04:29 UTC ---
and 4.9.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/41453] use INTENT(out) for optimization
       [not found] <bug-41453-4@http.gcc.gnu.org/bugzilla/>
  2012-06-29 14:26 ` [Bug middle-end/41453] use INTENT(out) for optimization Joost.VandeVondele at mat dot ethz.ch
  2013-03-29  9:04 ` Joost.VandeVondele at mat dot ethz.ch
@ 2022-08-25 19:31 ` anlauf at gcc dot gnu.org
  2022-08-25 19:58 ` [Bug fortran/41453] " anlauf at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-08-25 19:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gcc dot gnu.org

--- Comment #8 from anlauf at gcc dot gnu.org ---
Sometimes we now generate a clobber for the wrong variable when a function
result is involved.  An example, derived from PR105012:

! compile with -fdump-tree-original

module m
contains

  SUBROUTINE Y (Z)
    real, intent(out) :: Z
    Z = 1.
  END SUBROUTINE Y

  FUNCTION X ()
    real :: X
    CALL Y (X)      ! direct use of function result, bad clobber
  END FUNCTION X

  FUNCTION F () result(res)
    real :: res
    CALL Y (res)    ! using explicit result variable, good clobber
  END FUNCTION F

end


With current trunk this produces:

__attribute__((fn spec (". ")))
real(kind=4) f ()
{
  real(kind=4) res;

  res = {CLOBBER};
  y (&res);
  return res;
}


__attribute__((fn spec (". ")))
real(kind=4) x ()
{
  real(kind=4) __result_x;

  x = {CLOBBER};
  y (&__result_x);
  return __result_x;
}


__attribute__((fn spec (". w ")))
void y (real(kind=4) & restrict z)
{
  *z = 1.0e+0;
}


For function X (without the result clause) we should have:

  __result_x = {CLOBBER};

instead.  We probably need to have a closer look here:

(gdb) l 9539,9548
9539          else if (add_clobber && expr->ref == NULL)
9540            {
9541              tree clobber;
9542              tree var;
9543              /* FIXME: This fails if var is passed by reference, see PR
9544                 41453.  */
9545              var = expr->symtree->n.sym->backend_decl;
9546              clobber = build_clobber (TREE_TYPE (var));
9547              gfc_add_modify (&se->pre, var, clobber);
9548            }

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/41453] use INTENT(out) for optimization
       [not found] <bug-41453-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2022-08-25 19:31 ` anlauf at gcc dot gnu.org
@ 2022-08-25 19:58 ` anlauf at gcc dot gnu.org
  2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-08-25 19:58 UTC (permalink / raw)
  To: 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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/41453] use INTENT(out) for optimization
       [not found] <bug-41453-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2022-08-25 19:58 ` [Bug fortran/41453] " anlauf at gcc dot gnu.org
@ 2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
  2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-09-25 12:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Mikael Morin <mikael@gcc.gnu.org>:

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

commit r13-2837-g51c9480f9f0a80ef112ba2aed040b0b2ad0fc2a2
Author: Mikael Morin <mikael@gcc.gnu.org>
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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/41453] use INTENT(out) for optimization
       [not found] <bug-41453-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
@ 2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
  2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-09-25 12:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Mikael Morin <mikael@gcc.gnu.org>:

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

commit r13-2838-g467ef2c40dbaf9d1219d9642e90df77dc61f4fae
Author: Mikael Morin <mikael@gcc.gnu.org>
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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/41453] use INTENT(out) for optimization
       [not found] <bug-41453-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
@ 2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
  2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-09-25 12:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Mikael Morin <mikael@gcc.gnu.org>:

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

commit r13-2839-gd5e1935b09fa05093e31d7ce5e21b7e71957c103
Author: Mikael Morin <mikael@gcc.gnu.org>
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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/41453] use INTENT(out) for optimization
       [not found] <bug-41453-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
@ 2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
  2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-09-25 12:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

--- Comment #13 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Mikael Morin <mikael@gcc.gnu.org>:

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

commit r13-2840-g95375ffb3dd59f51e79408dd3b2b620dc1af71b1
Author: Mikael Morin <mikael@gcc.gnu.org>
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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/41453] use INTENT(out) for optimization
       [not found] <bug-41453-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
@ 2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
  2022-09-25 16:42 ` mikael at gcc dot gnu.org
  2022-09-25 20:32 ` tkoenig at gcc dot gnu.org
  10 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-09-25 12:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

--- Comment #14 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Mikael Morin <mikael@gcc.gnu.org>:

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

commit r13-2841-g77bbf69d2981dafc2ef3e59bfbefb645d88bab9d
Author: Mikael Morin <mikael@gcc.gnu.org>
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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/41453] use INTENT(out) for optimization
       [not found] <bug-41453-4@http.gcc.gnu.org/bugzilla/>
                   ` (8 preceding siblings ...)
  2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
@ 2022-09-25 16:42 ` mikael at gcc dot gnu.org
  2022-09-25 20:32 ` tkoenig at gcc dot gnu.org
  10 siblings, 0 replies; 11+ messages in thread
From: mikael at gcc dot gnu.org @ 2022-09-25 16:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

Mikael Morin <mikael at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mikael at gcc dot gnu.org

--- Comment #15 from Mikael Morin <mikael at gcc dot gnu.org> ---
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&x)
> 
> 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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/41453] use INTENT(out) for optimization
       [not found] <bug-41453-4@http.gcc.gnu.org/bugzilla/>
                   ` (9 preceding siblings ...)
  2022-09-25 16:42 ` mikael at gcc dot gnu.org
@ 2022-09-25 20:32 ` tkoenig at gcc dot gnu.org
  10 siblings, 0 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2022-09-25 20:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453

--- Comment #16 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
(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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-09-25 20:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-41453-4@http.gcc.gnu.org/bugzilla/>
2012-06-29 14:26 ` [Bug middle-end/41453] use INTENT(out) for optimization Joost.VandeVondele at mat dot ethz.ch
2013-03-29  9:04 ` Joost.VandeVondele at mat dot ethz.ch
2022-08-25 19:31 ` anlauf at gcc dot gnu.org
2022-08-25 19:58 ` [Bug fortran/41453] " anlauf at gcc dot gnu.org
2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
2022-09-25 12:48 ` cvs-commit at gcc dot gnu.org
2022-09-25 16:42 ` mikael at gcc dot gnu.org
2022-09-25 20:32 ` tkoenig at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).