From patchwork Mon May 29 16:19:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 70260 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 790303856636 for ; Mon, 29 May 2023 16:19:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 22D773858C00 for ; Mon, 29 May 2023 16:19:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 22D773858C00 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3E1721F88E; Mon, 29 May 2023 16:19:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1685377180; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=mEaz7Vd9R6yEL4VO23aC54qzrbR0AUF8rb5qOG6INvA=; b=F1YPrCXNpyMKQyXd3h3uLus3tVkCDLmak5iZxC3GxJCEA6/BbZ+6TLuGpA85+IQ0qf9+k7 TbzW8S4asX3ZdmvyNT4O+LJYzQWMml6hNVgvrZ7jfuGEcsEHZ3kAAwXl2LomBaRAF6lgBv aN0EywJipkEql7KNrlAy7Ep4l6g+z7Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1685377180; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=mEaz7Vd9R6yEL4VO23aC54qzrbR0AUF8rb5qOG6INvA=; b=uC0bj/by0rwSJ23zdI+h5kLj5haJDKCinLbPq/4vZwlukj/NNOTuIi4Jj/N53LpUW+r0Ms bIeJSCjzaVtQqbAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 31F2F13466; Mon, 29 May 2023 16:19:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ZTcoDJzQdGQpUgAAMHmgww (envelope-from ); Mon, 29 May 2023 16:19:40 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH 1/2] ipa-cp: Avoid long linear searches through DECL_ARGUMENTS User-Agent: Notmuch/0.37 (https://notmuchmail.org) Emacs/28.2 (x86_64-suse-linux-gnu) Date: Mon, 29 May 2023 18:19:39 +0200 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, there have been concerns that linear searches through DECL_ARGUMENTS that are often necessary to compute the index of a particular PARM_DECL which is the key to results of IPA-CP can happen often enough to be a compile time issue, especially if we plug the results into value numbering, as I intend to do with a follow-up patch. This patch creates a hash map to do the look-up for all functions which have some information discovered by IPA-CP and which have 32 parameters or more. 32 is a hard-wired magical constant here to capture the trade-off between the memory allocation overhead and length of the linear search. I do not think it is worth making it a --param but if people think it appropriate, I can turn it into one. Bootstrapped, tested and LTO bootstrapped on x86_64-linux, both as-is and with themagical constant dropped to 4 so that the has lookup path is also well excercised. OK for master? Thanks, Martin gcc/ChangeLog: 2023-05-26 Martin Jambor * ipa-prop.h (struct ipcp_transformation): Rearrange members according to C++ class coding convention, add m_tree_to_idx, get_param_index and maybe_create_parm_idx_map. * ipa-cp.cc (ipcp_transformation::get_param_index): New function. (ipcp_transformation::maype_create_parm_idx_map): Likewise. * ipa-prop.cc (ipcp_get_parm_bits): Use get_param_index. (ipcp_update_bits): Accept TS as a parameter, assume it is not NULL. (ipcp_update_vr): Likewise. (ipcp_transform_function): Call, maybe_create_parm_idx_map of TS, bail out quickly if empty, pass it to ipcp_update_bits and ipcp_update_vr. --- gcc/ipa-cp.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++ gcc/ipa-prop.cc | 44 +++++++++++++++++++------------------------- gcc/ipa-prop.h | 33 +++++++++++++++++++++++++-------- 3 files changed, 89 insertions(+), 33 deletions(-) diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index 0f37bb5e336..9f8b07b2398 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -6761,3 +6761,48 @@ ipa_cp_cc_finalize (void) orig_overall_size = 0; ipcp_free_transformation_sum (); } + +/* Given PARAM which must be a parameter of function FNDECL described by THIS, + return its index in the DECL_ARGUMENTS chain, using a pre-computed hash map + if avialable (which is pre-computed only if there are many parameters). Can + return -1 if param is static chain not represented among DECL_ARGUMENTS. */ + +int +ipcp_transformation::get_param_index (const_tree fndecl, const_tree param) const +{ + gcc_assert (TREE_CODE (param) == PARM_DECL); + if (m_tree_to_idx) + { + unsigned *pr = m_tree_to_idx->get(param); + if (!pr) + { + gcc_assert (DECL_STATIC_CHAIN (fndecl)); + return -1; + } + return (int) *pr; + } + + unsigned index = 0; + for (tree p = DECL_ARGUMENTS (fndecl); p; p = DECL_CHAIN (p), index++) + if (p == param) + return (int) index; + + gcc_assert (DECL_STATIC_CHAIN (fndecl)); + return -1; +} + +/* Assuming THIS describes FNDECL and it has sufficiently many parameters to + justify the overhead, creat a has map from parameter trees to their + indices. */ +void +ipcp_transformation::maybe_create_parm_idx_map (tree fndecl) +{ + int c = count_formal_params (fndecl); + if (c < 32) + return; + + m_tree_to_idx = hash_map::create_ggc (c); + unsigned index = 0; + for (tree p = DECL_ARGUMENTS (fndecl); p; p = DECL_CHAIN (p), index++) + m_tree_to_idx->put (p, index); +} diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index ab6de9f10da..f0976e363f7 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -5776,16 +5776,9 @@ ipcp_get_parm_bits (tree parm, tree *value, widest_int *mask) if (!ts || vec_safe_length (ts->bits) == 0) return false; - int i = 0; - for (tree p = DECL_ARGUMENTS (current_function_decl); - p != parm; p = DECL_CHAIN (p)) - { - i++; - /* Ignore static chain. */ - if (!p) - return false; - } - + int i = ts->get_param_index (current_function_decl, parm); + if (i < 0) + return false; clone_info *cinfo = clone_info::get (cnode); if (cinfo && cinfo->param_adjustments) { @@ -5802,16 +5795,12 @@ ipcp_get_parm_bits (tree parm, tree *value, widest_int *mask) return true; } - -/* Update bits info of formal parameters as described in - ipcp_transformation. */ +/* Update bits info of formal parameters of NODE as described in TS. */ static void -ipcp_update_bits (struct cgraph_node *node) +ipcp_update_bits (struct cgraph_node *node, ipcp_transformation *ts) { - ipcp_transformation *ts = ipcp_get_transformation_summary (node); - - if (!ts || vec_safe_length (ts->bits) == 0) + if (vec_safe_is_empty (ts->bits)) return; vec &bits = *ts->bits; unsigned count = bits.length (); @@ -5913,14 +5902,12 @@ ipcp_update_bits (struct cgraph_node *node) } } -/* Update value range of formal parameters as described in - ipcp_transformation. */ +/* Update value range of formal parameters of NODE as described in TS. */ static void -ipcp_update_vr (struct cgraph_node *node) +ipcp_update_vr (struct cgraph_node *node, ipcp_transformation *ts) { - ipcp_transformation *ts = ipcp_get_transformation_summary (node); - if (!ts || vec_safe_length (ts->m_vr) == 0) + if (vec_safe_is_empty (ts->m_vr)) return; const vec &vr = *ts->m_vr; unsigned count = vr.length (); @@ -5996,10 +5983,17 @@ ipcp_transform_function (struct cgraph_node *node) fprintf (dump_file, "Modification phase of node %s\n", node->dump_name ()); - ipcp_update_bits (node); - ipcp_update_vr (node); ipcp_transformation *ts = ipcp_get_transformation_summary (node); - if (!ts || vec_safe_is_empty (ts->m_agg_values)) + if (!ts + || (vec_safe_is_empty (ts->m_agg_values) + && vec_safe_is_empty (ts->bits) + && vec_safe_is_empty (ts->m_vr))) + return 0; + + ts->maybe_create_parm_idx_map (cfun->decl); + ipcp_update_bits (node, ts); + ipcp_update_vr (node, ts); + if (vec_safe_is_empty (ts->m_agg_values)) return 0; param_count = count_formal_params (node->decl); if (param_count == 0) diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h index f306f8a377e..211b12ff6b3 100644 --- a/gcc/ipa-prop.h +++ b/gcc/ipa-prop.h @@ -925,16 +925,10 @@ ipa_is_param_used_by_polymorphic_call (class ipa_node_params *info, int i) struct GTY(()) ipcp_transformation { - /* Known aggregate values. */ - vec *m_agg_values; - /* Known bits information. */ - vec *bits; - /* Value range information. */ - vec *m_vr; - /* Default constructor. */ ipcp_transformation () - : m_agg_values (NULL), bits (NULL), m_vr (NULL) + : m_agg_values (nullptr), bits (nullptr), m_vr (nullptr), + m_tree_to_idx (nullptr) { } /* Default destructor. */ @@ -944,6 +938,29 @@ struct GTY(()) ipcp_transformation vec_free (bits); vec_free (m_vr); } + + /* Given PARAM which must be a parameter of function FNDECL described by + THIS, return its index in the DECL_ARGUMENTS chain, using a pre-computed + hash map if avialable (which is pre-computed only if there are many + parameters). Can return -1 if param is static chain not represented among + DECL_ARGUMENTS. */ + int get_param_index (const_tree fndecl, const_tree param) const; + + /* Assuming THIS describes FUNC and it has sufficiently many parameters to + justify the overhead, creat a has map from parameter trees to their + indices. */ + + void maybe_create_parm_idx_map (tree fndecl); + + /* Known aggregate values. */ + vec *m_agg_values; + /* Known bits information. */ + vec *bits; + /* Value range information. */ + vec *m_vr; + /* If there are many parameters, a hash map to speed-up look-ups of their + indices. */ + hash_map *m_tree_to_idx; }; inline From patchwork Mon May 29 16:19:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 70261 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77AE8385660B for ; Mon, 29 May 2023 16:20:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 97C133857359 for ; Mon, 29 May 2023 16:19:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97C133857359 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A9EBA1F88E; Mon, 29 May 2023 16:19:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1685377190; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=/Bhsv8LdSaMVFmK9WKNW6DJOI8tkOVzr1Hfjq/gZ/WI=; b=XDhYM9j61vrb5Lnw2Ns76yG69FTvpCoNZ6Y8p6AwoyLqHLVBU9XMXV9jPmbWW2gB9sDAOt 2NgmsLDHZ7engOwKatzMVpXDz3jK5yOjZ/pz8sxQ+vvJiL7MvacxNThQvnokEPD5cW71Gr x0gtDkAzjhDo3JDEavaGCB+q3IbVnnk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1685377190; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=/Bhsv8LdSaMVFmK9WKNW6DJOI8tkOVzr1Hfjq/gZ/WI=; b=L6E4VDR6btIBjIeXrjngrAwmge4/qfBFR6NDsjgnpe4MF479dwOOIsd/i6WBc1KEXn8xMv hEnVyYPeClCSY+Dg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9DE0D13466; Mon, 29 May 2023 16:19:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 7QOEJqbQdGQ1UgAAMHmgww (envelope-from ); Mon, 29 May 2023 16:19:50 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka , Richard Biener Subject: [PATCH 2/2] ipa-cp: Feed results of IPA-CP into value numbering User-Agent: Notmuch/0.37 (https://notmuchmail.org) Emacs/28.2 (x86_64-suse-linux-gnu) Date: Mon, 29 May 2023 18:19:50 +0200 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, PRs 68930 and 92497 show that when IPA-CP figures out constants in aggregate parameters or when passed by reference but the loads happen in an inlined function the information is lost. This happens even when the inlined function itself was known to have - or even cloned to have - such constants in incoming parameters because the transform phase of IPA passes is not run on them. See discussion in the bugs for reasons why. Honza suggested that we can plug the results of IPA-CP analysis into value numbering, so that FRE can figure out that some loads fetch known constants. This is what this patch does. This version of the patch uses the new way we represent aggregate constants discovered IPA-CP and so avoids linear scan to find them. Similarly, it depends on the previous patch which avoids potentially slow linear look ups of indices of PARM_DECLs when there are many of them. Bootstrapped, LTO-bootstrapped and LTO-profiledbootstrapped and tested on x86_64-linux. OK for trunk? Thanks, Martin gcc/ChangeLog: 2023-05-26 Martin Jambor PR ipa/68930 PR ipa/92497 * ipa-prop.h (ipcp_get_aggregate_const): Declare. * ipa-prop.cc (ipcp_get_aggregate_const): New function. (ipcp_transform_function): Do not deallocate transformation info. * tree-ssa-sccvn.cc: Include alloc-pool.h, symbol-summary.h and ipa-prop.h. (vn_reference_lookup_2): When hitting default-def vuse, query IPA-CP transformation info for any known constants. gcc/testsuite/ChangeLog: 2022-09-05 Martin Jambor PR ipa/68930 PR ipa/92497 * gcc.dg/ipa/pr92497-1.c: New test. * gcc.dg/ipa/pr92497-2.c: Likewise. --- gcc/ipa-prop.cc | 33 +++++++++++++++++++++---- gcc/ipa-prop.h | 3 +++ gcc/testsuite/gcc.dg/ipa/pr92497-1.c | 26 ++++++++++++++++++++ gcc/testsuite/gcc.dg/ipa/pr92497-2.c | 26 ++++++++++++++++++++ gcc/tree-ssa-sccvn.cc | 36 +++++++++++++++++++++++++++- 5 files changed, 118 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr92497-1.c create mode 100644 gcc/testsuite/gcc.dg/ipa/pr92497-2.c diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index f0976e363f7..fb2c0c0466b 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -5765,6 +5765,34 @@ ipcp_modif_dom_walker::before_dom_children (basic_block bb) return NULL; } +/* If IPA-CP discovered a constant in parameter PARM at OFFSET of a given SIZE + - whether passed by reference or not is given by BY_REF - return that + constant. Otherwise return NULL_TREE. */ + +tree +ipcp_get_aggregate_const (struct function *func, tree parm, bool by_ref, + HOST_WIDE_INT bit_offset, HOST_WIDE_INT bit_size) +{ + cgraph_node *node = cgraph_node::get (func->decl); + ipcp_transformation *ts = ipcp_get_transformation_summary (node); + + if (!ts || !ts->m_agg_values) + return NULL_TREE; + + int index = ts->get_param_index (func->decl, parm); + if (index < 0) + return NULL_TREE; + + ipa_argagg_value_list avl (ts); + unsigned unit_offset = bit_offset / BITS_PER_UNIT; + tree v = avl.get_value (index, unit_offset, by_ref); + if (!v + || maybe_ne (tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (v))), bit_size)) + return NULL_TREE; + + return v; +} + /* Return true if we have recorded VALUE and MASK about PARM. Set VALUE and MASk accordingly. */ @@ -6037,11 +6065,6 @@ ipcp_transform_function (struct cgraph_node *node) free_ipa_bb_info (bi); fbi.bb_infos.release (); - ipcp_transformation *s = ipcp_transformation_sum->get (node); - s->m_agg_values = NULL; - s->bits = NULL; - s->m_vr = NULL; - vec_free (descriptors); if (cfg_changed) delete_unreachable_blocks_update_callgraph (node, false); diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h index 211b12ff6b3..f68fa4a12dd 100644 --- a/gcc/ipa-prop.h +++ b/gcc/ipa-prop.h @@ -1221,6 +1221,9 @@ void ipa_dump_param (FILE *, class ipa_node_params *info, int i); void ipa_release_body_info (struct ipa_func_body_info *); tree ipa_get_callee_param_type (struct cgraph_edge *e, int i); bool ipcp_get_parm_bits (tree, tree *, widest_int *); +tree ipcp_get_aggregate_const (struct function *func, tree parm, bool by_ref, + HOST_WIDE_INT bit_offset, + HOST_WIDE_INT bit_size); bool unadjusted_ptr_and_unit_offset (tree op, tree *ret, poly_int64 *offset_ret); diff --git a/gcc/testsuite/gcc.dg/ipa/pr92497-1.c b/gcc/testsuite/gcc.dg/ipa/pr92497-1.c new file mode 100644 index 00000000000..eb8f2e75fd0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr92497-1.c @@ -0,0 +1,26 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fno-early-inlining" } */ + +struct a {int a;}; +static int //__attribute__ ((noinline)) +foo (struct a a) +{ + if (!__builtin_constant_p (a.a)) + __builtin_abort (); + return a.a; +} + +static int __attribute__ ((noinline)) +bar (struct a a) +{ + return foo(a); +} + +volatile int r; + +int main() +{ + struct a a={1}; + r = bar (a); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/ipa/pr92497-2.c b/gcc/testsuite/gcc.dg/ipa/pr92497-2.c new file mode 100644 index 00000000000..56e611df8f9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr92497-2.c @@ -0,0 +1,26 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fno-early-inlining -fno-ipa-sra" } */ + +struct a {int a;}; +static int //__attribute__ ((noinline)) +foo (struct a *a) +{ + if (!__builtin_constant_p (a->a)) + __builtin_abort (); + return a->a; +} + +static int __attribute__ ((noinline)) +bar (struct a *a) +{ + return foo(a); +} + +volatile int r; + +int main() +{ + struct a a={1}; + r = bar (&a); + return 0; +} diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 27c84e78fcf..33215b5fc82 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -74,6 +74,9 @@ along with GCC; see the file COPYING3. If not see #include "ipa-modref-tree.h" #include "ipa-modref.h" #include "tree-ssa-sccvn.h" +#include "alloc-pool.h" +#include "symbol-summary.h" +#include "ipa-prop.h" /* This algorithm is based on the SCC algorithm presented by Keith Cooper and L. Taylor Simpson in "SCC-Based Value numbering" @@ -2327,7 +2330,7 @@ vn_walk_cb_data::push_partial_def (pd_data pd, with the current VUSE and performs the expression lookup. */ static void * -vn_reference_lookup_2 (ao_ref *op ATTRIBUTE_UNUSED, tree vuse, void *data_) +vn_reference_lookup_2 (ao_ref *op, tree vuse, void *data_) { vn_walk_cb_data *data = (vn_walk_cb_data *)data_; vn_reference_t vr = data->vr; @@ -2361,6 +2364,37 @@ vn_reference_lookup_2 (ao_ref *op ATTRIBUTE_UNUSED, tree vuse, void *data_) return *slot; } + if (SSA_NAME_IS_DEFAULT_DEF (vuse)) + { + HOST_WIDE_INT offset, size; + tree v = NULL_TREE; + if (op->base && TREE_CODE (op->base) == PARM_DECL + && op->offset.is_constant (&offset) + && op->size.is_constant (&size) + && op->max_size_known_p () + && known_eq (op->size, op->max_size)) + v = ipcp_get_aggregate_const (cfun, op->base, false, offset, size); + else if (op->ref) + { + HOST_WIDE_INT offset, size; + bool reverse; + tree base = get_ref_base_and_extent_hwi (op->ref, &offset, + &size, &reverse); + if (base + && TREE_CODE (base) == MEM_REF + && integer_zerop (TREE_OPERAND (base, 1)) + && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME + && SSA_NAME_IS_DEFAULT_DEF (TREE_OPERAND (base, 0)) + && (TREE_CODE (SSA_NAME_VAR (TREE_OPERAND (base, 0))) + == PARM_DECL)) + v = ipcp_get_aggregate_const (cfun, + SSA_NAME_VAR (TREE_OPERAND (base, 0)), + true, offset, size); + } + if (v) + return data->finish (vr->set, vr->base_set, v); + } + return NULL; }