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 D0F083858D32 for ; Thu, 10 Aug 2023 17:03:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D0F083858D32 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 0A1CF281310; Thu, 10 Aug 2023 19:03:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1691687025; 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=VcIF5Rhbqk0ooqjqZAXGn9nu1V63rzjfRiNSH5kvUGg=; b=avOfWqp+abZztcblDySXsG8YA4Wgj/uvx+Q2t0RKAJzutCNyRTcY6V+Up5Wf8IRyjBP2mr /XLCyeRGHfwbFZ/8HcL1b9sCxlbw1Gku6vf6qQbt4nE0haIjtXmN1HpjtP8Za7YjUkPFit kkoFEhPuYne7uwZfxaImed90nlhEAkE= Date: Thu, 10 Aug 2023 19:03:44 +0200 From: Jan Hubicka 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-Type: text/plain; charset=us-ascii 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 List-Id: 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 ();