public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/98913] New: Create-temporary difference coarray/noncoarray – invalid code due to missing temporary
Date: Mon, 01 Feb 2021 11:20:56 +0000	[thread overview]
Message-ID: <bug-98913-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 98913
           Summary: Create-temporary difference coarray/noncoarray –
                    invalid code due to missing temporary
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: jdelia at intec dot unl.edu.ar, tkoenig at gcc dot gnu.org
  Target Milestone: ---

Reported at https://gcc.gnu.org/pipermail/fortran/2021-January/055657.html

The testcase there uses
  real    (kind=idp), allocatable :: AA (:,:)[:]
  real    (kind=idp), allocatable :: BB (:,:)

For identical assignment, a temporary is generated for the
(this_image()-access) coarray variable but not for the local variable:

   37 |     AA (k1:nn,j) = AA (k1:nn,j) - UU (k1:nn) * AA (k,j)
      |                   1
Warning: Creating array temporary at (1) [-Warray-temporaries]


On the compiler side, I think the behaviour differs due to:
gfc_conv_resolve_dependencies():

          if (flag_realloc_lhs
              && dest_expr != ss_expr
              && gfc_is_reallocatable_lhs (dest_expr)
              && ss_expr->rank)
            nDepend = gfc_check_dependency (dest_expr, ss_expr, true);

 * * *

Looking at

  do  j = 1, nn
    AA (k1:nn,j) = AA (k1:nn,j) - UU (k1:nn) * AA (k,j)
  end do

I think a temporary is needed for "A(k,j)", i.e.
  do  j = 1, nn
    tmp = AA (k,j)
    do ii = k1, nn
      AA (ii,j) = AA (ii,j) - UU (ii) * tmp
    end do
  end do

without that temporary, k might be any value within k1:nn!

In this example, k = 1; k1 = 2 – thus, there is no dependency.

 * * *

For (b), I see (for "BB(k,j)"):

D.3991 = (*(real(kind=8)[0:] * restrict) bb.data)[(bb.offset +
(integer(kind=8)) j * bb.dim[1].stride) + (integer(kind=8)) k];

...
            D.3986 = (real(kind=8)[0:] * restrict) bb.data;
            D.3978 = (real(kind=8)[0:] * restrict) bb.data;

              while (1)
...
                  (*D.3986)[(S.0 + D.3994) + D.3997] = (*D.3978)[S.0 + D.3996]
- (*D.3982)[(S.0 + D.3993) + D.3983] * D.3991;

Namely:
  b(k,j) is accessed.

I am quite certain that "k = 1; k1 = k + 1" is not used for this analysis →
wrong code.

If it is, it should also apply to coarrays.

             reply	other threads:[~2021-02-01 11:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-01 11:20 burnus at gcc dot gnu.org [this message]
2021-02-01 11:51 ` [Bug fortran/98913] " burnus at gcc dot gnu.org
2021-02-01 12:30 ` jdelia@santafe-conicet.gov.ar
2021-02-03  9:34 ` cvs-commit at gcc dot gnu.org
2021-02-03  9:36 ` [Bug fortran/98913] Create-temporary difference coarray/noncoarray – unnecessarily created temporary burnus 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-98913-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).