From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 95069 invoked by alias); 17 Oct 2017 22:36:43 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@gcc.gnu.org Received: (qmail 94507 invoked by uid 89); 17 Oct 2017 22:36:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-12.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=our 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 ESMTP; Tue, 17 Oct 2017 22:36:41 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id B3890125F2; Wed, 18 Oct 2017 00:36:37 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id A5F1811DBB; Wed, 18 Oct 2017 00:36:37 +0200 (CEST) Received: from [78.35.134.134] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.1.9) (envelope-from ) id 59e685f5-02b8-7f0000012729-7f000001e366-1 for ; Wed, 18 Oct 2017 00:36:37 +0200 Received: from [192.168.178.20] (xdsl-78-35-134-134.netcologne.de [78.35.134.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA; Wed, 18 Oct 2017 00:36:35 +0200 (CEST) To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, fortran] Fix PR 82567 Message-ID: <359f2531-46d3-b2ce-666b-1267d28c1303@netcologne.de> Date: Tue, 17 Oct 2017 22:36:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2B0276DFC876A19045A7E64E" X-SW-Source: 2017-10/txt/msg00072.txt.bz2 This is a multi-part message in MIME format. --------------2B0276DFC876A19045A7E64E Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 785 Hello world, this patch fixes a regression with long compile times, which came about due to our handling of array constructors at compile time. This, togeteher with a simplification in front end optimization, led to long compile times and large code. Regression-tested. OK for trunk and the other affected branches? Regards Thomas 2917-10-17 Thomas Koenig PR fortran/82567 * frontend-passes.c (combine_array_constructor): If an array constructor is all constants and has more elements than a small constant, don't convert a*[b,c] to [a*b,a*c] to reduce compilation times. 2917-10-17 Thomas Koenig PR fortran/82567 * gfortran.dg/array_constructor_51.f90: New test. --------------2B0276DFC876A19045A7E64E Content-Type: text/x-fortran; name="array_constructor_51.f90" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="array_constructor_51.f90" Content-length: 450 ! { dg-do compile } ! { dg-additional-options "-ffrontend-optimize -fdump-tree-original" } ! PR 82567 - long compile times caused by large constant constructors ! multiplied by variables SUBROUTINE sub() IMPLICIT NONE INTEGER, PARAMETER :: n = 1000 REAL, ALLOCATABLE :: x(:) REAL :: xc, h INTEGER :: i ALLOCATE( x(n) ) xc = 100. h = xc/n x = h*[(i,i=1,n)] end ! { dg-final { scan-tree-dump-times "__var" 0 "original" } } --------------2B0276DFC876A19045A7E64E Content-Type: text/x-patch; name="p1.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="p1.diff" Content-length: 1554 Index: frontend-passes.c =================================================================== --- frontend-passes.c (Revision 253768) +++ frontend-passes.c (Arbeitskopie) @@ -1635,6 +1635,8 @@ combine_array_constructor (gfc_expr *e) gfc_constructor *c, *new_c; gfc_constructor_base oldbase, newbase; bool scalar_first; + int n_elem; + bool all_const; /* Array constructors have rank one. */ if (e->rank != 1) @@ -1674,12 +1676,38 @@ combine_array_constructor (gfc_expr *e) if (op2->ts.type == BT_CHARACTER) return false; - scalar = create_var (gfc_copy_expr (op2), "constr"); + /* This might be an expanded constructor with very many constant values. If + we perform the operation here, we might end up with a long compile time, + so an arbitrary length bound is in order here. If the constructor + constains something which is not a constant, it did not come from an + expansion, so leave it alone. */ +#define CONSTR_LEN_MAX 42 + oldbase = op1->value.constructor; + + n_elem = 0; + all_const = true; + for (c = gfc_constructor_first (oldbase); c; c = gfc_constructor_next(c)) + { + if (c->expr->expr_type != EXPR_CONSTANT) + { + all_const = false; + break; + } + n_elem += 1; + } + + if (all_const && n_elem > CONSTR_LEN_MAX) + return false; + +#undef CONSTR_LEN_MAX + newbase = NULL; e->expr_type = EXPR_ARRAY; + scalar = create_var (gfc_copy_expr (op2), "constr"); + for (c = gfc_constructor_first (oldbase); c; c = gfc_constructor_next (c)) { --------------2B0276DFC876A19045A7E64E--