[Bug fortran/31593] Invariant DO loop variables and subroutines

tkoenig at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Wed Aug 12 20:36:00 GMT 2009



------- Comment #8 from tkoenig at gcc dot gnu dot org  2009-08-12 20:36 -------
(In reply to comment #7)

> An interesting approach.  As long as you don't print array slices in the 
> loops this should work around the escaping pointer problem.  It comes at 
> the risk of creating excessive copies.

Apparently, the optimizers are smart enough for that at least for
simple cases.

The loop in the following subroutine gets translated to

subroutine foo
  do i=1,10
    call bar((i))
  end do
end subroutine foo

       leal    -12(%ebp), %esi
        .p2align 4,,7
L2:
        movl    %ebx, -12(%ebp)
        addl    $1, %ebx
        movl    %esi, (%esp)
        call    bar_
        cmpl    $11, %ebx
        jne     L2

which is pretty good.

> Actually, perhaps the right way of achieving this is not to add 
> OP_PARENTHESES in the frontend, but to do a copy when creating the call.

This would likely have the same result, the subprogram

subroutine foo
  do i=1,10
    j = i
    call bar(j)
  end do
end subroutine foo

gets the same code as the one above.

For comparision, the unadorned

$ cat a.f90
subroutine foo
  do i=1,10
    call bar(i)
  end do
end subroutine foo

gets

        movl    $1, -12(%ebp)
.L2:
        movl    %ebx, (%esp)
        call    bar_
        movl    -12(%ebp), %eax
        leal    1(%eax), %edx
        cmpl    $10, %eax
        movl    %edx, -12(%ebp)
        jne     .L2


-- 


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



More information about the Gcc-bugs mailing list