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: 134113 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp558751vqi; Thu, 10 Aug 2023 10:04:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEtnwnE7dlt1excl5wbrbB4h4xwCEyc6u/gi96L9IE0KR601H07EdGYbeax+jYGjbry8r0o X-Received: by 2002:a17:906:74dc:b0:99d:675e:521d with SMTP id z28-20020a17090674dc00b0099d675e521dmr2435244ejl.67.1691687070181; Thu, 10 Aug 2023 10:04:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691687070; cv=none; d=google.com; s=arc-20160816; b=z3BFpUfbi6UeiPsbAHspm/eFl5ctV3Kd4+8TJlKN2xvKYWe87Ryfzx6t4KJ/GyGzO7 psUlbBf8UqWMJeZ2jiT/A6+X5CLGA9kEjb1r+lw1gvpiIo0WB6A9IXuy64TDsfYBORIA 2c8OOcPNnaZb6y79REDxLlAuYUFbU1ljyMIX7qurXlumCuavQeZmXITNjnQeT/xABvZ2 QiBzauhy/+TJaMuv5IkErD8syYky40Qr//yCtWxb1XVLprx8jZNTO6Xmdyy3GliiduVw giXsONESf4sTLWtAqTHaCCf0OdR5OGJjD9Og1mEzheB+FFcyflVbsBZM8rCuU8Kz7C70 JLVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=VcIF5Rhbqk0ooqjqZAXGn9nu1V63rzjfRiNSH5kvUGg=; fh=KxPrluukuxmHUzYWntxWAHNXePa4vWvGreVeug6Wy5k=; b=BgQmS/g8WGJ3rybbD5B/+ECZg0xXop9huOwLGmBBz9rAFkDWoxK2bd0r2zb9DahEBM cY39r8fz0tT8aeKQXtvlTvmNFBlN8VYiuo2XjDUppMhSWwwjtQByaQw7ifE8DllxeI21 rXEk/s5gFSQGUoPQGTUpb3Lu/FSYL4nIXgMw9TDg2aSZh/qA4Nrh3IKjzQoFkai+UGMF WmsZFiQVue/Qqjt4/48D0/rEQTKMQ6IZTA4/CJEvto5aP9/7zPJzB6I1nB7vi22gfQNN gPE1Skg77IARN4ZM5eNCKuDpu5tXhIZ9DDGXE5RqVIdiwvhNeU72yWVqh1ykhztLjwaT 3i8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xEtigVlO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gu6-20020a170906f28600b0099b4a25c9b5si1888036ejb.450.2023.08.10.10.04.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 10:04:30 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xEtigVlO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D0E623857702 for ; Thu, 10 Aug 2023 17:04:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D0E623857702 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691687068; bh=VcIF5Rhbqk0ooqjqZAXGn9nu1V63rzjfRiNSH5kvUGg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=xEtigVlO7pkWHImlsZXOuRBzC2kC5pG+3dLEvwifwyN4FNcEh9h2cHEhggI9DvrEu EOZJg+z8V5LIz7ykypjA4/U7rdo7nRYABVUHIBnEzBST42SjaKpS6uwqdI/K+VW5tu EwTUe6A2nIdAcCkbFoRgMr/p1EzIdJ5As7zpIW0E= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773862461014382050 X-GMAIL-MSGID: 1773862461014382050 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 ();