------- Comment #23 from tkoenig at gcc dot gnu dot org 2009-08-14 22:05
-------
(In reply to comment #20)
> Created an attachment (id=18369)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18369&action=view) [edit]
> updated patch
>
> Corrected patch, I copied the variables in the wrong order on loop entry,
> clobbering the upper bound if it also happened to be the DO variable.
Hello Tobi,
your patch doesn't help a lot for this test case:
module foo
contains
subroutine output(i1,i2,i3,i4,i5)
print '(5(I0,:" "))',i1,i2,i3,i4,i5
end subroutine output
end module foo
program main
use foo
implicit none
integer :: value
integer :: p1, p2, p3, p4
integer :: i
do value = 750,800
do i=1, 10
do p1 = 1, value-2
do p2 = p1 + 1, value - p1
do p3 = p2 + 1, (value - (p1 + p2))/2
p4 = value - p1 - p2 - p3
if (p1 * p2 * p3 * p4 == value * 1000000) &
& call output(value,p1,p2,p3,p4)
end do
end do
end do
end do
end do
end program main
Without your patch:
tkoe...@gcc16:~/Do$ gfortran -fdump-tree-original -O2 count-4.f90 && time
./a.out > /dev/null
real 0m8.448s
user 0m8.449s
sys 0m0.000s
With your patch:
tkoe...@gcc16:~/Do$ gfortran -fdump-tree-original -O2 count-4.f90 && time
./a.out > /dev/null
real 0m7.772s
user 0m7.768s
sys 0m0.004s
The test case
tkoe...@gcc16:~/Do$ cat count-5.f90
module foo
contains
subroutine output(i1,i2,i3,i4,i5)
print '(5(I0,:" "))',i1,i2,i3,i4,i5
end subroutine output
end module foo
program main
use foo
implicit none
integer :: value
integer :: p1, p2, p3, p4
integer :: i
do value = 750,800
do i=1, 10
do p1 = 1, value-2
do p2 = p1 + 1, value - p1
do p3 = p2 + 1, (value - (p1 + p2))/2
p4 = value - p1 - p2 - p3
if (p1 * p2 * p3 * p4 == value * 1000000) &
& call output((value),(p1),(p2),(p3),(p4))
end do
end do
end do
end do
end do
end program main
tkoe...@gcc16:~/Do$ gfortran -fdump-tree-original -O2 count-5.f90 && time
./a.out > /dev/null
real 0m4.057s
user 0m4.056s
still produces much better code.
I think it would be better to use the original loop variable, and to create a
copy each time it is passed by reference.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31593