From patchwork Tue Mar 14 08:11:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1756725 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=M/7znLGg; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PbR7r5W4sz1yWp for ; Tue, 14 Mar 2023 19:11:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 633D53858C30 for ; Tue, 14 Mar 2023 08:11:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 633D53858C30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678781508; bh=oIi4XnELF0EnwNO5wx8UfCY/QyyZ/p3jxHGwaGYk2Dc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=M/7znLGg/UbxPKmbW6pERpZBDXd1+opfPS4OyKPd5Y70X6hT013SpUafILb3n+SG6 bjA26j2V8rEL5QOgnm2ZLerkTY47M7tAh6BueasAYtLRby14hm4OfPXvXCvrhNxqja se9YGbjQRWYugKzXC01inVqD7Zp6hpm011NtpIyo= 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 A98FE3858C5F for ; Tue, 14 Mar 2023 08:11:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A98FE3858C5F Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 62F1928A182; Tue, 14 Mar 2023 09:11:24 +0100 (CET) Date: Tue, 14 Mar 2023 09:11:24 +0100 To: gcc-patches@gcc.gnu.org Subject: Fix ICE in profile_count::to_sreal_frequency 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 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" As discussed in the PR log, profile_count::to_cgraph_frequency was originally intended to work across function boundary and has some extra logic and sanity check for that. It is used only within single function and with current API it can not really work well globally, so this patch synchronizes its implementation with probability_in which does similar job but to determine relative probability. Bootstrpped/regtested x86_64-linux, and also profilebootstrapped. Comitted. gcc/ChangeLog: 2023-03-14 Jan Hubicka PR tree-optimization/106896 * profile-count.cc (profile_count::to_sreal_scale): Synchronize implementatoin with probability_in; avoid some asserts. diff --git a/gcc/profile-count.cc b/gcc/profile-count.cc index d05fef3fb00..16585045f8e 100644 --- a/gcc/profile-count.cc +++ b/gcc/profile-count.cc @@ -325,6 +325,13 @@ profile_count::to_cgraph_frequency (profile_count entry_bb_count) const sreal profile_count::to_sreal_scale (profile_count in, bool *known) const { + if (*this == zero () + && !(in == zero ())) + { + if (known) + *known = true; + return 0; + } if (!initialized_p () || !in.initialized_p ()) { if (known) @@ -333,32 +340,13 @@ profile_count::to_sreal_scale (profile_count in, bool *known) const } 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) + if (*this == in) return 1; gcc_checking_assert (compatible_p (in)); - + if (m_val == in.m_val) + return 1; if (!in.m_val) - { - if (!m_val) - return 1; - return m_val * 4; - } + return m_val * 4; return (sreal)m_val / (sreal)in.m_val; }