public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/54932] New: Invalid loop code generated by Fortran FE for loops with bounds in HIGH(type)
@ 2012-10-15 11:45 hubicka at gcc dot gnu.org
  2012-10-15 11:49 ` [Bug fortran/54932] " rguenth at gcc dot gnu.org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: hubicka at gcc dot gnu.org @ 2012-10-15 11:45 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 54932
           Summary: Invalid loop code generated by Fortran FE for loops
                    with bounds in HIGH(type)
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: hubicka@gcc.gnu.org


The following fortran testcase (derrived from do-1.f90):
! { dg-do run }
! Program to check corner cases for DO statements.
program do_1
  implicit none
  integer i, j

  ! limit=HUGE(i), step 1
  j = 0
  do i = HUGE(i) - 10, HUGE(i), 1
    j = j + 1
  end do
  if (j .ne. 11) call abort

end program

gets invalid estimate on number of iterations of the loop

Statement i_9 = i_8 + 1;
 is executed at most 9 (bounded by 9) + 1 times in loop 1.
Loop 1 iterates at most 9 times.

(should be 10) this is because:
  <bb 3>:
  # i_8 = PHI <2147483637(2), i_9(3)>
  # j_6 = PHI <0(2), j_7(3)>
  # DEBUG j => j_6
  # DEBUG i => i_8
  j_7 = j_6 + 1;
  # DEBUG j => j_7
  i_9 = i_8 + 1;
  # DEBUG i => i_9
  if (i_8 == 2147483647)
    goto <bb 4>;
  else
    goto <bb 3>;

the loop is produce din a way that i_9 overflows in the last iteration. It is
unused by according to discussion with Richard on IRC the program is not valid.
This is already wrong in the output from the fortran FE:
<bb 3>:
  j = j + 1;
  test (&i);
  i.1 = i;
  D.1852 = i.1 == 2147483647;
  i.1 = i;
  i.2 = i.1 + 1;
  i = i.2;
  if (D.1852 != 0)
    goto <bb 4>;
  else
    goto <bb 3>;

the increment really should happen in the latch block.
Or is the testcase bogus?

Honza


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

end of thread, other threads:[~2013-03-20 11:39 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-15 11:45 [Bug fortran/54932] New: Invalid loop code generated by Fortran FE for loops with bounds in HIGH(type) hubicka at gcc dot gnu.org
2012-10-15 11:49 ` [Bug fortran/54932] " rguenth at gcc dot gnu.org
2012-10-16 19:26 ` burnus at gcc dot gnu.org
2012-10-17  9:23 ` rguenth at gcc dot gnu.org
2012-10-17 10:42 ` burnus at gcc dot gnu.org
2012-10-17 17:03 ` burnus at gcc dot gnu.org
2012-10-17 17:58 ` kargl at gcc dot gnu.org
2012-10-17 18:51 ` burnus at gcc dot gnu.org
2012-10-17 19:21 ` sgk at troutmask dot apl.washington.edu
2012-10-23 13:55 ` hubicka at ucw dot cz
2012-11-18 14:34 ` dominiq at lps dot ens.fr
2012-11-18 16:24 ` tkoenig at gcc dot gnu.org
2013-02-01 13:59 ` dominiq at lps dot ens.fr
2013-02-04  0:17 ` hubicka at ucw dot cz
2013-02-12 18:22 ` dominiq at lps dot ens.fr
2013-03-18 10:19 ` ro at gcc dot gnu.org
2013-03-18 11:05 ` hubicka at ucw dot cz
2013-03-20 11:39 ` 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).