From patchwork Thu Oct 24 12:55:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Jires X-Patchwork-Id: 99489 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 2FCDC3858C5F for ; Thu, 24 Oct 2024 12:57:30 +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 [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 6B4DD3858435 for ; Thu, 24 Oct 2024 12:55:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B4DD3858435 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6B4DD3858435 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729774549; cv=none; b=U0w2EkUBtE1HhqrM6gcR4XW9SPQjoWk02maQMvKbhJabm0khb3j+io38gF5taUcAsbzB96Qv5WYSYHe1GvqKrqxaagQckWpZ+Basd5gdwP1eL9jtYWR2iTOOc/NZM6dBDYrOZXPp90kH6Qs3K3uxpyM2T0WEU8bbWAjne3uWZNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729774549; c=relaxed/simple; bh=+DUUecw+7phbbs4JHHcFGgdpJqhuY90OHyAEUl6kg3w=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:Message-ID:MIME-Version; b=RpR8LgEpBRa0+OgTFUO4pKMaftCkr/XpZ0zcljGfpjPthsi9YhJitY0PQ5WMrzIUM6FEDyWBlVuRM+PKDIzp0XNxXdIgnUugO3izWyfk2yZQvlU41gwi8Z1gsGir5bp+KdCvNOC9rdLYdMXQzZXhXSfu2Ilu8ib1DrCJhXNJASk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3ABB721DD9; Thu, 24 Oct 2024 12:55:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1729774545; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=6O2wvkXzviQcAHLD+Uivhv5D8//jMSoGSOBlwPqmbbQ=; b=VR3rIKJ5lD3tYSdv8fZF2jG5JZ8tn/1lOzs9D3gtvykRzi+cAyHmL1Z6v+WZpGGVpOs0AO 944N/4U4cQOobrtO53VTHz0cuPGdzZkYzXY5Ot3zpZAB6kdPnj2mD0reBb30J0gL4c7s4W b73GfnnYAg/FlGRWFUYJrlY+iRrGUkA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1729774545; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=6O2wvkXzviQcAHLD+Uivhv5D8//jMSoGSOBlwPqmbbQ=; b=ub4fkXS/MtML1F8BlVJ6sUO0WFT0EVdrpM/zHJJMzJrKgzUbEV4sah8MpsUh9e0Kr4O8VV hef8QgVu+ZKgo0AQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1729774544; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=6O2wvkXzviQcAHLD+Uivhv5D8//jMSoGSOBlwPqmbbQ=; b=KSI1inm/HjGN8Fug00qc4XfRLbCGtnN7uFT6nMN0C0oDhsvgbcZFtFJXDM8YT4neWOmTMe N/ehKxGxkvw7ct70Urj5iR9ZQcCae2gNhMSJM+4w76lYoUowVRd8lVgURmIh48s2d9q9dn Lz/qBTS0bjf4A+6lKMOsYFUfeFz4+Bo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1729774544; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=6O2wvkXzviQcAHLD+Uivhv5D8//jMSoGSOBlwPqmbbQ=; b=ebUDLv8btuGvZiZJsGcoV9n0lAwoK5KwhRjya5uK4JhDCtKW61PVauMSUEfVmfVXMQ1CT0 Di1ts9nTbq/NlhDA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2C214136F5; Thu, 24 Oct 2024 12:55:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id yxhOCtBDGmfaDwAAD6G6ig (envelope-from ); Thu, 24 Oct 2024 12:55:44 +0000 Date: Thu, 24 Oct 2024 14:55:39 +0200 From: Michal Jires To: gcc-patches@gcc.gnu.org Cc: hubicka@ucw.cz, mjambor@suse.cz Subject: [PATCH] [lto] ipcp don't propagate where not needed Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Level: X-Spamd-Result: default: False [-3.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_RHS_NOT_FQDN(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; MISSING_XM_UA(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[ipa-prop.cc:url,lto-cgraph.cc:url] X-Spam-Score: -3.80 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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~patchwork=sourceware.org@gcc.gnu.org This patch disables propagation of ipcp information into lto partitions where all instances of the node are marked to be inlined. Motivation: Incremental LTO needs stable values between compilations to be effective. This requirement fails with following example: void heavily_used_debug_function(int); ... heavily_used_debug_function(__LINE__); Ipcp creates long list of all __LINE__ arguments, and then propagates it with every function clone, even though for inlined functions this information is not useful. gcc/ChangeLog: * ipa-prop.cc (write_ipcp_transformation_info): Disable uneeded value propagation. * lto-cgraph.cc (lto_symtab_encoder_encode): Default values. (lto_symtab_encoder_always_inlined_p): New. (lto_set_symtab_encoder_not_always_inlined): New. (add_node_to): Set always inlined. * lto-streamer.h (struct lto_encoder_entry): New field. (lto_symtab_encoder_always_inlined_p): New. --- gcc/ipa-prop.cc | 12 +++++++++--- gcc/lto-cgraph.cc | 41 +++++++++++++++++++++++++++++++++++++---- gcc/lto-streamer.h | 4 ++++ 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index 032358fde22..ef83ce3edb6 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -5404,9 +5404,15 @@ write_ipcp_transformation_info (output_block *ob, cgraph_node *node, streamer_write_bitpack (&bp); } - streamer_write_uhwi (ob, vec_safe_length (ts->m_vr)); - for (const ipa_vr &parm_vr : ts->m_vr) - parm_vr.streamer_write (ob); + /* If all instances of this node are inlined, ipcp info is not useful. */ + if (!lto_symtab_encoder_always_inlined_p (encoder, node)) + { + streamer_write_uhwi (ob, vec_safe_length (ts->m_vr)); + for (const ipa_vr &parm_vr : ts->m_vr) + parm_vr.streamer_write (ob); + } + else + streamer_write_uhwi (ob, 0); } /* Stream in the aggregate value replacement chain for NODE from IB. */ diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc index 53cc965bdfd..5c3e3076c8d 100644 --- a/gcc/lto-cgraph.cc +++ b/gcc/lto-cgraph.cc @@ -114,7 +114,7 @@ lto_symtab_encoder_encode (lto_symtab_encoder_t encoder, if (!encoder->map) { - lto_encoder_entry entry = {node, false, false, false}; + lto_encoder_entry entry = {node, false, false, true, false}; ref = encoder->nodes.length (); encoder->nodes.safe_push (entry); @@ -124,7 +124,7 @@ lto_symtab_encoder_encode (lto_symtab_encoder_t encoder, size_t *slot = encoder->map->get (node); if (!slot || !*slot) { - lto_encoder_entry entry = {node, false, false, false}; + lto_encoder_entry entry = {node, false, false, true, false}; ref = encoder->nodes.length (); if (!slot) encoder->map->put (node, ref + 1); @@ -190,6 +190,27 @@ lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder, encoder->nodes[index].body = true; } +/* Return TRUE if the NODE and its clones are always inlined. */ + +bool +lto_symtab_encoder_always_inlined_p (lto_symtab_encoder_t encoder, + struct cgraph_node *node) +{ + int index = lto_symtab_encoder_lookup (encoder, node); + return encoder->nodes[index].always_inlined; +} + +/* Specify that the NODE and its clones are not always inlined. */ + +static void +lto_set_symtab_encoder_not_always_inlined (lto_symtab_encoder_t encoder, + struct cgraph_node *node) +{ + int index = lto_symtab_encoder_encode (encoder, node); + gcc_checking_assert (encoder->nodes[index].node == node); + encoder->nodes[index].always_inlined = false; +} + /* Return TRUE if we should encode initializer of NODE (if any). */ bool @@ -799,15 +820,27 @@ output_refs (lto_symtab_encoder_t encoder) static void add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node, - bool include_body) + bool include_body, bool not_inlined) { if (node->clone_of) - add_node_to (encoder, node->clone_of, include_body); + add_node_to (encoder, node->clone_of, include_body, not_inlined); if (include_body) lto_set_symtab_encoder_encode_body (encoder, node); + if (not_inlined) + lto_set_symtab_encoder_not_always_inlined (encoder, node); lto_symtab_encoder_encode (encoder, node); } +/* Add NODE into encoder as well as nodes it is cloned from. + Do it in a way so clones appear first. */ + +static void +add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node, + bool include_body) +{ + add_node_to (encoder, node, include_body, include_body && !node->inlined_to); +} + /* Add all references in NODE to encoders. */ static void diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h index 397f5fc8d68..1a6bc9fa3a1 100644 --- a/gcc/lto-streamer.h +++ b/gcc/lto-streamer.h @@ -449,6 +449,8 @@ struct lto_encoder_entry unsigned int in_partition:1; /* Do we encode body in this partition? */ unsigned int body:1; + /* Do we always inline this node and its clones? */ + unsigned int always_inlined:1; /* Do we encode initializer in this partition? For example the readonly variable initializers are encoded to aid constant folding even if they are not in the partition. */ @@ -914,6 +916,8 @@ void lto_symtab_encoder_delete (lto_symtab_encoder_t); bool lto_symtab_encoder_delete_node (lto_symtab_encoder_t, symtab_node *); bool lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t, struct cgraph_node *); +bool lto_symtab_encoder_always_inlined_p (lto_symtab_encoder_t, + struct cgraph_node *); bool lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t, symtab_node *); void lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t,