From patchwork Thu Nov 28 17:32:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1202246 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-514788-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="Yk2HVA1h"; 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 47P4TM6djCz9sP4 for ; Fri, 29 Nov 2019 04:32:21 +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=cnzy5cuHX4IEz4fLWe1LK59KJfuPXQtm7PVKrHjdwBSWaKHtOwKNJ ihGxDcnq6YNbDLyIGytuPBDZOwmj8Gb4ogf+GPfE/CUEWa67xHvqQlOPAKBlIKJ0 +2q0H2N4hE4u1eudqImM6//vaEAH+vhZiP6pD9aG+eEH3t4SxeIuIo= 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=fdh8RbV2eEERZSE9UBw+5QcDoPI=; b=Yk2HVA1hrnxDCI5JtZlG UoxAEuceeU7lzmn6wWE/Sx5ANF/bgQg1KqPA04nUWjC29IV5D/D+nbp33qVVnhuL 25wEysbv0m4NQs+qQRjaIwDO2PlRyropYGQyfuFtBpQJiRcl3WBVD8cuK1/V30BH FKSHwqsapj6OfHsnxYH3XKA= Received: (qmail 80493 invoked by alias); 28 Nov 2019 17:32:14 -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 80485 invoked by uid 89); 28 Nov 2019 17:32:14 -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=prof 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 17:32:12 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 16484280823; Thu, 28 Nov 2019 18:32:10 +0100 (CET) Date: Thu, 28 Nov 2019 18:32:10 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Add sanity checking for profile counter compatibility Message-ID: <20191128173210.pyatmml4ysbilcf5@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Hi, this patch adds sanity checks with uncovered all the latent bugs I fixed today. I will add similar checking to cfg profile, too, and also few unit tests. Bootstrapped/regtested x86_64-linux, plan to commit it shortly. * profile-count.c (profile_count::to_cgraph_frequency, profile_count::to_sreal_scale): Check for compaibility of counts. * profile-count.h (compatible_p): Make public; add checking for global0 versus global types. * cgraph.c (cgraph_node::verify_node): Verify count compatibility. Index: profile-count.c =================================================================== --- profile-count.c (revision 278814) +++ profile-count.c (working copy) @@ -291,6 +292,7 @@ profile_count::to_cgraph_frequency (prof return 0; gcc_checking_assert (entry_bb_count.initialized_p ()); uint64_t scale; + gcc_checking_assert (compatible_p (entry_bb_count)); if (!safe_scale_64bit (!entry_bb_count.m_val ? m_val + 1 : m_val, CGRAPH_FREQ_BASE, MAX (1, entry_bb_count.m_val), &scale)) return CGRAPH_FREQ_MAX; @@ -328,6 +330,7 @@ profile_count::to_sreal_scale (profile_c return 0; if (m_val == in.m_val) return 1; + gcc_checking_assert (compatible_p (in)); if (!in.m_val) { Index: profile-count.h =================================================================== --- profile-count.h (revision 278814) +++ profile-count.h (working copy) @@ -700,6 +700,7 @@ private: uint64_t UINT64_BIT_FIELD_ALIGN m_val : n_bits; #undef UINT64_BIT_FIELD_ALIGN enum profile_quality m_quality : 3; +public: /* Return true if both values can meaningfully appear in single function body. We have either all counters in function local or global, otherwise @@ -711,9 +712,18 @@ private: if (*this == zero () || other == zero ()) return true; + /* Do not allow nonzero global profile together with local guesses + that are globally0. */ + if (ipa ().nonzero_p () + && !(other.ipa () == other)) + return false; + if (other.ipa ().nonzero_p () + && !(ipa () == *this)) + return false; + return ipa_p () == other.ipa_p (); } -public: + /* Used for counters which are expected to be never executed. */ static profile_count zero () { Index: cgraph.c =================================================================== --- cgraph.c (revision 278814) +++ cgraph.c (working copy) @@ -3061,6 +3061,13 @@ cgraph_node::verify_node (void) error ("inline clone in same comdat group list"); error_found = true; } + if (inlined_to && !count.compatible_p (inlined_to->count)) + { + error ("inline clone count is not compatible"); + count.debug (); + inlined_to->count.debug (); + error_found = true; + } if (!definition && !in_other_partition && local) { error ("local symbols must be defined"); @@ -3089,6 +3096,13 @@ cgraph_node::verify_node (void) identifier_to_locale (e->caller->name ())); error_found = true; } + if (!e->count.compatible_p (count)) + { + error ("edge count is not compatible with function count"); + e->count.debug (); + count.debug (); + error_found = true; + } if (!e->indirect_unknown_callee || !e->indirect_info) { @@ -3137,6 +3151,13 @@ cgraph_node::verify_node (void) { if (e->verify_count ()) error_found = true; + if (!e->count.compatible_p (count)) + { + error ("edge count is not compatible with function count"); + e->count.debug (); + count.debug (); + error_found = true; + } if (gimple_has_body_p (e->caller->decl) && !e->caller->inlined_to && !e->speculative