From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19391 invoked by alias); 14 Jan 2013 13:29:54 -0000 Received: (qmail 19373 invoked by uid 22791); 14 Jan 2013 13:29:52 -0000 X-SWARE-Spam-Status: No, hits=-0.4 required=5.0 tests=AWL,BAYES_50,KAM_STOCKGEN,KHOP_THREADED,RCVD_IN_DNSWL_NONE,RCVD_IN_HOSTKARMA_NO,RP_MATCHES_RCVD,TW_FC X-Spam-Check-By: sourceware.org Received: from smtp25.services.sfr.fr (HELO smtp25.services.sfr.fr) (93.17.128.118) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 14 Jan 2013 13:29:44 +0000 Received: from filter.sfr.fr (localhost [127.0.0.1]) by msfrf2519.sfr.fr (SMTP Server) with ESMTP id 65AEA700008B; Mon, 14 Jan 2013 14:29:40 +0100 (CET) Received: from [192.168.1.58] (150.15.72.86.rev.sfr.net [86.72.15.150]) by msfrf2519.sfr.fr (SMTP Server) with ESMTP id 010257000089; Mon, 14 Jan 2013 14:29:39 +0100 (CET) X-SFR-UUID: 20130114132940422.010257000089@msfrf2519.sfr.fr Message-ID: <50F4083E.30902@sfr.fr> Date: Mon, 14 Jan 2013 13:29:00 -0000 From: Mikael Morin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.11) Gecko/20121222 Thunderbird/10.0.11 MIME-Version: 1.0 To: Thomas Koenig CC: "fortran@gcc.gnu.org" , gcc-patches Subject: Re: [patch, Fortran] PR 55806 - Inefficient ANY with array constructors References: <50E344A6.1000802@netcologne.de> <50F06DB9.40102@sfr.fr> <50F331C8.2000200@netcologne.de> In-Reply-To: <50F331C8.2000200@netcologne.de> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 8bit X-IsSubscribed: yes 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 X-SW-Source: 2013-01/txt/msg00676.txt.bz2 Le 13/01/2013 23:14, Thomas Koenig a écrit : > Hi Mikael, > > thanks a lot for your comments! > >>> + actual_arglist->expr = gfc_copy_expr (e); + >>> actual_arglist->next = gfc_get_actual_arglist (); >> Another one is needed. I get a segmentation fault with SUM. > > Fixed by using gfc_build_intrisic_call. Nice. > > Updated test case and patch attached. > Index: frontend-passes.c > =================================================================== > --- frontend-passes.c (Revision 195136) > +++ frontend-passes.c (Arbeitskopie) [...] > + else if (id == GFC_ISYM_ANY || id == GFC_ISYM_ALL) > + fcn = gfc_build_intrinsic_call (current_ns, > + fn->value.function.isym->id, > + fn->value.function.isym->name, > + fn->where, 2, gfc_copy_expr (e), > + NULL); > + else > + gfc_error ("Illegal id in copy_walk_reduction_arg"); This is not very useful for a user. It should be an internal error (or gcc_unreachable would do as well). > + > +/* Callback function for optimzation of reductions to scalars. Transform ANY > + ([f1,f2,f3, ...]) to f1 .or. f2 .or. f3 .or. ..., with ANY, SUM and PRODUCT > + correspondingly. Handly only the simple cases without MASK and DIM. */ > + > +static int > +callback_reduction (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED, > + void *data ATTRIBUTE_UNUSED) > +{ > + gfc_expr *fn, *arg; > + gfc_intrinsic_op op; > + gfc_isym_id id; > + gfc_actual_arglist *a; > + gfc_actual_arglist *dim; > + gfc_constructor *c; > + gfc_expr *res, *new_expr; > + gfc_actual_arglist *mask; > + > + fn = *e; > + > + if (fn->rank != 0 || fn->expr_type != EXPR_FUNCTION > + || fn->value.function.isym == NULL) > + return 0; > + > + id = fn->value.function.isym->id; > + > + if (id != GFC_ISYM_SUM && id != GFC_ISYM_PRODUCT > + && id != GFC_ISYM_ANY && id != GFC_ISYM_ALL) > + return 0; > + > + a = fn->value.function.actual; > + > + /* Don't handle MASK or DIM. */ > + > + dim = a->next; > + > + if (dim->expr != NULL) > + return 0; > + Trailing whitespace. > + mask = dim->next; > + if (mask != NULL) > + if ( mask->expr != NULL) > + return 0; This is a bit confusing as mask is the first argument in the ANY/ALL case. You can use something like this instead: if (id == GFC_ISYM_SUM || id == GFC_ISYM_PRODUCT) { mask = dim->next; if (mask->expr != NULL) return 0; } > > OK for trunk? > OK with the changes suggested above. Thanks. Mikael