From patchwork Thu Feb 2 09:21:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 722930 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 3vDZHq2GQfz9ryr for ; Thu, 2 Feb 2017 20:21:25 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="PT9hhS4r"; 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:date :from:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=mBK7elCkYpqfcXmV e1t9FmTi0uMI378Gk4fmdxshmcygXskBQgIcpR+QnLr4MAPNFMbM/D50Xm/yB6EZ n0BXnuMvbTPR47DNctDC34pvA8aVzhgcsZ1BvKay975FnKARYYClG3BkmX/8Fag+ 796TO6jteZ5/40hn6KTZVcG90SU= 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:date :from:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=Oq6JDmH3z5L+17eVA3hHoa fB1VU=; b=PT9hhS4rFpW8rmAiRyq8PfcYUu4bU45Qy0YzjErYlCpfjmLZxQVb0S qeTBjuDuU8OEFJY9Fnc1do1mWt55aUdLMBTGEohfv+YCS1qEyY0QfqZ6FSeO7mDZ 6gmclp339N+I3zFjoCOPShb20hLdTW7YOLOXvSM4abtxj5wosDej8= Received: (qmail 7564 invoked by alias); 2 Feb 2017 09:21:15 -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 7551 invoked by uid 89); 2 Feb 2017 09:21:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=no version=3.3.2 spammy=fruit, needless, Bail X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 02 Feb 2017 09:21:04 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id F06DCAB1D; Thu, 2 Feb 2017 09:21:01 +0000 (UTC) Date: Thu, 2 Feb 2017 10:21:01 +0100 (CET) From: Richard Biener To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org, jason@redhat.com Subject: Re: [PATCH][C++] Improve memory use for PR12245 In-Reply-To: Message-ID: References: <20170201144109.GE14051@tucnak> User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 On Wed, 1 Feb 2017, Richard Biener wrote: > On Wed, 1 Feb 2017, Jakub Jelinek wrote: > > > On Wed, Feb 01, 2017 at 02:14:20PM +0100, Richard Biener wrote: > > > > > > Looks like we cache the answer to maybe_constant_value (INTEGER_CST) > > > which results in (-fmem-report): > > > > > > cp/constexpr.c:4814 (maybe_constant_value) 67108816:100.0% > > > 100663104 17: 0.0% ggc > > > > > > this can be improved trivially to > > > > > > cp/constexpr.c:4817 (maybe_constant_value) 2032: 13.6% > > > 2144 2: 0.0% ggc > > > > > > with the following patch which I am testing right now. > > > > > > Ok for trunk? > > > > > > (just in case it causes some fallout because, err, some tcc_constant > > > is not really constant, what's the subset we can cheaply check here? > > > basically we want to avoid caching all INTEGER_CSTs we use for > > > CONSTRUCTOR_INDEX in large initializers) > > > > I'm worried that we don't want to handle all the constants that way. > > As I wrote on IRC, I see some problematic constants: > > 1) not sure if constants can't be > > potential_nondependent_constant_expression, then we don't want to return > > them > > 2) cxx_eval_outermost_constant_expr has some special handling of > > trees with vector type (and array type) > > 3) constants with TREE_OVERFLOW should go through maybe_constant_value_1 > > 4) INTEGER_CSTs with POINTER_TYPE (if they aren't 0) likewise > > > > For 3) and 4) I believe maybe_constant_value is supposed to wrap the > > constants into a NOP_EXPR or something. > > Just to mention, bootstrap & regtest completed successfully without > regressions on x86_64-unknown-linux-gnu so we at least have zero > testing coverage for the cases that break. > > I'll wait for Jason to suggest specific things to avoid, TREE_OVERFLOW > and pointer types are easy (no need to special case zero, it's just > one entry per pointer type). Oh, and just to mention the same issue of course plagues maybe_constant_init which ends up allocating a hash_map 1630776 times (fixing that doesn't fix any memory-hog but would avoid some needless cycles spent on this). Similar "simple" patch would be * constexpr.c (maybe_constant_init): Bail out early for CONSTANT_CLASS_P. which is even eventually safer because it's after the !potential_nondependent_static_init_expression (if that can be ever true for CONSTANT_CLASS_P t). Then the other issue noticed is that we always copy every CONSTRUCTOR at least once via reshape_init_array. I think both maybe_constant_value and maybe_constant_init are low-hanging fruit to fix at this point so waiting for some guidance on Jakubs concerns (or just take it yourself from here). Thanks, Richard. > > > 2017-02-01 Richard Biener > > > > > > cp/ > > > * constexpr.c (maybe_constant_value): Do not cache > > > CONSTANT_CLASS_P nodes. > > > > > > Index: gcc/cp/constexpr.c > > > =================================================================== > > > --- gcc/cp/constexpr.c (revision 245094) > > > +++ gcc/cp/constexpr.c (working copy) > > > @@ -4810,6 +4810,9 @@ static GTY((deletable)) hash_map > > tree > > > maybe_constant_value (tree t, tree decl) > > > { > > > + if (CONSTANT_CLASS_P (t)) > > > + return t; > > > + > > > if (cv_cache == NULL) > > > cv_cache = hash_map::create_ggc (101); > > > Index: gcc/cp/constexpr.c =================================================================== --- gcc/cp/constexpr.c (revision 245119) +++ gcc/cp/constexpr.c (working copy) @@ -4916,6 +4919,8 @@ maybe_constant_init (tree t, tree decl) t = TARGET_EXPR_INITIAL (t); if (!potential_nondependent_static_init_expression (t)) /* Don't try to evaluate it. */; + else if (CONSTANT_CLASS_P (t)) + return t; else t = cxx_eval_outermost_constant_expr (t, true, false, decl); if (TREE_CODE (t) == TARGET_EXPR)