From patchwork Mon Apr 27 19:22:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 465203 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id F216E14007D for ; Tue, 28 Apr 2015 05:23:05 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=MNkBAYH7; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=MfNyV3oSHNRN6asth QKUvYl5vq9zX/alf7eG8bAv1zIkyM0IrA+1t0j0ynGjZfm6eVY2+H1w7HVyUhPFG Uyqu1wYJ8zRGm5scZfS+urZPe4SXt+xt7GtMpZmS83u7L4PUKWE41K1EMmNqLPBp KauArGG6u81kfuArPtdexBO7vI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=s7eZzaf4xqTozUgsE3hCbtp ddio=; b=MNkBAYH7bMBh8nHowlxMnyqhWMNYo1afUPqonL3QEjT2XqED8I54j8Y AAMlCC2cBLCYvTniw4p2mXrzIoefeDG9iXNozGIkplEc5xTlCXRccJmPmRz452Pf 7SGr0EejrqvW/lxS9t0BzVQda7u0q7JSYjlBvrlfWt+hzLuu+uPk= Received: (qmail 110529 invoked by alias); 27 Apr 2015 19:22:50 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 109753 invoked by uid 89); 27 Apr 2015 19:22:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL, BAYES_50, 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; Mon, 27 Apr 2015 19:22:48 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id A32B31201A; Mon, 27 Apr 2015 21:22:44 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id 9378E11D81; Mon, 27 Apr 2015 21:22:44 +0200 (CEST) Received: from [78.35.156.120] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.0.6) (envelope-from ) id 553e8c84-0b84-7f0000012729-7f000001b2e3-1 for ; Mon, 27 Apr 2015 21:22:44 +0200 Received: from [192.168.178.20] (xdsl-78-35-156-120.netcologne.de [78.35.156.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA; Mon, 27 Apr 2015 21:22:43 +0200 (CEST) Message-ID: <553E8C82.7060801@netcologne.de> Date: Mon, 27 Apr 2015 21:22:42 +0200 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: Re: [Patch, Fortran] Simplify lbound References: <553B7BA4.6040103@netcologne.de> <553BD925.3050401@sfr.fr> <553E83B4.8020005@netcologne.de> In-Reply-To: <553E83B4.8020005@netcologne.de> Hello world, here is a slight correction: This patch includes the change to the test case. Regards Thomas Index: fortran/simplify.c =================================================================== --- fortran/simplify.c (Revision 222431) +++ fortran/simplify.c (Arbeitskopie) @@ -3445,6 +3445,39 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gf done: + /* If the array shape is assumed shape or explicit, we can simplify lbound + to 1 if the given lower bound is one because this matches what lbound + should return for an empty array. */ + + if (!upper && as && dim && dim->expr_type == EXPR_CONSTANT + && (as->type == AS_ASSUMED_SHAPE || as->type == AS_EXPLICIT) + && ref->u.ar.type != AR_SECTION) + { + /* Watch out for allocatable or pointer dummy arrays, they can have + lower bounds that are not equal to one. */ + 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 + && mpz_cmp_si (lower->value.integer, 1) == 0) + { + 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" } }