From patchwork Sun Jul 9 13:28:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 117506 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp4445302vqx; Sun, 9 Jul 2023 06:29:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlGHzGDQ3Xz+eiI7olp0WjUMuurfqUQhjAZ5HNjQuytzqjojuKfdZgROKTLhWs6Cfe1ON2tv X-Received: by 2002:a17:907:7896:b0:992:be80:aaf9 with SMTP id ku22-20020a170907789600b00992be80aaf9mr9095007ejc.51.1688909343229; Sun, 09 Jul 2023 06:29:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688909343; cv=none; d=google.com; s=arc-20160816; b=mgWNqk8D6F4vBQ2bfVjZ7skkghT8G4Pkh+RWtADq8qehCEERHkEOeCncgSaMrxoh3b Vtb5n4kPvkFVMoC/0k+eHNZogGPXSiAa3Ka59ME0hN1BjWkxWVuMjjLi5TpwbLPQD3qG BeLG1vIWAykQaOeWGHrovvtXpMaJwrS5BrILFPUYDJSydltxGXgampzxBAoShXKXWqE8 4CNW9ro8sSm5E14Cd82Mu3hKkm+ouR0ljttrB+m9J4nTTbM0uJr4tOq4e3M1z7QZ/mKb CttTJ7vHRqJNgKm2zdPlXxTg4woXNI2UCZXj3TU0SyGX4RyFm/jFvF8Fs2amH3m2+FAM +S4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=y0ulQFuDAiouLEeAhs/V//hioiB7Be6SWREeZzN1vWI=; fh=KxPrluukuxmHUzYWntxWAHNXePa4vWvGreVeug6Wy5k=; b=u196dVucHIEV4T3/1upGzKvcuiQfX8GnwmRluzBo5CXvOnF84liRvO60APMjJYwIU8 TUcz6HL4yAxsdIHmong0o/scXOHDbTwdqX2DcJ7g6hQ79Z0hfFlvc6kZ1kj1n9ZqmB/p B4v3zWA3wsRnoXUGglzFEliN3JZP13QyRTQ2FQ5JYkMF50i1xj9NcTfmkvk10hN9TNBu c6caxzGOemHJdWcUoTm2QK3KgbY4RdSWuQoACI1+nAvEBGrsvAvz2Pz2UQZrCnwLJSmJ Qm577Zhpop37fLsSlxg59zjUq4ANfadY0XAB/Ha+UavXBv6TlHfMaMq+BWMICnNGPfaj FUEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=MD7ME2Gj; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g10-20020a170906594a00b00993a4cd974esi6182499ejr.287.2023.07.09.06.29.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:29:03 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=MD7ME2Gj; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2485538582A3 for ; Sun, 9 Jul 2023 13:29:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2485538582A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688909342; bh=y0ulQFuDAiouLEeAhs/V//hioiB7Be6SWREeZzN1vWI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=MD7ME2GjbahiQciK6fBo+fIbJiSVe0SHizZbZ/t2neUywo/bvQ+BJ9VvjOeQvbi0e 6niwUaD3Bo3yi8iiG/BmVr8/mS9ywtdKIiZ684QSNu1o9gE3U9GB3VJCGfTGd9/OuY Lf1vtD7bRlpmtTHxV+funxIUIHcACdFAbuuiqbPw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 777DE3858C2C for ; Sun, 9 Jul 2023 13:28:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 777DE3858C2C Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 17822281D0F; Sun, 9 Jul 2023 15:28:18 +0200 (CEST) Date: Sun, 9 Jul 2023 15:28:18 +0200 To: gcc-patches@gcc.gnu.org Subject: Improve dumping of profile_count Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: , X-Patchwork-Original-From: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka 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?1770949803442221710?= X-GMAIL-MSGID: =?utf-8?q?1770949803442221710?= Hi, dumps of profile_counts are quite hard to interpret since they are 64bit fixed point values. In many cases one looks at a single function and it is better to think of basic block frequency, that is how many times it is executed each invocatoin. This patch makes CFG dumps to also print this info. For example: main() { for (int i = 0; i < 10; i++) t(); } the -fdump-tree-optimized-blocks-details now prints: int main () { unsigned int ivtmp_1; unsigned int ivtmp_2; ;; basic block 2, loop depth 0, count 97603128 (estimated locally, freq 1.0000), maybe hot ;; prev block 0, next block 3, flags: (NEW, VISITED) ;; pred: ENTRY [always] count:97603128 (estimated locally, freq 1.0000) (FALLTHRU,EXECUTABLE) ;; succ: 3 [always] count:97603128 (estimated locally, freq 1.0000) (FALLTHRU,EXECUTABLE) ;; basic block 3, loop depth 1, count 976138697 (estimated locally, freq 10.0011), maybe hot ;; prev block 2, next block 4, flags: (NEW, VISITED) ;; pred: 3 [90.0% (guessed)] count:878535568 (estimated locally, freq 9.0011) (TRUE_VALUE,EXECUTABLE) ;; 2 [always] count:97603128 (estimated locally, freq 1.0000) (FALLTHRU,EXECUTABLE) # ivtmp_2 = PHI t (); ivtmp_1 = ivtmp_2 + 4294967295; if (ivtmp_1 != 0) goto ; [90.00%] else goto ; [10.00%] ;; succ: 3 [90.0% (guessed)] count:878535568 (estimated locally, freq 9.0011) (TRUE_VALUE,EXECUTABLE) ;; 4 [10.0% (guessed)] count:97603129 (estimated locally, freq 1.0000) (FALSE_VALUE,EXECUTABLE) ;; basic block 4, loop depth 0, count 97603128 (estimated locally, freq 1.0000), maybe hot ;; prev block 3, next block 1, flags: (NEW, VISITED) ;; pred: 3 [10.0% (guessed)] count:97603129 (estimated locally, freq 1.0000) (FALSE_VALUE,EXECUTABLE) return 0; ;; succ: EXIT [always] count:97603128 (estimated locally, freq 1.0000) (EXECUTABLE) } Which makes it easier to see that the inner bb is executed 10 times per invocation gcc/ChangeLog: * cfg.cc (check_bb_profile): Dump counts with relative frequency. (dump_edge_info): Likewise. (dump_bb_info): Likewise. * profile-count.cc (profile_count::dump): Add comma between quality and freq. gcc/testsuite/ChangeLog: * gcc.dg/predict-22.c: Update template. diff --git a/gcc/cfg.cc b/gcc/cfg.cc index 740d4f3581d..0de6d6b9e71 100644 --- a/gcc/cfg.cc +++ b/gcc/cfg.cc @@ -475,9 +475,9 @@ check_bb_profile (basic_block bb, FILE * file, int indent) { fprintf (file, ";; %sInvalid sum of incoming counts ", s_indent); - sum.dump (file); + sum.dump (file, fun); fprintf (file, ", should be "); - bb->count.dump (file); + bb->count.dump (file, fun); fprintf (file, "\n"); } } @@ -525,7 +525,7 @@ dump_edge_info (FILE *file, edge e, dump_flags_t flags, int do_succ) if (e->count ().initialized_p () && do_details) { fputs (" count:", file); - e->count ().dump (file); + e->count ().dump (file, cfun); } if (e->flags && do_details) @@ -808,7 +808,7 @@ dump_bb_info (FILE *outf, basic_block bb, int indent, dump_flags_t flags, if (bb->count.initialized_p ()) { fputs (", count ", outf); - bb->count.dump (outf); + bb->count.dump (outf, cfun); } if (maybe_hot_bb_p (fun, bb)) fputs (", maybe hot", outf); diff --git a/gcc/profile-count.cc b/gcc/profile-count.cc index 6bf9700d8db..2c07ebc5942 100644 --- a/gcc/profile-count.cc +++ b/gcc/profile-count.cc @@ -94,7 +94,7 @@ profile_count::dump (char *buffer, struct function *fun) const else if (fun && initialized_p () && fun->cfg && ENTRY_BLOCK_PTR_FOR_FN (fun)->count.initialized_p ()) - sprintf (buffer, "%" PRId64 " (%s freq %.4f)", m_val, + sprintf (buffer, "%" PRId64 " (%s, freq %.4f)", m_val, profile_quality_display_names[m_quality], to_sreal_scale (ENTRY_BLOCK_PTR_FOR_FN (fun)->count).to_double ()); else diff --git a/gcc/testsuite/gcc.dg/predict-22.c b/gcc/testsuite/gcc.dg/predict-22.c index f14c2b68861..1aed03fae79 100644 --- a/gcc/testsuite/gcc.dg/predict-22.c +++ b/gcc/testsuite/gcc.dg/predict-22.c @@ -55,5 +55,5 @@ foo (int x, int y, int z) baz (&f); } /* { dg-final { scan-tree-dump-times "Invalid sum" 0 "optimized"} } */ -/* { dg-final { scan-tree-dump-times "count 0 .precise.," 1 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "count 0 .precise" 1 "optimized"} } */ /* { dg-final { scan-rtl-dump-times "COLD_PARTITION" 1 "bbpart"} } */