From patchwork Tue Oct 17 22:36:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 827349 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-464382-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="O1fQfv+G"; dkim-atps=neutral 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 3yGqn721bQz9t2d for ; Wed, 18 Oct 2017 09:36:55 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=KGBYJCn5EhVk3EEkShXOnvyg9DFFlbJBD9kJ4rOlL13tzSTRkw k4jk4oGtaX9hZgfa11vPDiuhJur1dvjQhwpzlYpN4fL4+fgf+hngl3WCI+Jx4eRy h8H9aKWXrBZ1ZlXUQrRLtEIHYg8TF7VwMlI2UEoWcnVrqHkRGuG4I4+w0= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=7XHlyz8QM9a3jbh/u2972E0nRYo=; b=O1fQfv+GESGqhXqUi2hh OogCge/p0AJNjHriWe40S8ObR3Fd1Jn1/e3gx7iwknUlCulgMFlE9RwGaLihi4YL PP+zQiydHsrQBpICUS/9t8XEyNgCGDLcdi5mPcKS9oI7Ygkqy52T8ndNzVSFAqyp oBkXml/RoQLZYAEWPEpSuL0= Received: (qmail 95070 invoked by alias); 17 Oct 2017 22:36:43 -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 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: Wed, 18 Oct 2017 00:36:34 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 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. 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)) {