public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/48363] New: Recursion not converted into a loop
@ 2011-03-30 12:40 burnus at gcc dot gnu.org
2011-03-30 15:06 ` [Bug fortran/48363] " rguenth at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-03-30 12:40 UTC (permalink / raw)
To: gcc-bugs
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: unassigned@gcc.gnu.org
ReportedBy: burnus@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);
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/48363] Recursion not converted into a loop
2011-03-30 12:40 [Bug fortran/48363] New: Recursion not converted into a loop burnus at gcc dot gnu.org
@ 2011-03-30 15:06 ` rguenth at gcc dot gnu.org
2011-03-30 15:51 ` burnus at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-03-30 15:06 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48363
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2011.03.30 15:01:37
Ever Confirmed|0 |1
--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-03-30 15:01:37 UTC ---
The parameter has its address taken in
_gfortran_transfer_integer_write (&dt_parm.0, &i, 4);
thus we can't tail-recurse here (well, at least not as trivial as if
that wasn't the case).
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/48363] Recursion not converted into a loop
2011-03-30 12:40 [Bug fortran/48363] New: Recursion not converted into a loop burnus at gcc dot gnu.org
2011-03-30 15:06 ` [Bug fortran/48363] " rguenth at gcc dot gnu.org
@ 2011-03-30 15:51 ` burnus at gcc dot gnu.org
2011-03-30 15:58 ` rguenth at gcc dot gnu.org
2021-08-10 23:18 ` [Bug tree-optimization/48363] " pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-03-30 15:51 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48363
--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-03-30 15:38:13 UTC ---
(In reply to comment #1)
> The parameter has its address taken in
> _gfortran_transfer_integer_write (&dt_parm.0, &i, 4);
True, but the value is not modified - which the ME should know as the "fn spec"
is ".wR"
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/48363] Recursion not converted into a loop
2011-03-30 12:40 [Bug fortran/48363] New: Recursion not converted into a loop burnus at gcc dot gnu.org
2011-03-30 15:06 ` [Bug fortran/48363] " rguenth at gcc dot gnu.org
2011-03-30 15:51 ` burnus at gcc dot gnu.org
@ 2011-03-30 15:58 ` rguenth at gcc dot gnu.org
2021-08-10 23:18 ` [Bug tree-optimization/48363] " pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-03-30 15:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48363
--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-03-30 15:54:28 UTC ---
(In reply to comment #2)
> (In reply to comment #1)
> > The parameter has its address taken in
> > _gfortran_transfer_integer_write (&dt_parm.0, &i, 4);
>
> True, but the value is not modified - which the ME should know as the "fn spec"
> is ".wR"
The parameter is not in SSA form so tail-recursion would have to insert
a store and reload the value at appropriate places. It doesn't support that.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/48363] Recursion not converted into a loop
2011-03-30 12:40 [Bug fortran/48363] New: Recursion not converted into a loop burnus at gcc dot gnu.org
` (2 preceding siblings ...)
2011-03-30 15:58 ` rguenth at gcc dot gnu.org
@ 2021-08-10 23:18 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-10 23:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48363
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|middle-end |tree-optimization
Last reconfirmed|2011-03-30 15:01:37 |2021-8-10
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-08-10 23:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-30 12:40 [Bug fortran/48363] New: Recursion not converted into a loop burnus at gcc dot gnu.org
2011-03-30 15:06 ` [Bug fortran/48363] " rguenth at gcc dot gnu.org
2011-03-30 15:51 ` burnus at gcc dot gnu.org
2011-03-30 15:58 ` rguenth at gcc dot gnu.org
2021-08-10 23:18 ` [Bug tree-optimization/48363] " pinskia 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).