From patchwork Sat May 9 22:31:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 470396 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 7E3A314016A for ; Sun, 10 May 2015 08:31:43 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Zn+/b30D; 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=RKnBARRRLItrppOMm pGzymfhzroYgZRmvm/0mVj36OLkNuIBnQcpZnNPybMXmcYBrfB/PWcp83Ik3JNHq i1t0vs1yUkyn1eSDrdaR3qtiTJR26mSCYeV3qVHwq/InssT2o9z4TTfbD3mwaZCp U1AMFRMnyaBglHiraUW+/vckxc= 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=3MVzhbDwQxCvo2CO+z+08l3 Pp4s=; b=Zn+/b30DdO9l6BPJxhC5W3UoGLTdIvIANX+es3iHnNm8CoPWiGUFMTG EwdfvQxTdDajNCY/JcJDPavF5CZLNUqdeiX/W45Qm1PG8/Sj9vY/JJB2NqJW9jOI qvtJCHdRWFwajNf6fb8HbnT2wdy7Chnc2x/HD6RlR73LAKtzxxNk= Received: (qmail 94355 invoked by alias); 9 May 2015 22:31:29 -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 94338 invoked by uid 89); 9 May 2015 22:31:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL, BAYES_50, 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-smtpout2.netcologne.de Received: from cc-smtpout2.netcologne.de (HELO cc-smtpout2.netcologne.de) (89.1.8.212) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 09 May 2015 22:31:26 +0000 Received: from cc-smtpin3.netcologne.de (cc-smtpin3.netcologne.de [89.1.8.203]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id 3A5BF11EF9; Sun, 10 May 2015 00:31:22 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin3.netcologne.de (Postfix) with ESMTP id 2A8DE11DD8; Sun, 10 May 2015 00:31:22 +0200 (CEST) Received: from [78.35.161.90] (helo=cc-smtpin3.netcologne.de) by localhost with ESMTP (eXpurgate 4.0.7) (envelope-from ) id 554e8aba-0b62-7f0000012729-7f000001ec97-1 for ; Sun, 10 May 2015 00:31:22 +0200 Received: from [192.168.178.20] (xdsl-78-35-161-90.netcologne.de [78.35.161.90]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by cc-smtpin3.netcologne.de (Postfix) with ESMTPSA; Sun, 10 May 2015 00:31:19 +0200 (CEST) Message-ID: <554E8AB6.7000101@netcologne.de> Date: Sun, 10 May 2015 00:31:18 +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: Mikael Morin , "fortran@gcc.gnu.org" , gcc-patches Subject: Re: [patch, Fortran] Fix PR 66041 References: <554D348A.2050509@netcologne.de> <554DF684.2000800@sfr.fr> In-Reply-To: <554DF684.2000800@sfr.fr> Am 09.05.2015 um 13:59 schrieb Mikael Morin: > You also need to remove/free the trailing subreferences. That's right, I did that. Although I will probably never understand why lbound(a) should be different from lbound(a%r)... >> + /* We have to get rid of the shape, if thre is one. Do >> + so by freeing it and calling gfc_resolve to rebuild it, >> + if necessary. */ >> + >> + if (lbound_e->shape) >> + gfc_free_shape (&(lbound_e->shape), lbound_e->rank); >> + > >> + lbound_e->rank = ar->dimen; > ar->dimen is not what you think it is. > It is 3 for array(1, 1, :), while the rank is 1. > gfc_resolve_expr should set the rank for you, so just remove this line. It doesn't (for whatever reason), so I kept on setting it. >> + >> + gfc_resolve_expr (lbound_e); >> + lbound = get_array_inq_function (GFC_ISYM_LBOUND, >> + lbound_e, i + 1); > free lbound_e? It will be part of the lbound expression, or be simplified away. > >> } >> - lbound = get_array_inq_function (GFC_ISYM_LBOUND, e_in, >> - i_index + 1); >> + else >> + lbound = get_array_inq_function (GFC_ISYM_LBOUND, e_in, >> + i_index + 1); > You can't reuse e_in if it has subreferences. Changed. >> } >> >> ar->dimen_type[i] = DIMEN_ELEMENT; >> @@ -2639,6 +2665,8 @@ scalarized_expr (gfc_expr *e_in, gfc_expr **index, >> i_index ++; >> } >> } >> + gfc_free_expr (e_in); >> + > This side effect is asking for trouble. > Instead of this, remove the copies made in the callers. > This is independant from the rest, so it can be made later as a follow-up. Done (all in once). I have attached the new patch (in which I also restructured the test), plus the test cases. OK for trunk? Thomas 2015-05-08 Thomas Koenig PR fortran/66041 * frontend-passes.c (scalarized_expr): Copy first argument so it is not necessary to call gfc_copy_expr() on its argument. Set correct dimension and shape for the expression to be passed to lbound. Remove trailing references after array refrence. (inline_matmul_assign): Remove gfc_copy_expr() from calls to scalarized_expr(). 2015-05-08 Thomas Koenig PR fortran/66041 * gfortran.dg/inline_matmul_7.f90: New test. * gfortran.dg/inline_matmul_8.f90: New test. * gfortran.dg/inline_matmul_9.f90: New test. Index: frontend-passes.c =================================================================== --- frontend-passes.c (Revision 222864) +++ frontend-passes.c (Arbeitskopie) @@ -2532,16 +2532,17 @@ get_size_m1 (gfc_expr *e, int dimen) references have been frozen. */ static gfc_expr* -scalarized_expr (gfc_expr *e_in, gfc_expr **index, int count_index) +scalarized_expr (gfc_expr *ei, gfc_expr **index, int count_index) { gfc_array_ref *ar; int i; int rank; - gfc_expr *e; + gfc_expr *e, *e_in; int i_index; bool was_fullref; - e = gfc_copy_expr(e_in); + e = gfc_copy_expr(ei); + e_in = gfc_copy_expr (ei); rank = e->rank; @@ -2607,18 +2608,54 @@ static gfc_expr* } else { + gfc_expr *lbound_e; + gfc_ref *ref; + + lbound_e = gfc_copy_expr (e_in); + + for (ref = lbound_e->ref; ref; ref = ref->next) + if (ref->type == REF_ARRAY + && (ref->u.ar.type == AR_FULL + || ref->u.ar.type == AR_SECTION)) + break; + + if (ref->next) + { + gfc_free_ref_list (ref->next); + ref->next = NULL; + } + if (!was_fullref) { /* Look at full individual sections, like a(:). The first index is the lbound of a full ref. */ - + int j; gfc_array_ref *ar; - ar = gfc_find_array_ref (e_in); + ar = &ref->u.ar; ar->type = AR_FULL; + for (j = 0; j < ar->dimen; j++) + { + gfc_free_expr (ar->start[j]); + ar->start[j] = NULL; + gfc_free_expr (ar->end[j]); + ar->end[j] = NULL; + gfc_free_expr (ar->stride[j]); + ar->stride[j] = NULL; + } + + /* We have to get rid of the shape, if there is one. Do + so by freeing it and calling gfc_resolve to rebuild + it, if necessary. */ + + if (lbound_e->shape) + gfc_free_shape (&(lbound_e->shape), lbound_e->rank); + + lbound_e->rank = ar->dimen; + gfc_resolve_expr (lbound_e); } - lbound = get_array_inq_function (GFC_ISYM_LBOUND, e_in, - i_index + 1); + lbound = get_array_inq_function (GFC_ISYM_LBOUND, lbound_e, + i + 1); } ar->dimen_type[i] = DIMEN_ELEMENT; @@ -2639,6 +2676,8 @@ static gfc_expr* i_index ++; } } + gfc_free_expr (e_in); + return e; } @@ -2929,15 +2968,15 @@ inline_matmul_assign (gfc_code **c, int *walk_subt list[0] = var_3; list[1] = var_1; - cscalar = scalarized_expr (gfc_copy_expr (co->expr1), list, 2); + cscalar = scalarized_expr (co->expr1, list, 2); list[0] = var_3; list[1] = var_2; - ascalar = scalarized_expr (gfc_copy_expr (matrix_a), list, 2); + ascalar = scalarized_expr (matrix_a, list, 2); list[0] = var_2; list[1] = var_1; - bscalar = scalarized_expr (gfc_copy_expr (matrix_b), list, 2); + bscalar = scalarized_expr (matrix_b, list, 2); break; @@ -2955,14 +2994,14 @@ inline_matmul_assign (gfc_code **c, int *walk_subt var_2 = do_2->ext.iterator->var; list[0] = var_2; - cscalar = scalarized_expr (gfc_copy_expr (co->expr1), list, 1); + cscalar = scalarized_expr (co->expr1, list, 1); list[0] = var_2; list[1] = var_1; - ascalar = scalarized_expr (gfc_copy_expr (matrix_a), list, 2); + ascalar = scalarized_expr (matrix_a, list, 2); list[0] = var_1; - bscalar = scalarized_expr (gfc_copy_expr (matrix_b), list, 1); + bscalar = scalarized_expr (matrix_b, list, 1); break; @@ -2980,14 +3019,14 @@ inline_matmul_assign (gfc_code **c, int *walk_subt var_2 = do_2->ext.iterator->var; list[0] = var_1; - cscalar = scalarized_expr (gfc_copy_expr (co->expr1), list, 1); + cscalar = scalarized_expr (co->expr1, list, 1); list[0] = var_2; - ascalar = scalarized_expr (gfc_copy_expr (matrix_a), list, 1); + ascalar = scalarized_expr (matrix_a, list, 1); list[0] = var_2; list[1] = var_1; - bscalar = scalarized_expr (gfc_copy_expr (matrix_b), list, 2); + bscalar = scalarized_expr (matrix_b, list, 2); break;