From patchwork Sun Mar 1 14:37:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 444764 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 387A0140271 for ; Mon, 2 Mar 2015 01:37:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=IMBbhEKl; dkim-adsp=none (unprotected policy); 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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=ApwUPaIqF1E6zvPNa XSEUDJhG2bwZQH+CcUa7Ft/whyGJiHlabEiQU5gu0mlpK/+RZILOaIrk3tZlRWba BMczL+p5wNRUkRAD1cAdoEPajmJkZ4pvawrnonvkka4FPHA9bbMHGHoQXOWjqNGc oyw8GajfbWrNhxiO4/i0g/VJco= 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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=LHqmGY5n7uzU9vPJg0aRS65 v+Ho=; b=IMBbhEKlo/l1x3DVhIQANQ98sdXb6v4Uu2GLjE6o4diewFMCv2HiFvT +8J0zwFaf7dpNwhGW7ptR8UTmsrtb4EAzoCUgIVFP0gLGLF2LqlfvbXCQj9yyud3 VBw9mojX/nRy+GSxfSxwGPLBULw7GUPc+GHxfleZCOuEd5vRuw4o= Received: (qmail 90134 invoked by alias); 1 Mar 2015 14:37:48 -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 90114 invoked by uid 89); 1 Mar 2015 14:37:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: mx2.suse.de Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Sun, 01 Mar 2015 14:37:46 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9C7D5AC76; Sun, 1 Mar 2015 14:37:42 +0000 (UTC) Message-ID: <54F32435.9000104@suse.cz> Date: Sun, 01 Mar 2015 15:37:41 +0100 From: =?windows-1252?Q?Martin_Li=9Aka?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Jan Hubicka CC: "gcc- >> GCC Patches" Subject: Re: [PATCH] Fix for PR ipa/65245 References: <54F23BAD.2010304@suse.cz> <20150228224114.GC20437@kam.mff.cuni.cz> In-Reply-To: <20150228224114.GC20437@kam.mff.cuni.cz> X-IsSubscribed: yes On 02/28/2015 11:41 PM, Jan Hubicka wrote: >> Hello. >> >> Following patch skips all variable aliases as potential merge candidates. Tested on x86_64-linux. >> >> Ready for trunk? >> Thanks, >> Martin > >> >From fbde2e98f98a71105d18cf3e91e8032d0c657139 Mon Sep 17 00:00:00 2001 >> From: mliska >> Date: Fri, 27 Feb 2015 22:42:49 +0100 >> Subject: [PATCH 2/4] ICF: Do not consider variable aliases for merge >> operation. >> >> gcc/ChangeLog: >> >> 2015-02-28 Martin Liska >> Jan Hubicka >> >> PR ipa/65245 >> * ipa-icf.c (sem_function::parse): Do not consider aliases. >> (sem_variable::parse): Likewise. >> (sem_item_optimizer::build_graph): Consider ultimate aliases >> for references. > > OK, can you please add a testcase checking that two functions get merged even > if each of them referrs different alias of an equvalent symbols? Hi. Updated version of patch adds new testcase. Ready for trunk? Thanks, Martin > > Honza >> --- >> gcc/ipa-icf.c | 11 ++++++++--- >> 1 file changed, 8 insertions(+), 3 deletions(-) >> >> diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c >> index 92133fc..864a5d0 100644 >> --- a/gcc/ipa-icf.c >> +++ b/gcc/ipa-icf.c >> @@ -1095,7 +1095,7 @@ sem_function::parse (cgraph_node *node, bitmap_obstack *stack) >> tree fndecl = node->decl; >> function *func = DECL_STRUCT_FUNCTION (fndecl); >> >> - /* TODO: add support for thunks and aliases. */ >> + /* TODO: add support for thunks. */ >> >> if (!func || !node->has_gimple_body_p ()) >> return NULL; >> @@ -1407,6 +1407,9 @@ sem_variable::parse (varpool_node *node, bitmap_obstack *stack) >> { >> tree decl = node->decl; >> >> + if (node->alias) >> + return NULL; >> + >> bool readonly = TYPE_P (decl) ? TYPE_READONLY (decl) : TREE_READONLY (decl); >> if (!readonly) >> return NULL; >> @@ -2057,7 +2060,8 @@ sem_item_optimizer::build_graph (void) >> cgraph_edge *e = cnode->callees; >> while (e) >> { >> - sem_item **slot = m_symtab_node_map.get (e->callee); >> + sem_item **slot = m_symtab_node_map.get >> + (e->callee->ultimate_alias_target ()); >> if (slot) >> item->add_reference (*slot); >> >> @@ -2068,7 +2072,8 @@ sem_item_optimizer::build_graph (void) >> ipa_ref *ref = NULL; >> for (unsigned i = 0; item->node->iterate_reference (i, ref); i++) >> { >> - sem_item **slot = m_symtab_node_map.get (ref->referred); >> + sem_item **slot = m_symtab_node_map.get >> + (ref->referred->ultimate_alias_target ()); >> if (slot) >> item->add_reference (*slot); >> } >> -- >> 2.1.2 >> > From 7cedbe5e3736b9eb7b2fab1b931a7bc9ed269f37 Mon Sep 17 00:00:00 2001 From: mliska Date: Fri, 27 Feb 2015 22:42:49 +0100 Subject: [PATCH 2/4] ICF: Do not consider variable aliases for merge operation. gcc/ChangeLog: 2015-02-28 Martin Liska Jan Hubicka * ipa-icf-gimple.c (func_checker::compare_function_decl): Consider ultimate alias as targets. * ipa-icf.c (sem_function::parse): Do not consider aliases. (sem_function::compare_cgraph_references): Consider ultimate alias as targets. (sem_variable::parse): Likewise. (sem_item_optimizer::build_graph): Consider ultimate aliases for references. gcc/testsuite/ChangeLog: 2015-02-28 Martin Liska Jan Hubicka * gcc.dg/ipa/ipa-icf-34.c: New test. * gcc.target/i386/stackalign/longlong-2.c: Omit ICF. --- gcc/ipa-icf-gimple.c | 4 ++-- gcc/ipa-icf.c | 14 +++++++++++--- gcc/testsuite/gcc.dg/ipa/ipa-icf-34.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/ipa-icf-34.c diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c index cbeb795..8008e86 100644 --- a/gcc/ipa-icf-gimple.c +++ b/gcc/ipa-icf-gimple.c @@ -543,8 +543,8 @@ func_checker::compare_function_decl (tree t1, tree t2) if (t1 == t2) return true; - symtab_node *n1 = symtab_node::get (t1); - symtab_node *n2 = symtab_node::get (t2); + symtab_node *n1 = symtab_node::get (t1)->ultimate_alias_target (); + symtab_node *n2 = symtab_node::get (t2)->ultimate_alias_target (); if (m_ignored_source_nodes != NULL && m_ignored_target_nodes != NULL) { diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c index 92133fc..b95db0d 100644 --- a/gcc/ipa-icf.c +++ b/gcc/ipa-icf.c @@ -342,6 +342,9 @@ sem_function::compare_cgraph_references (hash_map &ignored_nodes, symtab_node *n1, symtab_node *n2) { + n1 = n1->ultimate_alias_target (); + n2 = n2->ultimate_alias_target (); + if (n1 == n2 || (ignored_nodes.get (n1) && ignored_nodes.get (n2))) return true; @@ -1095,7 +1098,7 @@ sem_function::parse (cgraph_node *node, bitmap_obstack *stack) tree fndecl = node->decl; function *func = DECL_STRUCT_FUNCTION (fndecl); - /* TODO: add support for thunks and aliases. */ + /* TODO: add support for thunks. */ if (!func || !node->has_gimple_body_p ()) return NULL; @@ -1407,6 +1410,9 @@ sem_variable::parse (varpool_node *node, bitmap_obstack *stack) { tree decl = node->decl; + if (node->alias) + return NULL; + bool readonly = TYPE_P (decl) ? TYPE_READONLY (decl) : TREE_READONLY (decl); if (!readonly) return NULL; @@ -2057,7 +2063,8 @@ sem_item_optimizer::build_graph (void) cgraph_edge *e = cnode->callees; while (e) { - sem_item **slot = m_symtab_node_map.get (e->callee); + sem_item **slot = m_symtab_node_map.get + (e->callee->ultimate_alias_target ()); if (slot) item->add_reference (*slot); @@ -2068,7 +2075,8 @@ sem_item_optimizer::build_graph (void) ipa_ref *ref = NULL; for (unsigned i = 0; item->node->iterate_reference (i, ref); i++) { - sem_item **slot = m_symtab_node_map.get (ref->referred); + sem_item **slot = m_symtab_node_map.get + (ref->referred->ultimate_alias_target ()); if (slot) item->add_reference (*slot); } diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-icf-34.c b/gcc/testsuite/gcc.dg/ipa/ipa-icf-34.c new file mode 100644 index 0000000..698044a --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipa-icf-34.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O0 -fipa-icf -fdump-ipa-icf" } */ + +static int do_work(void) +{ + return 0; +} + +static int foo() __attribute__((alias("do_work"))); +static int bar() __attribute__((alias("do_work"))); + +static int a() +{ + return foo(); +} + +static int b() +{ + return bar(); +} + +int main() +{ + return a() + b(); +} + +/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */ +/* { dg-final { cleanup-ipa-dump "icf" } } */ diff --git a/gcc/testsuite/gcc.target/i386/stackalign/longlong-2.c b/gcc/testsuite/gcc.target/i386/stackalign/longlong-2.c index 6ea83f9..d52b9d1 100644 --- a/gcc/testsuite/gcc.target/i386/stackalign/longlong-2.c +++ b/gcc/testsuite/gcc.target/i386/stackalign/longlong-2.c @@ -1,6 +1,6 @@ /* { dg-do compile { target { ! *-*-darwin* } } } */ /* { dg-require-effective-target ia32 } */ -/* { dg-options "-O2 -mpreferred-stack-boundary=2" } */ +/* { dg-options "-O2 -mpreferred-stack-boundary=2 -fno-ipa-icf" } */ /* { dg-final { scan-assembler-times "and\[lq\]?\[^\\n\]*-8,\[^\\n\]*sp" 2 } } */ /* { dg-final { scan-assembler-times "and\[lq\]?\[^\\n\]*-16,\[^\\n\]*sp" 2 } } */ -- 2.1.2