From patchwork Mon Feb 10 22:00:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 106309 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 D2B553858C56 for ; Mon, 10 Feb 2025 22:01:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D2B553858C56 Authentication-Results: sourceware.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=VsLCTfQT; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=4sEpCdsX; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=VsLCTfQT; dkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=4sEpCdsX 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 [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 6212E3858D20 for ; Mon, 10 Feb 2025 22:00:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6212E3858D20 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 6212E3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739224843; cv=none; b=Y7d/uSSY/49lxMEMWGTfk9A1n0srBE67fkYF9hCEqjyyLxwuKjoWra287ciJW+u3N6noBFDT0smXYPPGTf6y2TnAg0xyit2U4HG/blZXELMl5LVW4EvPgDCzY2kTBH9Q2kghbxPjf72659iR2JFPxV2NMVy+n2IGcOQBG1psvsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739224843; c=relaxed/simple; bh=SFc8onwABgwNNCuEjsYpptyhDY92i0SlCcXJOxkr18o=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=kXWpAtDzNP7uU/9WV362P4g8znuOKogO2QEjwxdTaQOdz10dYm+N0H1EF6ogMO2ztvEIuZ2WbhLBtUnXTyXffui92Dsn0H/NsIhWwYsfpk+7+xFQPoRPXQjAk0VW8qtvfakvDdKP+t7umTgq7xmyR9Yurism8SA3r4qQ25u4skM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6212E3858D20 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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-out2.suse.de (Postfix) with ESMTPS id 339E81F78A; Mon, 10 Feb 2025 22:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1739224842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=E1oIyCnTVK9iSKtjrW72wvby1HL3jxrXzXugmXjZknM=; b=VsLCTfQTvyrsC0e2arYuagFDMoKL3+zY/vNApQzUB4C/8mHvb1eVFR5XZoLG5oSeLPJk3b 74d6MXNlhftTGeiXEd/cT/4EZ9/LJSTBERkS2fsr4BqeonjZmHCVCIVjg8zjivD9jwyzM6 GJhAzB25dLhODl/sT6Efh8TQkbobDR4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1739224842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=E1oIyCnTVK9iSKtjrW72wvby1HL3jxrXzXugmXjZknM=; b=4sEpCdsXQzsjiPKPoBnnJju9ia9v9J/KVClo9szmW2QT5152U1fmLBWqKeY+3/rTaqXsLU GS3j7HatStMu7yAA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=VsLCTfQT; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=4sEpCdsX DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1739224842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=E1oIyCnTVK9iSKtjrW72wvby1HL3jxrXzXugmXjZknM=; b=VsLCTfQTvyrsC0e2arYuagFDMoKL3+zY/vNApQzUB4C/8mHvb1eVFR5XZoLG5oSeLPJk3b 74d6MXNlhftTGeiXEd/cT/4EZ9/LJSTBERkS2fsr4BqeonjZmHCVCIVjg8zjivD9jwyzM6 GJhAzB25dLhODl/sT6Efh8TQkbobDR4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1739224842; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=E1oIyCnTVK9iSKtjrW72wvby1HL3jxrXzXugmXjZknM=; b=4sEpCdsXQzsjiPKPoBnnJju9ia9v9J/KVClo9szmW2QT5152U1fmLBWqKeY+3/rTaqXsLU GS3j7HatStMu7yAA== 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 2A2FC13A62; Mon, 10 Feb 2025 22:00:42 +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 /bNKCgp3qmcULAAAD6G6ig (envelope-from ); Mon, 10 Feb 2025 22:00:42 +0000 From: Martin Jambor To: GCC Patches Cc: Jakub Jelinek , Jan Hubicka Subject: [PATCH] lto: Add an entry for cold attribute to lto_gnu_attributes User-Agent: Notmuch/0.38.3 (https://notmuchmail.org) Emacs/29.4 (x86_64-suse-linux-gnu) Date: Mon, 10 Feb 2025 23:00:33 +0100 Message-ID: MIME-Version: 1.0 X-Rspamd-Queue-Id: 339E81F78A X-Spam-Score: -4.51 X-Rspamd-Action: no action X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; ARC_NA(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MID_RHS_MATCH_FROMTLD(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo]; TO_DN_ALL(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.cz:+] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Level: X-Spam-Status: No, score=-11.7 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 Hi, PR 118125 is a performance regression stemming from the fact that we lose the cold attribute of our __builtin_unreachable. The attribute is simply and silently dropped on the floor by decl_attributes (in attribs.cc) in the process of building decls for builtins because it cannot look it up in the gnu attribute name space by lookup_scoped_attribute_spec. For that not to happen it must be in lto_gnu_attributes and this patch adds it there. In comment 13 of the bug Andrew identified other attributes which are in builtin-attrs.def but missing in lto_gnu_attributes but apart from cold it seems that they are either not used in builtins.def or are used in DEF_LIB_BUILTIN which I guess might be less critical? Eventually I decided to go for the most simple of patches and only add things if they are requested. For the same reason I also did not add any checking to the attribute "handle" callback or any exclusion check. They seem to be mostly relevant before LTO FE kicks in to me, but again, I'm happy to add any if they seem to be useful. Since Ian fixed PR 118746, the same issue has also been fixed in the Go front-end and so I have added a simple checking assert to the redirect_to_unreachable function to make sure it has the intended effect. LTO-bootstrapped and tested on x86_64-linux. OK for master? Thanks, Martin gcc/ChangeLog: 2025-02-03 Martin Jambor PR lto/118125 * ipa-fnsummary.cc (redirect_to_unreachable): Add checking assert that the builtin_unreachable decl has attribute cold. gcc/lto/ChangeLog: 2025-02-03 Martin Jambor PR lto/118125 * lto-lang.cc (lto_gnu_attributes): Add an entry for cold attribute. (handle_cold_attribute): New function. --- gcc/ipa-fnsummary.cc | 3 +++ gcc/lto/lto-lang.cc | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc index 33f19365ec3..4c062fe8a0e 100644 --- a/gcc/ipa-fnsummary.cc +++ b/gcc/ipa-fnsummary.cc @@ -255,6 +255,9 @@ redirect_to_unreachable (struct cgraph_edge *e) struct cgraph_node *target = cgraph_node::get_create (builtin_decl_unreachable ()); + gcc_checking_assert (lookup_attribute ("cold", + DECL_ATTRIBUTES (target->decl))); + if (e->speculative) e = cgraph_edge::resolve_speculation (e, target->decl); else if (!e->callee) diff --git a/gcc/lto/lto-lang.cc b/gcc/lto/lto-lang.cc index 652d7fc5e30..e41b548b398 100644 --- a/gcc/lto/lto-lang.cc +++ b/gcc/lto/lto-lang.cc @@ -60,6 +60,7 @@ static tree ignore_attribute (tree *, tree, tree, int, bool *); static tree handle_format_attribute (tree *, tree, tree, int, bool *); static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *); static tree handle_format_arg_attribute (tree *, tree, tree, int, bool *); +static tree handle_cold_attribute (tree *, tree, tree, int, bool *); /* Helper to define attribute exclusions. */ #define ATTR_EXCL(name, function, type, variable) \ @@ -128,6 +129,8 @@ static const attribute_spec lto_gnu_attributes[] = handle_sentinel_attribute, NULL }, { "type generic", 0, 0, false, true, true, false, handle_type_generic_attribute, NULL }, + { "cold", 0, 0, false, false, false, false, + handle_cold_attribute, NULL }, { "fn spec", 1, 1, false, true, true, false, handle_fnspec_attribute, NULL }, { "transaction_pure", 0, 0, false, true, true, false, @@ -598,6 +601,16 @@ handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree ARG_UNUSED (name), return NULL_TREE; } +/* Handle a "cold" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_cold_attribute (tree *, tree, tree, int, bool *) +{ + /* Nothing to be done here. */ + return NULL_TREE; +} + /* Cribbed from c-common.cc. */ static void