From patchwork Thu May 12 16:09:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 621661 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 3r5HxQ02Cmz9sD5 for ; Fri, 13 May 2016 02:09:29 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Pxh234oM; 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:message-id:mime-version:content-type; q=dns; s=default; b=eGShhze0LYBoMDnpvFULpaXXS0O0fJexTCgE8osFjlIGMGgxc6 AfnHkYG2AgLcnOJRrsX2MKoZB9EyacxNhOBuPm10rGUQoODkTuZO8eswbmVjiEL7 IcbNfjh4CKuhM8dnQTHFr5QDtNk8lOToW6bxurpf2SyH2juGYrWcvzqr8= 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=3wughr5/a0OXl0hzaU6+ZmRIPnc=; b=Pxh234oMByAvNtFTfFdb juF2rg8gUrovT+GxCfT7aEJlWFjXhHWTrjitvGViGhJRqLpylVv0EFWo74a4P2Ki rRg63QONsa18s+qB3vtMrkncrmyh5YmGtjTZGyvpXoqkK83RQcrPSRdYckjtkm9u GzIenfKe7DBFhdGxjbZM28I= Received: (qmail 47999 invoked by alias); 12 May 2016 16:09:21 -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 47977 invoked by uid 89); 12 May 2016 16:09:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=fa 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 (CAMELLIA256-SHA encrypted) ESMTPS; Thu, 12 May 2016 16:09:10 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B82E9AC95 for ; Thu, 12 May 2016 16:09:06 +0000 (UTC) Date: Thu, 12 May 2016 18:09:06 +0200 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH 3/3] Allow constant global VAR_DECLs in constant jump functions Message-ID: <20160512160906.GK5580@virgil.suse.cz> Mail-Followup-To: GCC Patches , Jan Hubicka MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.6.0 (2016-04-01) X-IsSubscribed: yes Hi, the following patch adds the final step necessary to perform optimization requested in PR 69708, i.e do indirect inlining of a function passed by value in a structure. It allows jump functions to be aggregate global constant VAR_DECLs, which enables the constructor-walking code introduced in the first patch of the series to deduce aggregate contents from it. IPA-CP expects jump-functions to be scalars, and they indeed need be for processing arithmetic jump-functions, but this patch allows any tree for the simple ones. Bootstrapped, lto-bootstrapped tested on x86_64. OK for trunk? Thanks, Martin 2016-05-11 Martin Jambor PR ipa/69708 * ipa-cp.c (ipa_get_jf_pass_through_result): Allow non-ip constant input for NOP_EXPR pass-through functions. * ipa-prop.c (ipa_compute_jump_functions_for_edge): Allow aggregate global constant VAR_DECLs in constant jump functions. testsuite/ * gcc.dg/ipa/iinline-cstagg-2.c: New test. * gcc.dg/ipa/ipcp-cstagg-5.c: Likewise. * gcc.dg/ipa/ipcp-cstagg-6.c: Likewise. * gcc.dg/ipa/ipcp-cstagg-7.c: Likewise. --- gcc/ipa-cp.c | 3 +- gcc/ipa-prop.c | 5 ++- gcc/testsuite/gcc.dg/ipa/iinline-cstagg-2.c | 30 +++++++++++++ gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-5.c | 37 ++++++++++++++++ gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-6.c | 43 +++++++++++++++++++ gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-7.c | 65 +++++++++++++++++++++++++++++ 6 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/iinline-cstagg-2.c create mode 100644 gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-5.c create mode 100644 gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-6.c create mode 100644 gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-7.c diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c index 2183da0..8caa973 100644 --- a/gcc/ipa-cp.c +++ b/gcc/ipa-cp.c @@ -1026,9 +1026,10 @@ ipa_get_jf_pass_through_result (struct ipa_jump_func *jfunc, tree input) { tree restype, res; - gcc_checking_assert (is_gimple_ip_invariant (input)); if (ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR) return input; + if (!is_gimple_ip_invariant (input)) + return NULL_TREE; if (TREE_CODE_CLASS (ipa_get_jf_pass_through_operation (jfunc)) == tcc_comparison) diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index 7d869ed..ead8267 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -1674,7 +1674,10 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, else gcc_assert (!jfunc->alignment.known); - if (is_gimple_ip_invariant (arg)) + if (is_gimple_ip_invariant (arg) + || (TREE_CODE (arg) == VAR_DECL + && is_global_var (arg) + && TREE_READONLY (arg))) ipa_set_jf_constant (jfunc, arg, cs); else if (!is_gimple_reg_type (TREE_TYPE (arg)) && TREE_CODE (arg) == PARM_DECL) diff --git a/gcc/testsuite/gcc.dg/ipa/iinline-cstagg-2.c b/gcc/testsuite/gcc.dg/ipa/iinline-cstagg-2.c new file mode 100644 index 0000000..546db87 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/iinline-cstagg-2.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-ipa-inline-details -fno-early-inlining -fno-ipa-sra -fno-ipa-cp" } */ + +typedef struct S +{ + int add_offset; + int (*call)(int); +} S; + +static int +bar (const S f, int x) +{ + x = f.call (x); + return x; +} + +static int +thisisthetarget (int x) +{ + return x * x; +} + +int +outerfunction (int x) +{ + return bar ((S){16, thisisthetarget}, x); +} + + +/* { dg-final { scan-ipa-dump "thisisthetarget\[^\\n\]*inline copy in outerfunction" "inline" } } */ diff --git a/gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-5.c b/gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-5.c new file mode 100644 index 0000000..56d544e --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-5.c @@ -0,0 +1,37 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-ipa-cp-details" } */ + +typedef struct S +{ + int add_offset; + int (*call)(int); +} S; + +extern const S *es; + +static int __attribute__((noinline)) +foo (const S f, int x) +{ + es = &f; /* This disables IPA-SRA */ + x = f.call(x+f.add_offset); + x = f.call(x); + x = f.call(x); + return x; +} + +static int +sq (int x) +{ + return x * x; +} + +static const S s = {16, sq}; + +int +h (int x) +{ + return foo (s, x); +} + +/* { dg-final { scan-ipa-dump "Discovered an indirect call to a known target" "cp" } } */ +/* { dg-final { scan-ipa-dump-times "Discovered an indirect call to a known target" 3 "cp" } } */ diff --git a/gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-6.c b/gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-6.c new file mode 100644 index 0000000..7891082 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-6.c @@ -0,0 +1,43 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-ipa-cp-details" } */ + +typedef struct S +{ + int add_offset; + int (*call)(int); +} S; + +extern const S *es, *fs; + +static int __attribute__((noinline)) +foo (const S f, int x) +{ + es = &f; /* This disables IPA-SRA */ + x = f.call(x+f.add_offset); + x = f.call(x); + x = f.call(x); + return x; +} + +static int __attribute__((noinline)) +bar (const S f, int x) +{ + fs = &f; /* This disables IPA-SRA */ + return foo (f, x); +} + +static int +sq (int x) +{ + return x * x; +} + +static const S s = {16, sq}; + +int +h (int x) +{ + return bar (s, x); +} + +/* { dg-final { scan-ipa-dump-times "Discovered an indirect call to a known target" 3 "cp" } } */ diff --git a/gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-7.c b/gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-7.c new file mode 100644 index 0000000..6af8bda --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-7.c @@ -0,0 +1,65 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-ipa-cp-details" } */ + +#define N 4 + +typedef int (* const A[N])(int); + +typedef struct S +{ + int add_offset; + A a; +} S; + +extern const S *gs, *hs; + +static int __attribute__((noinline)) +foo (const S f, int x) +{ + gs = &f; + x = f.a[2](x); + x = f.a[2](x); + x = f.a[2](x); + return x; +} + +static int __attribute__((noinline)) +bar (const S f, int x) +{ + hs = &f; + return foo (f, x); +} + +static int +zero (int x) +{ + return 0; +} + +static int +addone (int x) +{ + return x + 1; +} + +static int +sq (int x) +{ + return x * x; +} + +static int +cube (int x) +{ + return x * x * x; +} + +static const S s = {64, {zero, addone, sq, cube}}; + +int +h (int x) +{ + return bar (s, x); +} + +/* { dg-final { scan-ipa-dump-times "Discovered an indirect call to a known target" 3 "cp" } } */