[Patch, Fortran] Simplify lbound
Thomas Koenig
tkoenig@netcologne.de
Sat Apr 25 11:34:00 GMT 2015
Hello world,
this is a simplification for calculating the lboud of assumed-shape
arrays - it is usually one, or whatever the user specified as
lower bound (if constant).
The surprising thing was that the current code generated for the
array descriptor for
subroutine foo(a, b, n, m)
integer, dimension(:), intent(inout) :: a
integer, dimension(-2:), intent(inout) :: b
integer, intent(out) :: n,m
n = lbound(a,1)
m = lbound(b,1)
end subroutine foo
was not simplified to the simple assignment even at -O. This is
what the assembly looks like with the patch:
movl $1, (%rdx)
movl $-2, (%rcx)
ret
and this is what it looks like without the patch:
movq 24(%rsi), %rax
testq %rax, %rax
movl $1, %edi
cmove %rdi, %rax
movq 40(%rsi), %rdi
subq 32(%rsi), %rdi
movq %rdi, %rsi
subq $2, %rsi
movl $1, (%rdx)
movq %rax, %rdx
notq %rdx
shrq $63, %rdx
cmpq $-2, %rsi
setge %sil
movzbl %sil, %esi
testl %edx, %esi
jne .L6
shrq $63, %rax
movl $1, %edx
testl %eax, %eax
je .L3
.L6:
movl $-2, %edx
.L3:
movl %edx, (%rcx)
ret
This is important for the matmul inline patch, because I am using
lbound extensively there. The other cases (allocatables and
pointers as dummy arguments) are already covered.
Regression-tested. OK for trunk?
2015-04-25 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/37131
* simplify.c (simplify_bound): Get constant lower bounds
from array spec for assumed shape arrays.
2015-04-25 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/37131
* gfortran.dg/coarray_lib_this_image_2.f90: Adjust
scan pattern.
* gfortran.dg/bound_9.f90: New test case.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p2.diff
Type: text/x-patch
Size: 2381 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20150425/dcc3ccbd/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bound_9.f90
Type: text/x-fortran
Size: 855 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20150425/dcc3ccbd/attachment-0001.bin>
More information about the Fortran
mailing list