From patchwork Thu Oct 5 12:06:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1843881 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=SIeZ0i0q; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=9NAs8FGj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S1VyD2tB8z1yqD for ; Thu, 5 Oct 2023 23:20:36 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2ABF33861840 for ; Thu, 5 Oct 2023 12:20:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id B3B613858C5F for ; Thu, 5 Oct 2023 12:20:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B3B613858C5F 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-out1.suse.de (Postfix) with ESMTPS id E301721869 for ; Thu, 5 Oct 2023 12:20:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1696508420; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: resent-to:resent-from:resent-message-id; bh=WWX3UzgDEfzaGYu5c+R+Ay/HKyOK8KUGs5KECR/0G3c=; b=SIeZ0i0qWFAQRVJYaVPGKNsfslySn+uANeCyMRq/dMAWwXYEBd4h9EkGDa3LXnw1sBl8Ld JvVTH/+p5zcu5UV8U05jU2iQChl8VGec6VGNNdp8vuy3G/D4LsXater1P6v2+jzZIgrbRT t54epjIWMtre39x7sEQ6n7od7tILegs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1696508420; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: resent-to:resent-from:resent-message-id; bh=WWX3UzgDEfzaGYu5c+R+Ay/HKyOK8KUGs5KECR/0G3c=; b=9NAs8FGjAAMbmqswOPSePM2YbO72gdxp6Qd+e9Ij6XTSBEdOGdCfabQ10vuuRnF/qvFjMH Jq97fPXm6wF1HPCQ== 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 D392C139C2 for ; Thu, 5 Oct 2023 12:20:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id S61dMgSqHmUjZQAAMHmgww (envelope-from ) for ; Thu, 05 Oct 2023 12:20:20 +0000 Resent-From: Martin Jambor Resent-Date: Thu, 5 Oct 2023 14:20:20 +0200 Resent-Message-ID: Resent-To: gcc-patches@gcc.gnu.org Message-ID: From: Martin Jambor Date: Thu, 5 Oct 2023 14:06:47 +0200 Subject: [PATCH 1/3] ipa-cp: Templatize filtering of m_agg_values To: GCC Patches Cc: Jan Hubicka X-Spam-Status: No, score=-11.0 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 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org PR 111157 points to another place where IPA-CP collected aggregate compile-time constants need to be filtered, in addition to the one place that already does this in ipa-sra. In order to re-use code, this patch turns the common bit into a template. The functionality is still covered by testcase gcc.dg/ipa/pr108959.c. gcc/ChangeLog: 2023-09-13 Martin Jambor PR ipa/111157 * ipa-prop.h (ipcp_transformation): New member function template remove_argaggs_if. * ipa-sra.cc (zap_useless_ipcp_results): Use remove_argaggs_if to filter aggreagate constants. --- gcc/ipa-prop.h | 33 +++++++++++++++++++++++++++++++++ gcc/ipa-sra.cc | 33 ++++----------------------------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h index 7e033d2a7b8..815855006e8 100644 --- a/gcc/ipa-prop.h +++ b/gcc/ipa-prop.h @@ -966,6 +966,39 @@ struct GTY(()) ipcp_transformation void maybe_create_parm_idx_map (tree fndecl); + /* Remove all elements in m_agg_values on which PREDICATE returns true. */ + + template + void remove_argaggs_if (pred_function &&predicate) + { + unsigned ts_len = vec_safe_length (m_agg_values); + if (ts_len == 0) + return; + + bool removed_item = false; + unsigned dst_index = 0; + + for (unsigned i = 0; i < ts_len; i++) + { + ipa_argagg_value *v = &(*m_agg_values)[i]; + if (!predicate (*v)) + { + if (removed_item) + (*m_agg_values)[dst_index] = *v; + dst_index++; + } + else + removed_item = true; + } + if (dst_index == 0) + { + ggc_free (m_agg_values); + m_agg_values = NULL; + } + else if (removed_item) + m_agg_values->truncate (dst_index); + } + /* Known aggregate values. */ vec *m_agg_values; /* Known bits information. */ diff --git a/gcc/ipa-sra.cc b/gcc/ipa-sra.cc index edba364f56e..1551b694679 100644 --- a/gcc/ipa-sra.cc +++ b/gcc/ipa-sra.cc @@ -4047,35 +4047,10 @@ mark_callers_calls_comdat_local (struct cgraph_node *node, void *) static void zap_useless_ipcp_results (const isra_func_summary *ifs, ipcp_transformation *ts) { - unsigned ts_len = vec_safe_length (ts->m_agg_values); - - if (ts_len == 0) - return; - - bool removed_item = false; - unsigned dst_index = 0; - - for (unsigned i = 0; i < ts_len; i++) - { - ipa_argagg_value *v = &(*ts->m_agg_values)[i]; - const isra_param_desc *desc = &(*ifs->m_parameters)[v->index]; - - if (!desc->locally_unused) - { - if (removed_item) - (*ts->m_agg_values)[dst_index] = *v; - dst_index++; - } - else - removed_item = true; - } - if (dst_index == 0) - { - ggc_free (ts->m_agg_values); - ts->m_agg_values = NULL; - } - else if (removed_item) - ts->m_agg_values->truncate (dst_index); + ts->remove_argaggs_if ([ifs](const ipa_argagg_value &v) + { + return (*ifs->m_parameters)[v.index].locally_unused; + }); bool useful_bits = false; unsigned count = vec_safe_length (ts->bits);