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

           Summary: Recursion not converted into a loop
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: bur...@gcc.gnu.org


For the following Fortran program, the recursion could be replaced by a loop.
That's what happening for the related C program, but for the Fortran program
the recursion remains. (Tried with -O3.)

(I guess the I/O statement (_gfortran_st_write* and _gfortran_transfer_*_write)
confuse the ME, but I do not see why that should prevent the loop
transformation. Hints how to modify the FE to help the ME are welcome, too.)

! Fortran version
call x (1)
contains
  recursive subroutine x (i)
    use iso_fortran_env
    integer, value :: i
    if (mod (i, 1000000) == 0) write (error_unit,'(a,i0)')'i=', i
    call x (i+1)
  end subroutine x
end


/* C version */
#include <stdio.h>
static void
x (int i) {
  if (!(i % 1000000))
    fprintf(stderr, "i=%d\n", i);
  x(i + 1);
}
int main () {
  x (1);
}

Reply via email to