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: 1843882 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=KLP3uMf/; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=0YhOP8tf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4S1VyF3X2qz20ck for ; Thu, 5 Oct 2023 23:20:37 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0DFC93875432 for ; Thu, 5 Oct 2023 12:20:35 +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 A7EE6385B537 for ; Thu, 5 Oct 2023 12:20:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A7EE6385B537 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 D36FE21871 for ; Thu, 5 Oct 2023 12:20:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1696508421; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: resent-to:resent-from:resent-message-id:in-reply-to:in-reply-to: references:references; bh=ofEtN8JYdiu8BiOStexomuCh0pGyX5U91VF9GO0UZPY=; b=KLP3uMf/rav3hFefY1HvIYYAWynjZesStxVGc8H9ROS7hckjfjN79XusWOeGkeUFiyCOTs Z3/FzHViis6yW2PciOTFQAAA5XuC7qeD5c6dQLbuMjzR6TdT2XZ/4z/6MPArz2h7f+JWry LGgAmu2C5V+IitPMM1PCuTKhOl/NlNY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1696508421; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: resent-to:resent-from:resent-message-id:in-reply-to:in-reply-to: references:references; bh=ofEtN8JYdiu8BiOStexomuCh0pGyX5U91VF9GO0UZPY=; b=0YhOP8tfh0gY7BsMlyyv0/qn07dICOFWBhFkYy0Jlrs6mCISl779Iv71nSJ1gMj1senbMC x6h4OoRP5+b+wGBQ== 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 C86FC139C2 for ; Thu, 5 Oct 2023 12:20:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ApfrMAWqHmUoZQAAMHmgww (envelope-from ) for ; Thu, 05 Oct 2023 12:20:21 +0000 Resent-From: Martin Jambor Resent-Date: Thu, 5 Oct 2023 14:20:21 +0200 Resent-Message-ID: Resent-To: gcc-patches@gcc.gnu.org Message-ID: In-Reply-To: References: From: Martin Jambor Date: Thu, 5 Oct 2023 14:06:47 +0200 Subject: [PATCH 3/3] ipa: Limit pruning of IPA-CP aggregate constants if there are loads 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 This patch makes the previous one less conservative by looking whether there are known ipa-modref loads from areas covered by the IPA-CP aggregate constant entry in question. Because ipa-modref relies on alias information which IPA-CP does not have (yet), the test is much more crude and only reports overlapping accesses with known offsets and max_size. I was not able to put together a testcase which would fail without this patch however. It basically needs to be a combination of testcases for PR 92497 (so that IPA-CP transformation phase is not enough), PR 111157 (to get a load) and PR 103669 (to get a clobber/kill) in a way that ipa-modref can still track things. Therefore I am not sure if we actually want this patch. gcc/ChangeLog: 2023-10-04 Martin Jambor * ipa-modref.cc (ipcp_argagg_and_access_must_overlap_p): New function. (ipcp_argagg_and_modref_tree_must_overlap_p): Likewise. (update_signature): Use ipcp_argagg_and_modref_tree_must_overlap_p. Combined third step --- gcc/ipa-modref.cc | 65 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/gcc/ipa-modref.cc b/gcc/ipa-modref.cc index a8fcf159259..d2bfca3445d 100644 --- a/gcc/ipa-modref.cc +++ b/gcc/ipa-modref.cc @@ -4090,6 +4090,64 @@ ipcp_argagg_and_kill_overlap_p (const ipa_argagg_value &v, return false; } +/* Return true if V overlaps with ACCESS_NODE. When in doubt, return + false. */ + +static bool +ipcp_argagg_and_access_must_overlap_p (const ipa_argagg_value &v, + const modref_access_node &access_node) +{ + if (access_node.parm_index == MODREF_GLOBAL_MEMORY_PARM + || access_node.parm_index == MODREF_UNKNOWN_PARM + || access_node.parm_index == MODREF_GLOBAL_MEMORY_PARM) + return false; + + if (access_node.parm_index == v.index) + { + if (!access_node.parm_offset_known) + return false; + + poly_int64 repl_size; + bool ok = poly_int_tree_p (TYPE_SIZE (TREE_TYPE (v.value)), + &repl_size); + gcc_assert (ok); + poly_int64 repl_offset (v.unit_offset); + repl_offset <<= LOG2_BITS_PER_UNIT; + poly_int64 combined_offset + = (access_node.parm_offset << LOG2_BITS_PER_UNIT) + access_node.offset; + if (ranges_maybe_overlap_p (repl_offset, repl_size, + combined_offset, access_node.max_size)) + return true; + } + return false; +} + +/* Return true if MT contains an access that certainly overlaps with V even + when we cannot evaluate alias references. When in doubt, return false. */ + +template +static bool +ipcp_argagg_and_modref_tree_must_overlap_p (const ipa_argagg_value &v, + const modref_tree &mt) +{ + for (auto base_node : mt.bases) + { + if (base_node->every_ref) + return false; + for (auto ref_node : base_node->refs) + { + if (ref_node->every_access) + return false; + for (auto access_node : ref_node->accesses) + { + if (ipcp_argagg_and_access_must_overlap_p (v, access_node)) + return true; + } + } + } + return false; +} + /* If signature changed, update the summary. */ static void @@ -4111,14 +4169,17 @@ update_signature (struct cgraph_node *node) continue; if (r) for (const modref_access_node &kill : r->kills) - if (ipcp_argagg_and_kill_overlap_p (v, kill)) + if (ipcp_argagg_and_kill_overlap_p (v, kill) + && !ipcp_argagg_and_modref_tree_must_overlap_p (v, *r->loads)) { v.killed = true; break; } if (!v.killed && r_lto) for (const modref_access_node &kill : r_lto->kills) - if (ipcp_argagg_and_kill_overlap_p (v, kill)) + if (ipcp_argagg_and_kill_overlap_p (v, kill) + && !ipcp_argagg_and_modref_tree_must_overlap_p (v, + *r_lto->loads)) { v.killed = 1; break;