From patchwork Thu Nov 28 08:30:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1201952 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-514758-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="x+ZTl9OX"; 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 47NrSJ56txz9sP6 for ; Thu, 28 Nov 2019 19:30:40 +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=utE2HmMUOKhB5cdibZst+LX/SeDvsDYCF8PxWEitNkd13BpkUos60 bKRssXo9bPduzs4NrxSNQekWtmGtZABz0FJ3INQ/cs1Y+3jse4qbYcUsOP2QqTqG TN0dt3T325fKX/ziqtQJV3bm7T57TfgF0R/hnqovwiAvtBZpqUU0oo= 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=kAEPY6wM4wQsxZ4rqSxS/nHId+M=; b=x+ZTl9OXtMm1alSQjs/e geGb6hxV51oDVKdLc7omcVn2zMdJOEKnovGwksPA8IIEoYmVUVTCl6hwUPSj2G16 +wCVEwz9RbugifqCoIonL5CabPs9H5vFNzSqzZNlwweiQurxiV9Wpe8EFjqZxOkC zuF9q8wmPICncUER2xzhoEM= Received: (qmail 122946 invoked by alias); 28 Nov 2019 08:30:32 -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 122888 invoked by uid 89); 28 Nov 2019 08:30:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=profile-count.c, profilecountc, UD:profile-count.c, tracked 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 08:30:24 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id DA911280822; Thu, 28 Nov 2019 09:30:21 +0100 (CET) Date: Thu, 28 Nov 2019 09:30:21 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Handle correctly global0 and global counters in profile_count::to_sreal_scale Message-ID: <20191128083021.halyv64mwwundvrv@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Hi, This patch fixes problem in profile_count::to_sreal_scale. We our porfile counters can be function local, global (ipa) or function local but globally 0. The last is used to hold static estimates for functions executed 0 times in profile. Now only one 64bit value is stored and if we compute frequency of global0 counter in global counter we mix them up and return non-zero value incorrectly. I also implemented unit test, but will commit sanity checking separately from fixes: there are multiple bugs in this area I tracked down. Bootstrapped/regtested x86_64-linux, comitted. Honza * profile-count.c (profile_count::to_sreal_scale): Handle correctly combination of globa0 and global counters.. Index: profile-count.c =================================================================== --- profile-count.c (revision 278681) +++ profile-count.c (working copy) @@ -310,6 +311,20 @@ profile_count::to_sreal_scale (profile_c } if (known) *known = true; + /* Watch for cases where one count is IPA and other is not. */ + if (in.ipa ().initialized_p ()) + { + gcc_checking_assert (ipa ().initialized_p ()); + /* If current count is inter-procedurally 0 and IN is inter-procedurally + non-zero, return 0. */ + if (in.ipa ().nonzero_p () + && !ipa().nonzero_p ()) + return 0; + } + else + /* We can handle correctly 0 IPA count within locally estimated + profile, but otherwise we are lost and this should not happen. */ + gcc_checking_assert (!ipa ().initialized_p () || !ipa ().nonzero_p ()); if (*this == zero ()) return 0; if (m_val == in.m_val)