public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/45676]  New: Move array assignments out of loop
@ 2010-09-15  5:44 tkoenig at gcc dot gnu dot org
  2010-09-15  6:40 ` [Bug fortran/45676] " ubizjak at gmail dot com
  2010-09-15  9:47 ` rguenth at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2010-09-15  5:44 UTC (permalink / raw)
  To: gcc-bugs

Consider

program main
  integer :: a(100), b(100), c(100)
  a = 2
  do i=1,10
     b = a
     c = 1/b
     print *,c
  end do
end program main

The statements

b = a
c = 1/b

could be moved out of the loop.  (The second one still has the
problem that we currently don't know that print doesn't read
values).  Currently, this doesn't happen, as a dump shows:

<bb 4>:
  # ivtmp.13_40 = PHI <10(3), ivtmp.13_39(6)>
  MEM[(c_char * {ref-all})&b] = MEM[(c_char * {ref-all})&a];

<bb 5>:
  # ivtmp.24_8 = PHI <ivtmp.24_45(5), 0(4)>
  D.1598_11 = MEM[symbol: b, index: ivtmp.24_8, offset: 0B];
  D.1599_12 = 1 / D.1598_11;
  MEM[symbol: c, index: ivtmp.24_8, offset: 0B] = D.1599_12;
  ivtmp.24_45 = ivtmp.24_8 + 4;
  if (ivtmp.24_45 == 400)
    goto <bb 6>;
  else
    goto <bb 5>;

<bb 6>:
  dt_parm.2.common.filename = &"foo.f90"[1]{lb: 1 sz: 1};
  dt_parm.2.common.line = 7;
  dt_parm.2.common.flags = 128;
  dt_parm.2.common.unit = 6;
  _gfortran_st_write (&dt_parm.2);
  parm.3.dtype = 265;
  parm.3.dim[0].lbound = 1;
  parm.3.dim[0].ubound = 100;
  parm.3.dim[0].stride = 1;
  parm.3.data = &c[0];
  parm.3.offset = -1;
  _gfortran_transfer_array (&dt_parm.2, &parm.3, 4, 0);
  _gfortran_st_write_done (&dt_parm.2);
  ivtmp.13_39 = ivtmp.13_40 - 1;
  if (ivtmp.13_39 == 0)
    goto <bb 7>;
  else
    goto <bb 4>;

<bb 7>:
  return;

Not sure if this is better handled in the front or middle end, though.


-- 
           Summary: Move array assignments out of loop
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tkoenig at gcc dot gnu dot org


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


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

* [Bug fortran/45676] Move array assignments out of loop
  2010-09-15  5:44 [Bug fortran/45676] New: Move array assignments out of loop tkoenig at gcc dot gnu dot org
@ 2010-09-15  6:40 ` ubizjak at gmail dot com
  2010-09-15  9:47 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: ubizjak at gmail dot com @ 2010-09-15  6:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from ubizjak at gmail dot com  2010-09-15 06:40 -------
Related to PR42108 and PR45223.


-- 


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


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

* [Bug fortran/45676] Move array assignments out of loop
  2010-09-15  5:44 [Bug fortran/45676] New: Move array assignments out of loop tkoenig at gcc dot gnu dot org
  2010-09-15  6:40 ` [Bug fortran/45676] " ubizjak at gmail dot com
@ 2010-09-15  9:47 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-09-15  9:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2010-09-15 09:47 -------
We can't hoist invariant control flow.  Also print *,c is surely thought
to be an escape point for c and thus may clobber it.

I'd rate this impossible to do for the middle-end (and generally not worth
the hassle to implement).  Better fix your sources ;)


-- 


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


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

end of thread, other threads:[~2010-09-15  9:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-15  5:44 [Bug fortran/45676] New: Move array assignments out of loop tkoenig at gcc dot gnu dot org
2010-09-15  6:40 ` [Bug fortran/45676] " ubizjak at gmail dot com
2010-09-15  9:47 ` rguenth at gcc dot gnu dot 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).