public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "anlauf at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/110241] New: Redundant temporaries passing empty array constructors
Date: Tue, 13 Jun 2023 19:27:56 +0000	[thread overview]
Message-ID: <bug-110241-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 110241
           Summary: Redundant temporaries passing empty array constructors
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anlauf at gcc dot gnu.org
  Target Milestone: ---

Found while working on pr86277:

program p
  call sub ([real :: 42.])  ! Single temporary
  call sub ([real ::    ])  ! Double temporary
contains
  subroutine sub (arg)
    real, intent(in), optional :: arg(:)
    if (.not. present (arg)) stop 1
  end
end

The dump-tree (at r14-1795-gc1691509e5a887) shows the following for the
first call:

  {
    static real(kind=4) A.4[1] = {4.2e+1};
    struct array01_real(kind=4) parm.5;

    parm.5.span = 4;
    parm.5.dtype = {.elem_len=4, .rank=1, .type=3};
    parm.5.dim[0].lbound = 1;
    parm.5.dim[0].ubound = 1;
    parm.5.dim[0].stride = 1;
    parm.5.data = (void *) &A.4[0];
    parm.5.offset = -1;
    sub (&parm.5);
  }

which is as expected, but for the second call:

  {
    struct array01_real(kind=4) atmp.6;
    real(kind=4) A.7[0];
    struct array01_real(kind=4) atmp.9;
    real(kind=4) A.10[0];

        typedef real(kind=4) [0];
    atmp.6.dtype = {.elem_len=4, .rank=1, .type=3};
    atmp.6.dim[0].stride = 1;
    atmp.6.dim[0].lbound = 0;
    atmp.6.dim[0].ubound = -1;
    atmp.6.span = 4;
    atmp.6.data = (void * restrict) &A.7;
    atmp.6.offset = 0;
        typedef real(kind=4) [0];
    atmp.9.dtype = {.elem_len=4, .rank=1, .type=3};
    atmp.9.dim[0].stride = 1;
    atmp.9.dim[0].lbound = 0;
    atmp.9.dim[0].ubound = -1;
    atmp.9.span = 4;
    atmp.9.data = (void * restrict) &A.10;
    atmp.9.offset = 0;
    {
      integer(kind=8) S.11;

      S.11 = 0;
      while (1)
        {
          if (S.11 >= 0) goto L.2;
          (*(real(kind=4)[0] * restrict) atmp.9.data)[S.11] =
(*(real(kind=4)[0] * restrict) atmp.6.data)[S.11];
          S.11 = S.11 + 1;
        }
      L.2:;
    }
    sub (&atmp.9);
  }

While this is at least correct code (as opposed to before the fix for pr86277),
it could be as simple as for the non-empty constructor.
(There's a patch attached to the other pr demonstrating that this can be
achieved for this code snippet).

             reply	other threads:[~2023-06-13 19:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-13 19:27 anlauf at gcc dot gnu.org [this message]
2023-06-14  7:44 ` [Bug fortran/110241] " mikael at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110241-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).