From patchwork Wed Aug 28 14:40:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 270536 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 24F6D2C0085 for ; Thu, 29 Aug 2013 00:40:24 +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:mime-version:content-type; q=dns; s=default; b=qUcyQTxsPOQe5m6a07B/go1UAyHmeL6j18mGm7KvP+mKZg4kSg /8FPc9u/T0anFTYSZTIfNfyM+6GIDPve4kB/8h3cS8Q4egAzwjQ2XfdAzMvKX76X qJY8QF16vurElz+bhE0/FQ4pV2irovIS7yRbAHuRbSNqpNPJ6x24c4/uI= 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:mime-version:content-type; s= default; bh=ffiW7NUZNWRkok2/VWsLJhLI75g=; b=ba+WUvCK7SE0oonfIQ8o E4cGjRgK633scPCUDDHE+fRm0VbfH2a08qbRJHFR1Ifavt+1ujs/2m8SkkYVOTqO j8GavXTxajnr1eyFzziGywj48daocFPq84AET7dHiSUMiIOBwtwuckPp2b+AwqH4 V3MND8ayoVfGbAJmXSDgkQY= Received: (qmail 13013 invoked by alias); 28 Aug 2013 14:40:16 -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 13002 invoked by uid 89); 28 Aug 2013 14:40:16 -0000 Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 28 Aug 2013 14:40:16 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL, BAYES_00, RDNS_NONE autolearn=no version=3.3.2 X-HELO: mx2.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id EDA52A51CB; Wed, 28 Aug 2013 16:40:12 +0200 (CEST) Date: Wed, 28 Aug 2013 16:40:12 +0200 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH, PR 58106] Make ipa_edge_duplication_hook cope with recursive inlining Message-ID: <20130828144012.GD3564@virgil.suse> Mail-Followup-To: GCC Patches , Jan Hubicka MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Hi, PR 58106 happens because the reference description duplication code cannot deal with existence of master_nodes of recursive inlining. It did not put rdescs pertaining to edges going out of these nodes to the lookup linked list (because they do not seem to be inlined into anything) but the remapping of "not-this-edge" rdesc pointers looked for them there - and also need to consider that the rdesc edge caller is not inlined into anything to find them. So this patch puts all rdesc clones to the lookup linked list and updates the search criteria and fixes the issue. I have looked at how often we duplicate rdescs and we do it very rarely, 26 times in whole SPEC 2006 at -Ofast for example. This is expected because we create them only constant jump functions with addresses of functions. In order to build a long lookup list which could potentially be a compile time hog, such an edge would need to be inlined and we'd have to inline its caller massively, the length grows linearly with the number of inline clones and the number of searches as well. Bootstrapped and tested on x86_64-linux, OK for trunk? Thanks, Martin 2013-08-27 Martin Jambor PR ipa/58106 * ipa-prop.c (ipa_edge_duplication_hook): Always put new rdesc to the linked list. When finding the correct duplicate, also consider also the caller in additon to its inlined_to node. testsuite/ * gcc.dg/ipa/pr58106.c: New test. Index: src/gcc/ipa-prop.c =================================================================== --- src.orig/gcc/ipa-prop.c +++ src/gcc/ipa-prop.c @@ -2964,11 +2964,8 @@ ipa_edge_duplication_hook (struct cgraph = (struct ipa_cst_ref_desc *) pool_alloc (ipa_refdesc_pool); dst_rdesc->cs = dst; dst_rdesc->refcount = src_rdesc->refcount; - if (dst->caller->global.inlined_to) - { - dst_rdesc->next_duplicate = src_rdesc->next_duplicate; - src_rdesc->next_duplicate = dst_rdesc; - } + dst_rdesc->next_duplicate = src_rdesc->next_duplicate; + src_rdesc->next_duplicate = dst_rdesc; dst_jf->value.constant.rdesc = dst_rdesc; } else @@ -2983,9 +2980,14 @@ ipa_edge_duplication_hook (struct cgraph for (dst_rdesc = src_rdesc->next_duplicate; dst_rdesc; dst_rdesc = dst_rdesc->next_duplicate) - if (dst_rdesc->cs->caller->global.inlined_to - == dst->caller->global.inlined_to) - break; + { + struct cgraph_node *top; + top = dst_rdesc->cs->caller->global.inlined_to + ? dst_rdesc->cs->caller->global.inlined_to + : dst_rdesc->cs->caller; + if (dst->caller->global.inlined_to == top) + break; + } gcc_assert (dst_rdesc); dst_jf->value.constant.rdesc = dst_rdesc; } Index: src/gcc/testsuite/gcc.dg/ipa/pr58106.c =================================================================== --- /dev/null +++ src/gcc/testsuite/gcc.dg/ipa/pr58106.c @@ -0,0 +1,50 @@ +/* PR 58106 testcase. Verify that redsc chain creating and lookup works with + recursive inlining and master clone creation. */ +/* { dg-do compile } */ +/* { dg-options "-O3" } */ + +typedef struct rtx_def *rtx; +enum rtx_code { + LAST_AND_UNUSED_RTX_CODE}; +extern const char * const rtx_format[((int) LAST_AND_UNUSED_RTX_CODE)]; +struct rtx_def { + enum rtx_code code; +}; +typedef int (*rtx_function) (rtx *, void *); +extern int for_each_rtx (rtx *, rtx_function, void *); +int +replace_label (rtx *x, void *data) +{ + rtx l = *x; + if (l == (rtx) 0) + { + { + rtx new_c, new_l; + for_each_rtx (&new_c, replace_label, data); + } + } +} +static int +for_each_rtx_1 (rtx exp, int n, rtx_function f, void *data) +{ + int result, i, j; + const char *format = (rtx_format[(int) (((enum rtx_code) (exp)->code))]); + rtx *x; + for (; format[n] != '\0'; n++) + { + switch (format[n]) + { + case 'e': + result = (*f) (x, data); + { + result = for_each_rtx_1 (*x, i, f, data); + } + } + } +} +int +for_each_rtx (rtx *x, rtx_function f, void *data) +{ + int i; + return for_each_rtx_1 (*x, i, f, data); +}