From patchwork Tue Feb 21 14:42:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 60115 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp45739wrd; Tue, 21 Feb 2023 06:43:31 -0800 (PST) X-Google-Smtp-Source: AK7set+FzP31DzNUmgo33cT8a86jDhQVl72iEMHznT5sK87Bx7OKGPwV6rZIJlKZ2fJ1XcSQ7LIW X-Received: by 2002:aa7:da06:0:b0:4aa:da7c:4c5c with SMTP id r6-20020aa7da06000000b004aada7c4c5cmr4355398eds.34.1676990611160; Tue, 21 Feb 2023 06:43:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676990611; cv=none; d=google.com; s=arc-20160816; b=Md0oVa/yllpoW/BWbopUrZtHAfnEISyQvVLvkojginoAJ9iHf6249Z5xVOb7hp5Tj3 WCPTe27coTk3Sgv78J3eIFYEhf7s6eKVj7FbEsyUyR+4b+KG1UFqeQX0IOwEz1cedApB GuUclZKBsJ4M94NIgJMYsygro6WdHXhJPUAMLeA0987gudZxOCxMjPV7Px94LMxALrAb 5dEnLJLNEBNIhJlZaPM3U62orExBjkIYW08Ktp3ezGIiWyoUvSmCOYs1SwyPAe1qEOHO ig+nDVuV9d02ZSeS+BltHV2dNX8JAYNVf6tvokscyLN4Ir6EhhYAnBIjwx5JK1AoAGlr YRzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :user-agent:subject:cc:to:from:dkim-signature:dkim-signature :dmarc-filter:delivered-to; bh=COAVFI5z46w9Zf0Ei1imKNs0l0Zx3X9EFd2ksjghEyU=; b=frVMoPp2mbIAd29/XBokja+CzHT/9jn2bTTgxHgBLII7iT6lyA2rrhOM9Zlbe7O/9u eO1E9vzOYPQ48EZ02ECV38kNUVpmiwtfhrHRsN7JXRsJ4mIjL1K1M3YplL5Il2UI0vXz 9QLz4D5KXXpPIDYePB3ft6ga+IW7mrEvpZagfCNOqg0LWldRNZbEiMz3eUE5yR4GnJYi 0pVkhA4NiBJgEdkDZla/gR+sShTJ8DcpU3aE/Hwg/OpjRFRWo3p0yeo2GWaNDfRWrrn8 6bgoj48mI2D2KFwip0Ezx0+kwEDg/lEGIPrMOIGotH2CF2fLv10nWPpd+UJOihRAF0oA kIRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="WqkJ/P46"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=hiLcazTt; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d25-20020aa7d699000000b004aad0c7e385si19385669edr.270.2023.02.21.06.43.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 06:43:31 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="WqkJ/P46"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=hiLcazTt; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8511F384F487 for ; Tue, 21 Feb 2023 14:43:09 +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.220.28]) by sourceware.org (Postfix) with ESMTPS id D68263858D32 for ; Tue, 21 Feb 2023 14:42:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D68263858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass 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 9719634B3E; Tue, 21 Feb 2023 14:42:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1676990561; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=COAVFI5z46w9Zf0Ei1imKNs0l0Zx3X9EFd2ksjghEyU=; b=WqkJ/P46vNPEgWJWjXDCO+eWJZfydUNDq8QRNrXvkjXP8pSE2ax9Y345BPO0Zbr7gWrnCT /WLjx7a1ETu5ARhKn79ocHK9OlLDodNFvEECGyIn2P/utjjGHU/itdU5T1deFRvbqTqAGo iX3dYgdrvRIgxPSNBxr5qFOsYtz6mKM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1676990561; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=COAVFI5z46w9Zf0Ei1imKNs0l0Zx3X9EFd2ksjghEyU=; b=hiLcazTtCyglqI8DcxBkaQy+jsXSzZVlEPHxLAxvYNn43ZA0PfxD61o3VWtsOCIUNDbfJA oou/UNe4l3iYJ2DQ== 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 8A64E13223; Tue, 21 Feb 2023 14:42:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id fm6+IWHY9GP7WQAAMHmgww (envelope-from ); Tue, 21 Feb 2023 14:42:41 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH 1/2] ipa-cp: Fix various issues in update_specialized_profile (PR 107925) User-Agent: Notmuch/0.37 (https://notmuchmail.org) Emacs/28.2 (x86_64-suse-linux-gnu) Date: Tue, 21 Feb 2023 15:42:41 +0100 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758452106897272890?= X-GMAIL-MSGID: =?utf-8?q?1758452106897272890?= Hi, the patch below fixes various issues in function update_specialized_profile. The main is removal of the assert which is bogus in the case of recursive cloning. The division of unexplained counts is guesswork, which then leads to updates of counts of recursive edges, which then can be redirected to the new clone and their count subtracted from the count and there simply may not be enough left in the count of the original node - especially when we clone a lot because of using --param ipa-cp-eval-threshold=1. The other issue was omission to drop the count of the original node to ipa count. And when calculating the remainder, we should use lenient_count_portion_handling to account for partial train runs. Finally, the patch adds dumping of the original count which I think is useful. Profiled-LTO-bootstrapped on its own and also normally bootstrapped and tested together with the subsequent patch on an x86_64-linux. OK for master and the 12 branch - assuming it is also affected? Thanks, Martin gcc/ChangeLog: 2023-02-17 Martin Jambor PR ipa/107925 * ipa-cp.cc (update_specialized_profile): Drop orig_node_count to ipa count, remove assert, lenient_count_portion_handling, dump also orig_node_count. --- gcc/ipa-cp.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index 4b8dedc0c51..5a6b41cf2d6 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -5093,22 +5093,24 @@ update_specialized_profile (struct cgraph_node *new_node, profile_count redirected_sum) { struct cgraph_edge *cs; - profile_count new_node_count, orig_node_count = orig_node->count; + profile_count new_node_count, orig_node_count = orig_node->count.ipa (); if (dump_file) { fprintf (dump_file, " the sum of counts of redirected edges is "); redirected_sum.dump (dump_file); + fprintf (dump_file, "\n old ipa count of the original node is "); + orig_node_count.dump (dump_file); fprintf (dump_file, "\n"); } if (!(orig_node_count > profile_count::zero ())) return; - gcc_assert (orig_node_count >= redirected_sum); - new_node_count = new_node->count; new_node->count += redirected_sum; - orig_node->count -= redirected_sum; + orig_node->count + = lenient_count_portion_handling (orig_node->count - redirected_sum, + orig_node); for (cs = new_node->callees; cs; cs = cs->next_callee) cs->count += cs->count.apply_scale (redirected_sum, new_node_count); From patchwork Tue Feb 21 14:42:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 60116 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp45771wrd; Tue, 21 Feb 2023 06:43:36 -0800 (PST) X-Google-Smtp-Source: AK7set+X9FNK+4qY5lb4dyQY5vz4+aqC8c5POvs/iKQGRCh03XZu9kNRi5C3cftdA806fgN97qnv X-Received: by 2002:a17:906:d8cf:b0:8b2:5262:562c with SMTP id re15-20020a170906d8cf00b008b25262562cmr13302090ejb.34.1676990615982; Tue, 21 Feb 2023 06:43:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676990615; cv=none; d=google.com; s=arc-20160816; b=OXkIKGXElGlV0M2/NErcNOwCCTsfAuB//kbNEPQ2uO4L1RjLa8c69+6lYCXA/cpmZd LhTf2iebR/D4hKMnCjPFW0FMSW5W0zra9KW1iB/N21ucVoM5QFVgAor2KIO1VDjsZwGR GsjDC2HxkueeTEij5gKtLqI/1abYNuj8icEYrXl+N9TefUg0xTWq14RdhE1aaBSVcSNh nVz48aJoOdCNbCLN3pmxgkvbnKLjLrb0GMzBTLSIc42jUPBKxLLTtiWs+a4x4Yp6RQbp 4+Q3qjWXO5a6m+dDEHxcOP8KNxgc29wBJwZZcSq0K/oFv+WigppwfDbAQ+7stHoiW7L+ wp6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :user-agent:subject:cc:to:from:dkim-signature:dkim-signature :dmarc-filter:delivered-to; bh=mVfrJJWjsuCVRggm6DJcICECDf53bOVFA81nC1rU+1s=; b=0T9amS1dOoSAM1gGLvxMggcIl9uFR0WEpFRWIlgcFaRSjy36H5lZtgJ4/UiDrPTe+w qzkH7U4YPFUaA3cSa3SkgrG25+82lLCCZIEfoAGy+JLqqgyvT5LtIIZ++t0bWcWYB7UF BvncooyxCPBvhAw2ktsySAB2kVspt5JIRZyjQ+1pDuInp87qhPbtGz3O9FTM/OcWAprq VY+CA+2wscARnG23ZXiZISmmgPnbYhaFinrEbZ9A2rFdJt/bCrEoT0FUyvxEsy75WI7f 8xepg7xoHn/2fibKx7j19/OJ85uD4XvDrURb0y6p1vrBdAhp4EoDcYMQG7hjXjuT6y3t 8E5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=OxJ7jH1O; dkim=neutral (no key) header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 12-20020a17090600cc00b008dcebb5a0fasi3813019eji.944.2023.02.21.06.43.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 06:43:35 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=OxJ7jH1O; dkim=neutral (no key) header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE5A0385735E for ; Tue, 21 Feb 2023 14:43:11 +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 6D1723858D3C for ; Tue, 21 Feb 2023 14:42:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D1723858D3C 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 9EF6334B3F; Tue, 21 Feb 2023 14:42:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1676990563; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=mVfrJJWjsuCVRggm6DJcICECDf53bOVFA81nC1rU+1s=; b=OxJ7jH1OzFrXW/NpHzmrFI7eGnMYifplEFDWrYtesLHdegvQo74harXHWwznbd8JO//W2T 1P4BXcvrZpI2gywJDnRq+Ek4FMi79FixM5UUcMgV93Eq6GlUsSb7uFg3PN6kEoqnfg9lGZ Ckr1MlXaQww0bmjM7w8DvUcCVzVxlLc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1676990563; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=mVfrJJWjsuCVRggm6DJcICECDf53bOVFA81nC1rU+1s=; b=R8qmgLPEYtjT5OKsVEGSQyPeYDn8rfj/tDh45AeOEDrpHuQx2WMDhh2fWdUPxhP92ReHSY oNrpis6yhRHjrpAw== 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 9358613223; Tue, 21 Feb 2023 14:42:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id fnTbI2PY9GP+WQAAMHmgww (envelope-from ); Tue, 21 Feb 2023 14:42:43 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH 2/2] ipa-cp: Improve updating behavior when profile counts have gone bad User-Agent: Notmuch/0.37 (https://notmuchmail.org) Emacs/28.2 (x86_64-suse-linux-gnu) Date: Tue, 21 Feb 2023 15:42:43 +0100 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758452111722227339?= X-GMAIL-MSGID: =?utf-8?q?1758452111722227339?= Hi, Looking into the behavior of profile count updating in PR 107925, I noticed that an option not considered possible was actually happening, and - with the guesswork in place to distribute unexplained counts - it simply can happen. Currently it is handled by dropping the counts to local estimated zero, whereas it is probably better to leave the count as they are but drop the category to GUESSED_GLOBAL0 - which is what profile_count::combine_with_ipa_count in a similar case (or so I hope :-) Profiled-LTO-bootstrapped and normally bootstrapped and tested on an x86_64-linux. OK for master once stage1 opens up? Or perhaps even now? Thanks, Martin gcc/ChangeLog: 2023-02-20 Martin Jambor PR ipa/107925 * ipa-cp.cc (update_profiling_info): Drop counts of orig_node to global0 instead of zeroing when it does not have as many counts as it should. --- gcc/ipa-cp.cc | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index 5a6b41cf2d6..6477bb840e5 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -4969,10 +4969,20 @@ update_profiling_info (struct cgraph_node *orig_node, false); new_sum = stats.count_sum; + bool orig_edges_processed = false; if (new_sum > orig_node_count) { - /* TODO: Perhaps this should be gcc_unreachable ()? */ - remainder = profile_count::zero ().guessed_local (); + /* TODO: Profile has alreay gone astray, keep what we have but lower it + to global0 category. */ + remainder = orig_node->count.global0 (); + + for (cgraph_edge *cs = orig_node->callees; cs; cs = cs->next_callee) + cs->count = cs->count.global0 (); + for (cgraph_edge *cs = orig_node->indirect_calls; + cs; + cs = cs->next_callee) + cs->count = cs->count.global0 (); + orig_edges_processed = true; } else if (stats.rec_count_sum.nonzero_p ()) { @@ -5070,11 +5080,16 @@ update_profiling_info (struct cgraph_node *orig_node, for (cgraph_edge *cs = new_node->indirect_calls; cs; cs = cs->next_callee) cs->count = cs->count.apply_scale (new_sum, orig_new_node_count); - profile_count::adjust_for_ipa_scaling (&remainder, &orig_node_count); - for (cgraph_edge *cs = orig_node->callees; cs; cs = cs->next_callee) - cs->count = cs->count.apply_scale (remainder, orig_node_count); - for (cgraph_edge *cs = orig_node->indirect_calls; cs; cs = cs->next_callee) - cs->count = cs->count.apply_scale (remainder, orig_node_count); + if (!orig_edges_processed) + { + profile_count::adjust_for_ipa_scaling (&remainder, &orig_node_count); + for (cgraph_edge *cs = orig_node->callees; cs; cs = cs->next_callee) + cs->count = cs->count.apply_scale (remainder, orig_node_count); + for (cgraph_edge *cs = orig_node->indirect_calls; + cs; + cs = cs->next_callee) + cs->count = cs->count.apply_scale (remainder, orig_node_count); + } if (dump_file) {