From patchwork Thu Nov 8 00:49:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Indu Bhagat X-Patchwork-Id: 994576 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-489306-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="j8iSxPh4"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="I5b+YJ8g"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42r4Gr4rb9z9sC7 for ; Thu, 8 Nov 2018 11:41:37 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=a22nY1ECQaXzZFlN0n9QwCK+xklMqzWbyZLJWX0Wjahcs+US349f+ LZLcjwvYlsr/ps5KlML+c+kW/V2HTZwbX1mfJkGPY0w92GVAH1Bc61IU52QNGMh8 Y74/AdJM9GRWSMXGntb9hJaYIvM6nFskctaXE3QTWtpiTrscGGIalk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=GAIS1wJvS3iIi9rgWVe73YlobZ0=; b=j8iSxPh47oumKPKT5scj dVnmg7vDKl3krdAi/Eo3Yzux1c1Vqej7EkTYhCZ2Biqpfbq+7/M4NjGWMgL5jMj1 A3IkSqe5W3Y4zVeOSjL4/MQyL7HYml/74UVPfM5bXO7pHBFC95ZNyPb+Zc2BLia4 Q7l00tW7F3+klcK42MbyQJU= Received: (qmail 7743 invoked by alias); 8 Nov 2018 00:41:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 7716 invoked by uid 89); 8 Nov 2018 00:41:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=trained, Trunk, fdo, FDO X-HELO: aserp2120.oracle.com Received: from aserp2120.oracle.com (HELO aserp2120.oracle.com) (141.146.126.78) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 08 Nov 2018 00:41:28 +0000 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wA80Y58w026116 for ; Thu, 8 Nov 2018 00:41:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : subject : to : message-id : date : mime-version : content-type; s=corp-2018-07-02; bh=cpsVZ/iLGLXganEELH4CuRl1r05M+DXP4dmElC2bYCg=; b=I5b+YJ8g7qRaKVP1tBzki5d094VfjrmJHO84uZoUbTYd8Dyl+pVb1UPM8WTNlRNOGN9D CIzbf8iVXY+t/6p2UA7yoJCKCz5+PfpxaFc1FEN/EvIQCXydZsKloa9pDZd218jqr4i7 wgFYayRudfZjf9Mjx0lJ93kRZqrdqPlSB5o/xgpbV1fyguRft8TlYj2KWQOpRheljChF VDpjuKvMwWF87INaUyJBgKkOW/bZOFxIjirkUiD2YzqrHFMHFcUaobInnGwz7qoPArAl TtE3O35SD7yjyTqeYIYCIV0S967Wd2w/fFDxsIsSBCdUdulxYIeO7SRJdP5mpRAysjhD zw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2nh3mpxqp4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 08 Nov 2018 00:41:26 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wA80fPK7000480 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 8 Nov 2018 00:41:25 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wA80fOtS032004 for ; Thu, 8 Nov 2018 00:41:25 GMT Received: from [10.159.246.215] (/10.159.246.215) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 07 Nov 2018 16:41:24 -0800 From: Indu Bhagat Subject: [PATCH] minor FDO profile related fixes To: gcc-patches@gcc.gnu.org Message-ID: <3391e0e6-4acb-cd88-985d-4788d650c878@oracle.com> Date: Wed, 7 Nov 2018 16:49:13 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 I have been looking at -fdump-ipa-profile dump with an intention to sanitize bits of information so that one may use it to judge the "quality of a profile" in FDO. The overall question I want to address is - are there ways to know which functions were not run in the training run, i.e. have ZERO profile ? (This patch corrects some dumped info; in a subsequent patch I would like to add some more explicit information/diagnostics.) Towards that end, I noticed that there are a couple of misleading bits of information (so I think) in the symbol table dump listing all functions in the compilation unit : --- "globally 0" appears even when profile data has not been fed by feedback profile (not the intent as the documentation of profile_guessed_global0 in profile-count.h suggests). --- "unlikely_executed" should appear only when there is profile feedback or a function attribute is specified (as per documentation of node_frequency in coretypes.h). "unlikely_executed" in case of STALE or NO profile is misleading in my opinion. Summary of changes : 1. This patch makes some adjustments around how x_profile_status of a function is set - x_profile_status should be set to PROFILE_READ only when there is a profile for a function read from the .gcda file. So, instead of relying on profile_info (set whenever the gcda feedback file is present, even if the function does not have a profile available in the file), use exec_counts (non null when function has a profile (the latter may or may not be zero)). In essence, x_profile_status and profile_count::m_quality are set consistent to the stated intent (in code comments.) 2. A minor change in coverage.c is for more precise location of the message Following -fdump-ipa-profile dump excerpts show the effect : ------------------------------------------------ -O1, -O2, -O3 ------------------------------------------------ 0. APPLICABLE PROFILE Trunk : Function flags: count:224114269 body hot After Patch : Function flags: count:224114269 (precise) body hot 1. STALE PROFILE (i.e., those cases covered by Wcoverage-mismatch; when control flow changes between profile-generate and profile-use) Trunk : Function flags: count:224114269 body hot After Patch : Function flags: count:224114269 (precise) body hot 2. NO PROFILE (i.e., those cases covered by Wmissing-profile; when function has no profile available in the .gcda file) Trunk (missing .gcda file) : Function flags: count:1073741824 (estimated locally) body Trunk (missing function) : Function flags: count: 1073741824 (estimated locally, globally 0) body unlikely_executed After Patch (missing .gcda file) : Function flags: count:1073741824 (estimated locally) body After Patch (missing function) : Function flags: count:1073741824 (estimated locally) body 3. ZERO PROFILE (functions not run in training run) Trunk : Function flags: count: 1073741824 (estimated locally, globally 0) body unlikely_executed After Patch (remains the same) : count: 1073741824 (estimated locally, globally 0) body unlikely_executed -------------------------------------------------- O0 -------------------------------------------------- In O0, flag_guess_branch_prob is not set. This makes the profile_quality set to (precise) for most of the above cases. 0. APPLICABLE PROFILE Trunk : Function flags: count:224114269 body hot After Patch : Function flags: count:224114269 (precise) body hot 1. STALE PROFILE (i.e., those cases covered by Wcoverage-mismatch; when control flow changes between profile-generate and profile-use) Trunk : Function flags: count:224114269 body hot After Patch : Function flags: count:224114269 (precise) body hot 2. NO PROFILE (i.e., those cases covered by Wmissing-profile; when function has no profile available in the .gcda file) Trunk (missing file) : Function flags: body Trunk (missing function) : Function flags: count:0 body unlikely_executed After Patch (missing file) : Function flags: body *** After Patch (missing function) : Function flags: count:0 (precise) body (*** This remains misleading, and I do not have a solution for this; as use of heuristics to guess branch probability is not allowed in O0) 3. ZERO PROFILE (functions not run in training run) Trunk : Function flags: count:0 body unlikely_executed After Patch : Function flags: count:0 (precise) body -------------------------------------------------- make check-gcc on x86_64 shows no new failures. (A related PR was https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86957 where we added diagnostics for the NO PROFILE case.) diff --git a/gcc/coverage.c b/gcc/coverage.c index 599a3bb..7595e6c 100644 --- a/gcc/coverage.c +++ b/gcc/coverage.c @@ -358,7 +358,7 @@ get_coverage_counts (unsigned counter, unsigned cfg_checksum, if (warning_printed && dump_enabled_p ()) { dump_user_location_t loc - = dump_user_location_t::from_location_t (input_location); + = dump_user_location_t::from_function_decl (current_function_decl); dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc, "use -Wno-error=coverage-mismatch to tolerate " "the mismatch but performance may drop if the " diff --git a/gcc/profile-count.c b/gcc/profile-count.c index f4ab244..90f4feb 100644 --- a/gcc/profile-count.c +++ b/gcc/profile-count.c @@ -83,6 +83,8 @@ profile_count::dump (FILE *f) const fprintf (f, " (auto FDO)"); else if (m_quality == profile_guessed) fprintf (f, " (guessed)"); + else if (m_quality == profile_precise) + fprintf (f, " (precise)"); } } diff --git a/gcc/profile.c b/gcc/profile.c index 2130319..57e3f3c 100644 --- a/gcc/profile.c +++ b/gcc/profile.c @@ -698,6 +698,11 @@ compute_branch_probabilities (unsigned cfg_checksum, unsigned lineno_checksum) } } + if (exec_counts) + { + profile_status_for_fn (cfun) = PROFILE_READ; + } + /* If we have real data, use them! */ if (bb_gcov_count (ENTRY_BLOCK_PTR_FOR_FN (cfun)) || !flag_guess_branch_prob) @@ -705,7 +710,7 @@ compute_branch_probabilities (unsigned cfg_checksum, unsigned lineno_checksum) bb->count = profile_count::from_gcov_type (bb_gcov_count (bb)); /* If function was not trained, preserve local estimates including statically determined zero counts. */ - else + else if (profile_status_for_fn (cfun) == PROFILE_READ) FOR_ALL_BB_FN (bb, cfun) if (!(bb->count == profile_count::zero ())) bb->count = bb->count.global0 (); @@ -718,6 +723,11 @@ compute_branch_probabilities (unsigned cfg_checksum, unsigned lineno_checksum) if (dump_file) { + fprintf (dump_file, " Profile feedback for function"); + fprintf (dump_file, ((profile_status_for_fn (cfun) == PROFILE_READ) + ? " is available \n" + : " is not available \n")); + fprintf (dump_file, "%d branches\n", num_branches); if (num_branches) for (i = 0; i < 10; i++) @@ -1317,12 +1327,12 @@ branch_prob (void) values.release (); free_edge_list (el); coverage_end_function (lineno_checksum, cfg_checksum); - if (flag_branch_probabilities && profile_info) + if (flag_branch_probabilities + && (profile_status_for_fn (cfun) == PROFILE_READ)) { struct loop *loop; if (dump_file && (dump_flags & TDF_DETAILS)) report_predictor_hitrates (); - profile_status_for_fn (cfun) = PROFILE_READ; /* At this moment we have precise loop iteration count estimates. Record them to loop structure before the profile gets out of date. */