public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/98913] New: Create-temporary difference coarray/noncoarray – invalid code due to missing temporary
@ 2021-02-01 11:20 burnus at gcc dot gnu.org
  2021-02-01 11:51 ` [Bug fortran/98913] " burnus at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-02-01 11:20 UTC (permalink / raw)
  To: gcc-bugs

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.

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

* [Bug fortran/98913] Create-temporary difference coarray/noncoarray – invalid code due to missing temporary
  2021-02-01 11:20 [Bug fortran/98913] New: Create-temporary difference coarray/noncoarray – invalid code due to missing temporary burnus at gcc dot gnu.org
@ 2021-02-01 11:51 ` burnus at gcc dot gnu.org
  2021-02-01 12:30 ` jdelia@santafe-conicet.gov.ar
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-02-01 11:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(In reply to Tobias Burnus from comment #0)
> D.3991 = (*(real(kind=8)[0:] * restrict) bb.data)[(bb.offset +
> (integer(kind=8)) j * bb.dim[1].stride) + (integer(kind=8)) k];

Missed that this one is a FP number not a pointer – hence, the issue I have
does not exist.

(Probably works – I have not verified whether that is always the case and I
hope it does.)

 * * *

The difference between coarray and not occurs elsewhere: dependency.c's
gfc_dep_resolver has:

        case REF_ARRAY:
          /* For now, treat all coarrays as dangerous.  */
          if (lref->u.ar.codimen || rref->u.ar.codimen)
            return 1;

Alternative would be to check for
  flag_coarray == GFC_FCOARRAY_SINGLE
|| ref->u.ar.dimen_type[ref->u.ar.dimen] == DIMEN_THIS_IMAGE)

or something like that.

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

* [Bug fortran/98913] Create-temporary difference coarray/noncoarray – invalid code due to missing temporary
  2021-02-01 11:20 [Bug fortran/98913] New: Create-temporary difference coarray/noncoarray – invalid code due to missing temporary burnus at gcc dot gnu.org
  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
  3 siblings, 0 replies; 5+ messages in thread
From: jdelia@santafe-conicet.gov.ar @ 2021-02-01 12:30 UTC (permalink / raw)
  To: gcc-bugs

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

Jorge D'Elia <jdelia@santafe-conicet.gov.ar> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jdelia@santafe-conicet.gov.
                   |                            |ar

--- Comment #2 from Jorge D'Elia <jdelia@santafe-conicet.gov.ar> ---
Thanks Tobias for filling out this report. I do not follow all the internal
details of the compiler, although, just in case, I comment that the discrepancy
between array vs coarray was initially detected with the -fcoarray=lib flag and
using opencoarrays.

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

* [Bug fortran/98913] Create-temporary difference coarray/noncoarray – invalid code due to missing temporary
  2021-02-01 11:20 [Bug fortran/98913] New: Create-temporary difference coarray/noncoarray – invalid code due to missing temporary burnus at gcc dot gnu.org
  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
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-02-03  9:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tobias Burnus <burnus@gcc.gnu.org>:

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

commit r11-7054-ge3f9f80bfa9e58a90dfe75631921c78660342daf
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Wed Feb 3 10:34:18 2021 +0100

    Fortran: Fix Array dependency with local coarrays [PR98913]

    gcc/fortran/ChangeLog:

            PR fortran/98913
            * dependency.c (gfc_dep_resolver): Treat local access
            to coarrays like any array access in dependency analysis.

    gcc/testsuite/ChangeLog:

            PR fortran/98913
            * gfortran.dg/coarray/array_temporary.f90: New test.

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

* [Bug fortran/98913] Create-temporary difference coarray/noncoarray – unnecessarily created temporary
  2021-02-01 11:20 [Bug fortran/98913] New: Create-temporary difference coarray/noncoarray – invalid code due to missing temporary burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-02-03  9:34 ` cvs-commit at gcc dot gnu.org
@ 2021-02-03  9:36 ` burnus at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-02-03  9:36 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|wrong-code                  |missed-optimization
         Resolution|---                         |FIXED
            Summary|Create-temporary difference |Create-temporary difference
                   |coarray/noncoarray –        |coarray/noncoarray –
                   |invalid code due to missing |unnecessarily created
                   |temporary                   |temporary
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> ---
FIXED on mainline (GCC 11).

Thanks for the report!

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

end of thread, other threads:[~2021-02-03  9:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-01 11:20 [Bug fortran/98913] New: Create-temporary difference coarray/noncoarray – invalid code due to missing temporary burnus at gcc dot gnu.org
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

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).