From patchwork Thu Aug 10 17:03:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1819982 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=server2.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=VyWQorrf; dkim-atps=neutral Received: from server2.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 4RMCvG1gktz1yfB for ; Fri, 11 Aug 2023 03:04:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F2FB13857B8E for ; Thu, 10 Aug 2023 17:04:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F2FB13857B8E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691687046; bh=VcIF5Rhbqk0ooqjqZAXGn9nu1V63rzjfRiNSH5kvUGg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=VyWQorrfanj2jLDj2s+PKtJPY9KzA3nsGB8m4NZbC0Z75hbUeCe8cxUfEP9ZzIJ8g l2lHgHj8YcyS9xBn67qo84Md1ukrd8lVLnxHf/qVhZ2sHjoZvuwxhIR8G6OHUL2bGc 6xXQRDBxO+vGMmkMoYD49sEBHGNXg2D8dfnKjjXc= 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 D0F083858D32 for ; Thu, 10 Aug 2023 17:03:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D0F083858D32 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 0A1CF281310; Thu, 10 Aug 2023 19:03:44 +0200 (CEST) Date: Thu, 10 Aug 2023 19:03:44 +0200 To: gcc-patches@gcc.gnu.org Subject: Fix profile update in duplicat_loop_body_to_header_edge for loops with 0 count_in Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.1 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 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" Hi, this patch makes duplicate_loop_body_to_header_edge to not drop profile counts to uninitialized when count_in is 0. This happens because profile_probability in 0 count is undefined. Bootstrapped/regtested x86_64-linux, committed. gcc/ChangeLog: * cfgloopmanip.cc (duplicate_loop_body_to_header_edge): Special case loops with 0 iteration count. diff --git a/gcc/cfgloopmanip.cc b/gcc/cfgloopmanip.cc index b237ad4e8ac..a2ed54a23bb 100644 --- a/gcc/cfgloopmanip.cc +++ b/gcc/cfgloopmanip.cc @@ -1296,6 +1296,16 @@ duplicate_loop_body_to_header_edge (class loop *loop, edge e, } profile_probability prob_pass_wont_exit = new_count_le.probability_in (count_in); + /* If profile count is 0, the probability will be uninitialized. + We can set probability to any initialized value to avoid + precision loss. If profile is sane, all counts will be 0 anyway. */ + if (!count_in.nonzero_p ()) + { + prob_pass_thru + = profile_probability::always ().apply_scale (1, 2); + prob_pass_wont_exit + = profile_probability::always ().apply_scale (1, 2); + } scale_step = XNEWVEC (profile_probability, ndupl); @@ -1306,7 +1316,9 @@ duplicate_loop_body_to_header_edge (class loop *loop, edge e, /* Complete peeling is special as the probability of exit in last copy becomes 1. */ - if (flags & DLTHE_FLAG_COMPLETTE_PEEL) + if (!count_in.nonzero_p ()) + ; + else if (flags & DLTHE_FLAG_COMPLETTE_PEEL) { profile_count wanted_count = e->count ();