public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/44442]  New: Useless temporary with RESHAPE
@ 2010-06-07 11:36 dominiq at lps dot ens dot fr
  2010-06-07 13:50 ` [Bug fortran/44442] " dominiq at lps dot ens dot fr
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: dominiq at lps dot ens dot fr @ 2010-06-07 11:36 UTC (permalink / raw)
  To: gcc-bugs

While playing with -Warray-temporaries, I noticed that the warning is emitted
twice for RESHAPE as illustrated by the following example:

[macbook] f90/bug% cat pr36928_red.f90
! { dg-do compile }
! { dg-options "-Warray-temporaries" }
! PR 36928 - optimize array interleaving array temporaries
program main
  integer :: i, m, n
  real, dimension(4,5) :: b
  real, dimension(5,4) :: c
  b = reshape([(i, i=1,20)],[4,5])
  m = 5
  n = 4
  c = reshape(b, [m,n])
end program main
[macbook] f90/bug% gfc -Warray-temporaries pr36928_red.f90
pr36928_red.f90:11.17:

  c = reshape(b, [m,n])
                 1
Warning: Creating array temporary at (1)
pr36928_red.f90:11.17:

  c = reshape(b, [m,n])
                 1
Warning: Creating array temporary at (1)

(see the polyhedron test capacita.f90 for "real life" code). If I read
correctly the dump

...
      atmp.3.dtype = 265;
      atmp.3.dim[0].stride = 1;
      atmp.3.dim[0].lbound = 0;
      atmp.3.dim[0].ubound = 1;
      atmp.3.data = (void * restrict) &A.4;
      atmp.3.offset = 0;
      (*(integer(kind=4)[2] * restrict) atmp.3.data)[0] = m;
      (*(integer(kind=4)[2] * restrict) atmp.3.data)[1] = n;
      atmp.6.dtype = 521;
      atmp.6.dim[0].stride = 1;
      atmp.6.dim[0].lbound = 0;
      atmp.6.dim[0].ubound = 1;
      atmp.6.data = (void * restrict) &A.7;
      atmp.6.offset = 0;
      {
        integer(kind=8) S.8;

        S.8 = 0;
        while (1)
          {
            if (S.8 > 1) goto L.1;
            (*(integer(kind=8)[2] * restrict) atmp.6.data)[S.8] =
(integer(kind=8)) (*(integer(kind=4)[2] * restrict) atmp.3.data)[S.8];
            S.8 = S.8 + 1;
          }
        L.1:;
      }
      _gfortran_reshape_r4 (&parm.1, &parm.2, &atmp.6, 0B, 0B);
    }
  }
}

there are two temporaries atmp.3 and atmp.6, and I don't see any reason why the
second one should be needed (all the arguments are INTENT(IN), isn't it?).


-- 
           Summary: Useless temporary with RESHAPE
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dominiq at lps dot ens dot fr


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


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

* [Bug fortran/44442] Useless temporary with RESHAPE
  2010-06-07 11:36 [Bug fortran/44442] New: Useless temporary with RESHAPE dominiq at lps dot ens dot fr
@ 2010-06-07 13:50 ` dominiq at lps dot ens dot fr
  2010-06-07 15:59 ` mikael at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: dominiq at lps dot ens dot fr @ 2010-06-07 13:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from dominiq at lps dot ens dot fr  2010-06-07 13:49 -------
Useless temporaries are also emitted for PAD and ORDER optional arguments:

program main
  integer :: i, k, l, m, n
  real :: e1, e2
  real, dimension(4,5) :: b
  real, dimension(5,4) :: c
  b = reshape([(i, i=1,20)],[4,5])
  m = 5
  n = 4
  c = reshape(b, [m,n])
  e1 = 1.0
  e2 = 2.0
  k = 2
  l = 1
  c = reshape(b, [m,n], [e1,e2], [k,l])
end program main

pr36928_red.f90:17.24:

  c = reshape(b, [m,n], [e1,e2], [k,l])
                        1
Warning: Creating array temporary at (1)
pr36928_red.f90:17.24:

  c = reshape(b, [m,n], [e1,e2], [k,l])
                        1
Warning: Creating array temporary at (1)
pr36928_red.f90:17.33:

  c = reshape(b, [m,n], [e1,e2], [k,l])
                                 1
Warning: Creating array temporary at (1)
pr36928_red.f90:17.33:

  c = reshape(b, [m,n], [e1,e2], [k,l])
                                 1
Warning: Creating array temporary at (1)


-- 


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


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

* [Bug fortran/44442] Useless temporary with RESHAPE
  2010-06-07 11:36 [Bug fortran/44442] New: Useless temporary with RESHAPE dominiq at lps dot ens dot fr
  2010-06-07 13:50 ` [Bug fortran/44442] " dominiq at lps dot ens dot fr
@ 2010-06-07 15:59 ` mikael at gcc dot gnu dot org
  2010-06-09 19:45 ` dfranke at gcc dot gnu dot org
  2010-06-09 20:58 ` dominiq at lps dot ens dot fr
  3 siblings, 0 replies; 5+ messages in thread
From: mikael at gcc dot gnu dot org @ 2010-06-07 15:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from mikael at gcc dot gnu dot org  2010-06-07 15:59 -------
(In reply to comment #1)
> Useless temporaries are also emitted for PAD and ORDER optional arguments:
> 

This is a known limitation of array constructors handling by gfortran.
For passing to the library function, a temporary will be created anyway.
The array constructor will fill an intermediary temporary on top of the
previous one.


-- 

mikael at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-06-07 15:59:13
               date|                            |


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


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

* [Bug fortran/44442] Useless temporary with RESHAPE
  2010-06-07 11:36 [Bug fortran/44442] New: Useless temporary with RESHAPE dominiq at lps dot ens dot fr
  2010-06-07 13:50 ` [Bug fortran/44442] " dominiq at lps dot ens dot fr
  2010-06-07 15:59 ` mikael at gcc dot gnu dot org
@ 2010-06-09 19:45 ` dfranke at gcc dot gnu dot org
  2010-06-09 20:58 ` dominiq at lps dot ens dot fr
  3 siblings, 0 replies; 5+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2010-06-09 19:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from dfranke at gcc dot gnu dot org  2010-06-09 19:45 -------
I believe this is a dupe of PR33341.


-- 


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


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

* [Bug fortran/44442] Useless temporary with RESHAPE
  2010-06-07 11:36 [Bug fortran/44442] New: Useless temporary with RESHAPE dominiq at lps dot ens dot fr
                   ` (2 preceding siblings ...)
  2010-06-09 19:45 ` dfranke at gcc dot gnu dot org
@ 2010-06-09 20:58 ` dominiq at lps dot ens dot fr
  3 siblings, 0 replies; 5+ messages in thread
From: dominiq at lps dot ens dot fr @ 2010-06-09 20:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from dominiq at lps dot ens dot fr  2010-06-09 20:57 -------
(In reply to comment #2)
> This is a known limitation of array constructors handling by gfortran.

I was about to ask if this pr is a duplicate. From comment #3, it is; so I am
closing it as such.
For the record the optimized dump (with 4.6) reads:

...

  atmp.6.dtype = 521;
  atmp.6.dim[0].stride = 1;
  atmp.6.dim[0].lbound = 0;
  atmp.6.dim[0].ubound = 1;
  atmp.6.data = &A.7;
  atmp.6.offset = 0;
  A.7[0] = 5;
  A.7[1] = 4;
  _gfortran_reshape_r4 (&parm.1, &parm.2, &atmp.6, 0B, 0B);
...

So one temporary is removed with optimization.


*** This bug has been marked as a duplicate of 33341 ***


-- 

dominiq at lps dot ens dot fr changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


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


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

end of thread, other threads:[~2010-06-09 20:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-07 11:36 [Bug fortran/44442] New: Useless temporary with RESHAPE dominiq at lps dot ens dot fr
2010-06-07 13:50 ` [Bug fortran/44442] " dominiq at lps dot ens dot fr
2010-06-07 15:59 ` mikael at gcc dot gnu dot org
2010-06-09 19:45 ` dfranke at gcc dot gnu dot org
2010-06-09 20:58 ` dominiq at lps dot ens dot fr

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