From patchwork Thu Oct 5 13:11:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Trofimovich X-Patchwork-Id: 148692 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2016:b0:403:3b70:6f57 with SMTP id fe22csp286567vqb; Thu, 5 Oct 2023 06:12:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEnIf99W5ATgTYm+X4HGzGDdEuqwxkyc/rlovy62lP7DQDXyG5FUMeKL7TsdSNZToHS7LKN X-Received: by 2002:a05:6402:70e:b0:52f:4c92:69ee with SMTP id w14-20020a056402070e00b0052f4c9269eemr5091863edx.36.1696511548345; Thu, 05 Oct 2023 06:12:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696511548; cv=none; d=google.com; s=arc-20160816; b=qUSMsGzxmEMpl4MxkK2PZ1ipGIQrfqd7dKyGX8xBeJ/vcdcreB/41ylqNL7V+C+nF/ 0Y5jLPCeqNEZpsV6I2OfKQFjGWlNS9EEgZuchAaEs+0tCxl5NvnAuXC4hem81bJ/v/r2 iTBwLQfDa+yhKbagTBdDe38RFsyhhe61cLWN97Xo8dph8o96r2bB8ySLdw0+7HZYRA/4 owAufJPE65u67mwETESK/jYtGWH73EvoUTn70sH+u0Al05I9Zcx9IYaaBNtG4fhkCBLz EcCMdM4gh9x/aXgWUoBtZNgRonSPIeHnjD1gL6I/ZBbGYSQbN/cfGCoKvWUD7E6QhUUe xljw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dmarc-filter:delivered-to; bh=8IKBEfoObzovU5ahDg4ASQcQWhn3mAYdZvjh/PbE5xg=; fh=DBwi5ANJKdMzU7ux8GPzDNJgg/ywboNgMuAIT7kgOts=; b=VmMgNbjMPfWHiVZZpruic/WgTNjyBTiEThsGjQ6Z/kkiNSb2OSBJTawZJw/O2NKEEB ZfA1ema3efq1JIB9zYbyb7RpfMX+JBE28XWWTYu6aQffEii/8+tq4pfX4Y+HiNI/TiUw At+bRyHUb5bs7AZfc2wil1g3K1p5tb+0I4jKnPlpMBe9FSrohmsFYPK8i5iDK2c1cJRI htkbIZPMEss1KfYlQkOSzlUgN8Iwacil848u2prw4h/I7ylSD6mpA9L/d3c3/8koQ+T0 iGEM7MpZlDzztR8QQHaCHExEKlgANFoXeax2ffMyNfcEJSMmKf8tdrfXZR1PNw7Qn/BY y4LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Dx7NlHGl; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u25-20020aa7d999000000b00530ba492253si682671eds.101.2023.10.05.06.12.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 06:12:28 -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=@gmail.com header.s=20230601 header.b=Dx7NlHGl; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B0BC38323C4 for ; Thu, 5 Oct 2023 13:12:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id E2536385DC0D for ; Thu, 5 Oct 2023 13:11:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E2536385DC0D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-406650da82bso8389765e9.3 for ; Thu, 05 Oct 2023 06:11:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696511509; x=1697116309; darn=gcc.gnu.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8IKBEfoObzovU5ahDg4ASQcQWhn3mAYdZvjh/PbE5xg=; b=Dx7NlHGl/RNbMEJXjNfIjdGoemgry00+JiTohG2ATHXDTMAyo3IWzL4Esf5uffiZZg fVDrtQ9lY0dsY8xfAOtVvJVjhGukqxin0b2cdmKhpeWbbSNiepReMqwAmDgv+1o7j6MJ qospYZB3G8FHjxGZaE+/T61Gv1Z9GIlagY3FgbyKHzOlZR9sKfnBcGlbjQCQYx2UzwxF JqfZTKENCV7jYZ9xqSy3MLvtQahEt7lzcueIUMfafOfht0AhnWc0XFLLExvBD8ZW6EJP USDAW/75DUeAMxl3i2rVAzVR8OWOqtprqX6/eMJQP742mWQB+HW2JoSj40bCbisw2Rh0 gOtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696511509; x=1697116309; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8IKBEfoObzovU5ahDg4ASQcQWhn3mAYdZvjh/PbE5xg=; b=CbFiz0v7uoesUwqm1RResH1xt5BANE9J2HC19nFJ783UtuZUGC37wvyE0p9gEzhEAb xnuof1RfEAkqgPsyr7rHEKKOEgwxlPrjt5QdVA7NxezWh4leZvD6FICegDndmxFF0xtf uoHfCE8jzsAedkC4+lFsQgoR/L7kRFCwAhHxoDov5uuMTv40qqh3YHTtSRtTVh42IxNa 64h0K36jaaUrGqtF1bP7YijPi2HLG4f0gbBxtcwk8xFkErf9hbxfC+jtMQVoeTg1YQeF OreRxblfKdh+7WrqcOX39dl1u7nuk+kDsLZfIKfO8EEufBRPmuDUBTrBfZLLUXPrwTjW iAsg== X-Gm-Message-State: AOJu0YyLeAFrIw8tLrTn6dT7wX17csQ/ZNo3eOABQGoraQ/1PDut+b3d dSUBlYH3ZjiqRW142tfLQ5NQzeI1dsmfPQ== X-Received: by 2002:a05:600c:d1:b0:406:5396:9f9e with SMTP id u17-20020a05600c00d100b0040653969f9emr4983525wmm.32.1696511509228; Thu, 05 Oct 2023 06:11:49 -0700 (PDT) Received: from nz.home ([2a00:23c8:a613:101:b681:80c1:a81d:5318]) by smtp.gmail.com with ESMTPSA id x9-20020a05600c21c900b003fefe70ec9csm3762228wmj.10.2023.10.05.06.11.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 06:11:48 -0700 (PDT) Received: by nz.home (Postfix, from userid 1000) id 1BD7A11439AEA6; Thu, 5 Oct 2023 14:11:48 +0100 (BST) Date: Thu, 5 Oct 2023 14:11:48 +0100 From: Sergei Trofimovich To: Jan Hubicka Cc: gcc-patches@gcc.gnu.org, rguenther@suse.de, siarheit@google.com Subject: [PATCH v4] ipa-utils: avoid uninitialized probabilities on ICF [PR111559] Message-ID: References: <20230927144438.3337173-1-slyich@gmail.com> <20231001192943.3473530-1-slyich@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778582680055339012 X-GMAIL-MSGID: 1778921293026805122 On Thu, Oct 05, 2023 at 03:04:55PM +0200, Jan Hubicka wrote: > > diff --git a/gcc/ipa-utils.cc b/gcc/ipa-utils.cc > > index 956c6294fd7..1355ccac6f0 100644 > > --- a/gcc/ipa-utils.cc > > +++ b/gcc/ipa-utils.cc > > @@ -651,13 +651,16 @@ ipa_merge_profiles (struct cgraph_node *dst, > > { > > edge srce = EDGE_SUCC (srcbb, i); > > edge dste = EDGE_SUCC (dstbb, i); > > - dste->probability = > > - dste->probability * dstbb->count.ipa ().probability_in > > - (dstbb->count.ipa () > > - + srccount.ipa ()) > > - + srce->probability * srcbb->count.ipa ().probability_in > > - (dstbb->count.ipa () > > - + srccount.ipa ()); > > + profile_count sum = > > + dstbb->count.ipa () + srccount.ipa (); > > + if (sum.nonzero_p ()) > > + dste->probability = > > + dste->probability * dstbb->count.ipa ().probability_in > > + (dstbb->count.ipa () > > + + srccount.ipa ()) > > + + srce->probability * srcbb->count.ipa ().probability_in > > + (dstbb->count.ipa () > > + + srccount.ipa ()); > > looks good. You can use probability_in (sum) > in both of the places. Oh, great point! Completely forgot about it. Attached v4. If it still looks reasonable I'll check again if `python` and `profiledbootstrap` still survives it and will push. diff --git a/gcc/ipa-utils.cc b/gcc/ipa-utils.cc index 956c6294fd7..6024ac69cc2 100644 --- a/gcc/ipa-utils.cc +++ b/gcc/ipa-utils.cc @@ -651,13 +651,14 @@ ipa_merge_profiles (struct cgraph_node *dst, { edge srce = EDGE_SUCC (srcbb, i); edge dste = EDGE_SUCC (dstbb, i); - dste->probability = - dste->probability * dstbb->count.ipa ().probability_in - (dstbb->count.ipa () - + srccount.ipa ()) - + srce->probability * srcbb->count.ipa ().probability_in - (dstbb->count.ipa () - + srccount.ipa ()); + profile_count sum = + dstbb->count.ipa () + srccount.ipa (); + if (sum.nonzero_p ()) + dste->probability = + dste->probability * dstbb->count.ipa ().probability_in + (sum) + + srce->probability * srcbb->count.ipa ().probability_in + (sum); } dstbb->count = dstbb->count.ipa () + srccount.ipa (); } diff --git a/gcc/testsuite/gcc.dg/tree-prof/pr111559.c b/gcc/testsuite/gcc.dg/tree-prof/pr111559.c new file mode 100644 index 00000000000..43202c6c888 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-prof/pr111559.c @@ -0,0 +1,16 @@ +/* { dg-options "-O2" } */ + +__attribute__((noipa)) static void edge(void) {} + +int p = 0; + +__attribute__((noinline)) +static void rule1(void) { if (p) edge(); } + +__attribute__((noinline)) +static void rule1_same(void) { if (p) edge(); } + +__attribute__((noipa)) int main(void) { + rule1(); + rule1_same(); +}