From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 112795 invoked by alias); 25 Apr 2015 11:34:04 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 112774 invoked by uid 89); 25 Apr 2015 11:34:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,KAM_ASCII_DIVIDERS,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: cc-smtpout3.netcologne.de Received: from cc-smtpout3.netcologne.de (HELO cc-smtpout3.netcologne.de) (89.1.8.213) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 25 Apr 2015 11:34:01 +0000 Received: from cc-smtpin1.netcologne.de (cc-smtpin1.netcologne.de [89.1.8.201]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id 84C1386AC4; Sat, 25 Apr 2015 13:33:58 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin1.netcologne.de (Postfix) with ESMTP id 76BE811E18; Sat, 25 Apr 2015 13:33:58 +0200 (CEST) Received: from [78.35.187.166] (helo=cc-smtpin1.netcologne.de) by localhost with ESMTP (eXpurgate 4.0.6) (envelope-from ) id 553b7ba6-0bdb-7f0000012729-7f000001a549-1 for ; Sat, 25 Apr 2015 13:33:58 +0200 Received: from [192.168.178.20] (xdsl-78-35-187-166.netcologne.de [78.35.187.166]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by cc-smtpin1.netcologne.de (Postfix) with ESMTPSA; Sat, 25 Apr 2015 13:33:56 +0200 (CEST) Message-ID: <553B7BA4.6040103@netcologne.de> Date: Sat, 25 Apr 2015 11:34:00 -0000 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: "fortran@gcc.gnu.org" , gcc-patches Subject: [Patch, Fortran] Simplify lbound Content-Type: multipart/mixed; boundary="------------030602020207000804000500" X-SW-Source: 2015-04/txt/msg01541.txt.bz2 This is a multi-part message in MIME format. --------------030602020207000804000500 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-length: 1892 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 PR fortran/37131 * simplify.c (simplify_bound): Get constant lower bounds from array spec for assumed shape arrays. 2015-04-25 Thomas Koenig PR fortran/37131 * gfortran.dg/coarray_lib_this_image_2.f90: Adjust scan pattern. * gfortran.dg/bound_9.f90: New test case. --------------030602020207000804000500 Content-Type: text/x-patch; name="p2.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="p2.diff" Content-length: 2381 Index: fortran/simplify.c =================================================================== --- fortran/simplify.c (Revision 222431) +++ fortran/simplify.c (Arbeitskopie) @@ -3445,6 +3445,32 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gf done: + + if (!upper && as && as->type == AS_ASSUMED_SHAPE && dim + && dim->expr_type == EXPR_CONSTANT && ref->u.ar.type != AR_SECTION) + { + if (!(array->symtree && array->symtree->n.sym + && (array->symtree->n.sym->attr.allocatable + || array->symtree->n.sym->attr.pointer))) + { + unsigned long int ndim; + gfc_expr *lower, *res; + + ndim = mpz_get_si (dim->value.integer) - 1; + lower = as->lower[ndim]; + if (lower->expr_type == EXPR_CONSTANT) + { + res = gfc_copy_expr (lower); + if (kind) + { + int nkind = mpz_get_si (kind->value.integer); + res->ts.kind = nkind; + } + return res; + } + } + } + if (as && (as->type == AS_DEFERRED || as->type == AS_ASSUMED_SHAPE || as->type == AS_ASSUMED_RANK)) return NULL; Index: testsuite/gfortran.dg/coarray_lib_this_image_2.f90 =================================================================== --- testsuite/gfortran.dg/coarray_lib_this_image_2.f90 (Revision 222431) +++ testsuite/gfortran.dg/coarray_lib_this_image_2.f90 (Arbeitskopie) @@ -20,7 +20,7 @@ end ! { dg-final { scan-tree-dump-times "mylcobound = 5;" 1 "original" } } ! { dg-final { scan-tree-dump-times "parm...dim\\\[1\\\].lbound = 5;" 1 "original" } } ! { dg-final { scan-tree-dump-times "myucobound =\[^\n\r\]* parm...dim\\\[1\\\].lbound \\+ \[^\n\r\]*_gfortran_caf_num_images \\(0, -1\\).? \\+ -?\[0-9\]+\\);" 1 "original" } } -! { dg-final { scan-tree-dump-times "mylbound = parm...dim\\\[0\\\].stride >= 0 && parm...dim\\\[0\\\].ubound >= parm...dim\\\[0\\\].lbound \\|\\| parm...dim\\\[0\\\].stride < 0 \\?\[^\n\r\]* parm...dim\\\[0\\\].lbound : 1;" 1 "original" } } +! { dg-final { scan-tree-dump-times "mylbound = 1;" 1 "original" } } ! { dg-final { scan-tree-dump-times "mythis_image = _gfortran_caf_this_image \\(0\\);" 1 "original" } } ! { dg-final { scan-tree-dump-times "bar \\(&parm.\[0-9\]+, caf_token.\[0-9\]+, \\(integer\\(kind=\[48\]\\)\\) parm.\[0-9\]+.data - \\(integer\\(kind=\[48\]\\)\\) x\\);" 1 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_init \\(&argc, &argv\\);" 1 "original" } } --------------030602020207000804000500 Content-Type: text/x-fortran; name="bound_9.f90" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="bound_9.f90" Content-length: 855 ! { dg-do run } ! Check that simplificiation of ubound is done. ! { dg-options "-O -fdump-tree-original -fdump-tree-optimized" } module bar implicit none contains 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 end module bar program main use bar implicit none integer, dimension(3) :: a, b integer :: n,m call foo(a,b,n,m) if (n .ne. 1 .or. m .ne. -2) call abort end program main ! { dg-final { scan-tree-dump-times "\\*n = 1" 1 "original" } } ! { dg-final { scan-tree-dump-times "\\*m = -2" 1 "original" } } ! { dg-final { scan-tree-dump-times "lbound" 0 "optimized" } } ! { dg-final { cleanup-tree-dump "original" } } ! { dg-final { cleanup-tree-dump "optimized" } } --------------030602020207000804000500--