From patchwork Thu Nov 28 14:44:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1202092 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514771-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ucw.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ZJsPvn0D"; 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 47P0mH6XGZz9sPW for ; Fri, 29 Nov 2019 01:45:02 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=hFCh6YcIyYqmw0ABZNFmhI8xAqrZTVZCSkuPZvDXvRr9XGqGah7Te St2pWGyp4Bgu7Uq8R3/84GO/xb4Ivc5FI7SWAkgyuK1T0Ly+ddf6TGZzFOJKSQGd sqzxx0z/CI4UIKRAOBdl+Cbiq0HUZNP+gUjicdkPiFPbvUz1at2u0A= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=6SeHsnZO82f3PVKSzyw5qpELrlQ=; b=ZJsPvn0DZ1rTJ4K0e5H8 TmWjk1mjJoYUzn6AWVWw7j/Iv4Ku5LO2q31F/lPg2GiTbNfAVDnAdVw3fm0ZoOQa cjrYlIiQ2nyw1MyYWqDx8+pP7YiNbT5EYz27YWG5reknnmmBF+gGbms96obPmtBF 1pIHzr86DNxfbryky2X2Ze8= Received: (qmail 116436 invoked by alias); 28 Nov 2019 14:44:54 -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 116423 invoked by uid 89); 28 Nov 2019 14:44:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS autolearn=ham version=3.3.1 spammy=drops, 1368, cgraphclones.c, UD:cgraphclones.c X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 28 Nov 2019 14:44:53 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 2DE3F280822; Thu, 28 Nov 2019 15:44:51 +0100 (CET) Date: Thu, 28 Nov 2019 15:44:51 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix profile adjusments while cloning Message-ID: <20191128144451.imjykj7kjhwwmlri@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Hi, this patch fixes profile updates while cloning. When new clone is produced its global profile is subtracted from the original function. If the original function profile drops to 0 we want to switch from global profiles to global0 profiles which is implemented by combine_with_ipa_count_within. However this is done on all edges independnetly and it may happen that we end up combining global and globa0 profiles in one functions which is not a good idea. This implements profile_count::combine_with_ipa_count_within which is able to take into account that the counter is inside function with a given count. Bootstrapped/regtested x86_64-linux, comitted. Honza * profile-count.h (profile_count::combine_with_ipa_count_within): Declare. * profile-count.c (profile_count::combine_with_ipa_count_within): New. * cgraphclones.c (cgraph_edge::clone, cgraph_node::create_clone): Use it. Index: profile-count.h =================================================================== --- profile-count.h (revision 278809) +++ profile-count.h (working copy) @@ -1194,6 +1215,10 @@ public: global0. */ profile_count combine_with_ipa_count (profile_count ipa); + /* Same as combine_with_ipa_count but inside function with count IPA2. */ + profile_count combine_with_ipa_count_within + (profile_count ipa, profile_count ipa2); + /* The profiling runtime uses gcov_type, which is usually 64bit integer. Conversions back and forth are used to read the coverage and get it into internal representation. */ Index: profile-count.c =================================================================== --- profile-count.c (revision 278809) +++ profile-count.c (working copy) @@ -383,6 +388,23 @@ profile_count::combine_with_ipa_count (p return this->global0adjusted (); } +/* Sae as profile_count::combine_with_ipa_count but within function with count + IPA2. */ +profile_count +profile_count::combine_with_ipa_count_within (profile_count ipa, + profile_count ipa2) +{ + profile_count ret; + if (!initialized_p ()) + return *this; + if (ipa2.ipa () == ipa2 && ipa.initialized_p ()) + ret = ipa; + else + ret = combine_with_ipa_count (ipa); + gcc_checking_assert (ret.compatible_p (ipa2)); + return ret; +} + /* The profiling runtime uses gcov_type, which is usually 64bit integer. Conversions back and forth are used to read the coverage and get it into internal representation. */ Index: cgraphclones.c =================================================================== --- cgraphclones.c (revision 278809) +++ cgraphclones.c (working copy) @@ -136,8 +141,9 @@ cgraph_edge::clone (cgraph_node *n, gcal /* Update IPA profile. Local profiles need no updating in original. */ if (update_original) - count = count.combine_with_ipa_count (count.ipa () - - new_edge->count.ipa ()); + count = count.combine_with_ipa_count_within (count.ipa () + - new_edge->count.ipa (), + caller->count); symtab->call_edge_duplication_hooks (this, new_edge); return new_edge; } @@ -341,7 +349,14 @@ cgraph_node::create_clone (tree new_decl /* Update IPA profile. Local profiles need no updating in original. */ if (update_original) - count = count.combine_with_ipa_count (count.ipa () - prof_count.ipa ()); + { + if (inlined_to) + count = count.combine_with_ipa_count_within (count.ipa () + - prof_count.ipa (), + inlined_to->count); + else + count = count.combine_with_ipa_count (count.ipa () - prof_count.ipa ()); + } new_node->decl = new_decl; new_node->register_symbol (); new_node->origin = origin;