From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 65A0C3858D39 for ; Thu, 27 Jul 2023 14:19:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 65A0C3858D39 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kam.mff.cuni.cz Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 6FF4D282ADE; Thu, 27 Jul 2023 16:19:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1690467597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=60iCTojOVwuPPcbX2iRQMDiJ4atLJxq6p268rzRbnvg=; b=PIc5ULk/chZPIG2IPcpBf63S2JsyZUrtnjiY9i0/5k6Fomo2c8NiLJA8BciOggQsrsQTHB Y752gx0MVMXsemjbYwPgv+mEc/eFH763v3rFOrdHyY6sHffcLkn8ucasi2eNUI8EtvPhju EjKj+o/aQhtSsqdctOtXqQciEot+4pw= Date: Thu, 27 Jul 2023 16:19:57 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix profile_count::apply_probability Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,JMQ_SPF_NEUTRAL,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, profile_count::apply_probability misses check for uninitialized probability which leads to completely random results on applying uninitialized probability to initialized scale. This can make difference when i.e. inlining -fno-guess-branch-probability function to -fguess-branch-probability one. Boootstrapped/regtested x86_64-linux, commited. gcc/ChangeLog: * profile-count.h (profile_count::apply_probability): Fix handling of uninitialized probabilities, optimize scaling by probability 1. diff --git a/gcc/profile-count.h b/gcc/profile-count.h index bf1136782a3..e860c5db540 100644 --- a/gcc/profile-count.h +++ b/gcc/profile-count.h @@ -1129,11 +1132,11 @@ public: /* Scale counter according to PROB. */ profile_count apply_probability (profile_probability prob) const { - if (*this == zero ()) + if (*this == zero () || prob == profile_probability::always ()) return *this; if (prob == profile_probability::never ()) return zero (); - if (!initialized_p ()) + if (!initialized_p () || !prob.initialized_p ()) return uninitialized (); profile_count ret; uint64_t tmp;