From patchwork Mon Aug 18 12:07:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 380986 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 3542C1400A8 for ; Mon, 18 Aug 2014 22:08:44 +1000 (EST) 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:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=yDaZUlG5En45TQfpY s6lFNbw+q+Rca2hMBNcws+Nn0oVs5etsukJHehDOVqPEJ+P81vi9tuxO+FB/KrUa 8u8RdwqZIGCBEQisyomDBg3O7BkbfZD6iQ5jx+AYcJYKQ3XekbY3BHYaJnchQj0e 1kj+hHXSGJzQHd9YdCsQmVz6rk= 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:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=IL5WlUGkWUjFFb9AnASadX7 ECik=; b=hxd324RZ/1X7YSxc7s+qXVU1aD4TK+qQ7+7q29DMNqRQm+zDXbkEr4G 9GaspYFlcIrlwR1ljF4nrn2PUC1yzLGCRBj8CWDuCv2J6vZPItiGM8ndx7I5g9ZZ DrgtH29P/Cj0Q9Z6UNhByNWwA+yL6r2miXWjIJTA5SZpx1s1KkzA= Received: (qmail 15244 invoked by alias); 18 Aug 2014 12:08:23 -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 15229 invoked by uid 89); 18 Aug 2014 12:08:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f45.google.com Received: from mail-pa0-f45.google.com (HELO mail-pa0-f45.google.com) (209.85.220.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 18 Aug 2014 12:08:15 +0000 Received: by mail-pa0-f45.google.com with SMTP id eu11so7690849pac.18 for ; Mon, 18 Aug 2014 05:08:11 -0700 (PDT) X-Received: by 10.67.1.195 with SMTP id bi3mr34827578pad.74.1408363690309; Mon, 18 Aug 2014 05:08:10 -0700 (PDT) Received: from msticlxl57.ims.intel.com (fmdmzpr01-ext.fm.intel.com. [192.55.54.36]) by mx.google.com with ESMTPSA id pu1sm16050967pbc.45.2014.08.18.05.08.08 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Aug 2014 05:08:09 -0700 (PDT) Date: Mon, 18 Aug 2014 16:07:48 +0400 From: Ilya Enkovich To: Jan Hubicka Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Avoid redundant indirect_info computation during inderct edge cloning Message-ID: <20140818120748.GA29976@msticlxl57.ims.intel.com> References: <20140814222333.GA34087@msticlxl57.ims.intel.com> <20140815210857.GD29797@atrey.karlin.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140815210857.GD29797@atrey.karlin.mff.cuni.cz> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes On 15 Aug 23:08, Jan Hubicka wrote: > > Hi, > > > > I get a segafult in decl_maybe_in_construction_p during function versioning. We have following steps in clone creation (e.g. as in create_version_clone_with_body): > > 1. Create function decl > > 2. Create clone of cgraph node > > 3. Copy function body > > After the first step there is no body attached to function and DECL_STRUCT_FUNCTION for new decl is NULL. It is initialized on the third step. But on the second step get_polymorphic_call_info may be called for new function; it calls decl_maybe_in_construction_p which assumes DECL_STRUCT_FUNCTION already exists. > > > > I firstly wanted to fix decl_maybe_in_construction_p but then realized cgraph_clone_edge copy indirect_info from the original edge anyway and therefore its computation is not required at all. > > > > Following patch removes redundant indirect_info computation. Bootstrapped and regtested on linux-x86_64. Does it look OK for trunk? > > OK, plase also add testcase from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61800 > > Thanks, > Honza Here is a version with testcase to be committed. Thanks, Ilya --- gcc/ 2014-08-18 Ilya Enkovich PR ipa/61800 * cgraph.h (cgraph_node::create_indirect_edge): Add compute_indirect_info param. * cgraph.c (cgraph_node::create_indirect_edge): Compute indirect_info only when it is required. * cgraphclones.c (cgraph_clone_edge): Do not recompute indirect_info fore cloned indirect edge. gcc/testsuite 2014-08-18 Ilya Enkovich * g++.dg/ipa/pr61800.C: New. diff --git a/gcc/cgraph.c b/gcc/cgraph.c index 370a96a..cb49cdc 100644 --- a/gcc/cgraph.c +++ b/gcc/cgraph.c @@ -942,7 +942,8 @@ cgraph_allocate_init_indirect_info (void) struct cgraph_edge * cgraph_node::create_indirect_edge (gimple call_stmt, int ecf_flags, - gcov_type count, int freq) + gcov_type count, int freq, + bool compute_indirect_info) { struct cgraph_edge *edge = cgraph_node::create_edge (this, NULL, call_stmt, count, freq, true); @@ -954,7 +955,8 @@ cgraph_node::create_indirect_edge (gimple call_stmt, int ecf_flags, edge->indirect_info->ecf_flags = ecf_flags; /* Record polymorphic call info. */ - if (call_stmt + if (compute_indirect_info + && call_stmt && (target = gimple_call_fn (call_stmt)) && virtual_method_call_p (target)) { diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 13c09af..2594ae5 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -915,7 +915,8 @@ public: statement destination is a formal parameter of the caller with index PARAM_INDEX. */ struct cgraph_edge *create_indirect_edge (gimple call_stmt, int ecf_flags, - gcov_type count, int freq); + gcov_type count, int freq, + bool compute_indirect_info = true); /* Like cgraph_create_edge walk the clone tree and update all clones sharing same function body. If clones already have edge for OLD_STMT; only diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c index c04b5c8..557f734 100644 --- a/gcc/cgraphclones.c +++ b/gcc/cgraphclones.c @@ -136,7 +136,7 @@ cgraph_clone_edge (struct cgraph_edge *e, struct cgraph_node *n, { new_edge = n->create_indirect_edge (call_stmt, e->indirect_info->ecf_flags, - count, freq); + count, freq, false); *new_edge->indirect_info = *e->indirect_info; } } diff --git a/gcc/testsuite/g++.dg/ipa/pr61800.C b/gcc/testsuite/g++.dg/ipa/pr61800.C new file mode 100644 index 0000000..b4da899 --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/pr61800.C @@ -0,0 +1,67 @@ +/* PR ipa/61800 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +#pragma GCC visibility push(hidden) +class A +{ +public: + unsigned long m_fn1 () const; +}; +class B; +class C +{ +public: + ; + virtual bool m_fn2 (void) = 0; +}; +class D +{ + virtual bool m_fn3 (const int &p1, B *p2) = 0; +}; +class F : public D +{ + bool m_fn3 (const int &p1, B *p2); + A mPredicates; +}; +class B +{ +}; +class G : public B +{ + virtual unsigned int m_fn4 () = 0; +}; +class H : public G +{ +public: + int txNodeSetContext_aContextNodeSet; + H (B *p1) {} + int + m_fn5 () + { + return mPosition < m_fn4 (); + } + unsigned int m_fn4 (); + unsigned int mPosition; +}; + +unsigned int a; +C *b; +bool +F::m_fn3 (const int &p1, B *p2) +{ + if (!b->m_fn2 ()) + return false; + unsigned int c = mPredicates.m_fn1 (); + for (1; 1 < c; ++a) + { + H d (p2); + while (d.m_fn5 ()) + { + do + { + } + while (0); + } + } +}