From patchwork Wed Sep 27 14:44:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Trofimovich X-Patchwork-Id: 145402 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2679813vqu; Wed, 27 Sep 2023 07:45:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHqlesKyh7EXnQT+W3U9LdW1CqglOFUTp5S4W8OutOugzbTIi5806xgjUYZrrD/SXIVJpQD X-Received: by 2002:a19:5e5e:0:b0:503:18c3:d874 with SMTP id z30-20020a195e5e000000b0050318c3d874mr1672605lfi.45.1695825916591; Wed, 27 Sep 2023 07:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695825916; cv=none; d=google.com; s=arc-20160816; b=zyqv/k2/6zIqkbV7M/55LFJjX5aMJc+8zC5dN1Nc0C3/Lj000JCNr3M0qOp5DaLXry UekgEAmxFYfqY9eBzmTdQg0yV0R0AANRY1WgpPGmhlcLSxgOjklm7akw4ZzodYFEMZBx cfzzFHxOt85qj00YOAc2B3lpBXl4bj8iXJetZAhKYpUMk0SANsY4Fg9uEORshbR56B18 ZLljgaNz7sXMlOBufQTwXQYN786xE4zUvgq84taEMmW+4FtEEWhwOFvGbpKXOcxxzfNw yQetQsJEddIUfM5SByjigPMZVGbS8iBJ9YtkPYUXxuyeOVQAyJklbkc1KQ37ZmvvNk+H 4jSQ== 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:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=EAwnUVS1w5VSQyhDF4LyORFaTgaAJvRul6O/KRbhVEk=; fh=pH+t6bMN/dJFS3pFFDFc1RgCmJJLCnFkc103Ag9eI3g=; b=DRgFwOh6L4huZXgghW8vflLQSuxB0wi5+7ZyKpiaOLlKIXGo/7jolmqgfIv9VAeOFK 8LUVhrphP3s/0ie+trbZSMGork8ex2JDaTA9rotIQfi6CKY9UJ3/vobS1LuhFz+kpqfo NrYWoGfawulBXId2rGlJPzdUgq8Tv2nenElg3fTSiW8BziCe0BHsESp1+FRC00cVcrJF uuRVpEhDEm7pdFBE0CNGuZ+9s9CYChRGmvbIaRrotupJoFe+xD7twm2fWvquoCU81iuM FWL9BTlTW/TuojB2Z25+RmICImoAIATtSW5N5i7GODEIUEyaGkEduVgkKb0VTU/SwMpn ISpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fp740qNl; 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 i13-20020a056402054d00b005257f2c057esi12853309edx.127.2023.09.27.07.45.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:45:16 -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=fp740qNl; 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 3953938618FE for ; Wed, 27 Sep 2023 14:45:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 260283857B93 for ; Wed, 27 Sep 2023 14:44:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 260283857B93 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-x331.google.com with SMTP id 5b1f17b1804b1-4053c6f0e50so107621345e9.1 for ; Wed, 27 Sep 2023 07:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695825882; x=1696430682; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EAwnUVS1w5VSQyhDF4LyORFaTgaAJvRul6O/KRbhVEk=; b=fp740qNl/Ei3tCwibv++7sQehW5VjbDDzJM6SF5Qw64DnlSn8pkSaFuItcdg8LWzbe gAdoM0RjbJvRPpIweuaHAzcICnpAnClBoUapBpg89YLpTUIWUZuP9rk6d7EEvhnvI3zx FErXeRho6A1iqAsampTwJvemuMezNWT/z2Ovy7Rbp6viOrZTqAk7nFciesqkS1Jjrrv1 ypI5cizmCEUd4u+q4gX8ot50Gawg+0HXPqTOUnSQgsCxah1gewKGwSJ0KF2FGpU8/XAP OgDhB2xjJ+eAlFz5JwDa4f88i0nOmNtTz/VK6IG5m/wvmC9w4HDYAUndJ/+gM+i+PDdm uHag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695825882; x=1696430682; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EAwnUVS1w5VSQyhDF4LyORFaTgaAJvRul6O/KRbhVEk=; b=iFyEyVmGaVkRgSafwFqn1cEThxGRZz/OOuEL/uATc/4555jGdBmju1+FcCDaEvX4Aj YzsHrmzcD/lqRc7xGjyJTk4ocAwkRIJJxYhbm2BSIQZY1ld4yk6MexvbXsCF55xXhK4V cw1N2Iz7AP73wLGxnEpt1SJBvjH+jhhm82Y0g4tBLL/xSgJB3+Ll77f1lSyUi5W3zNbn O1pIDRZvTq//XdzjfZ4LwexgbM7nXSKwrscaJMd9mH/9Xonx5N7cX+R4Lkmct5cB2C6d 1Lg6C2hnBwlS70RnzcAaz+gLWV2wmG06ZSo5hAI7mue3LSGuQpIZM4hl339cNKmNCx4r dl5Q== X-Gm-Message-State: AOJu0YxeJNdYkfkf60bVd7A/54SM5j5vWLRbiqn14PXzP4gt+7mICHey smIEkOsme1zQNoxt8NunKPxTP51zrq0= X-Received: by 2002:a7b:c5c6:0:b0:402:cf9f:c02d with SMTP id n6-20020a7bc5c6000000b00402cf9fc02dmr2205709wmk.8.1695825881490; Wed, 27 Sep 2023 07:44:41 -0700 (PDT) Received: from nz.home (host86-139-202-110.range86-139.btcentralplus.com. [86.139.202.110]) by smtp.gmail.com with ESMTPSA id q12-20020a05600c040c00b0040586360a36sm9577548wmb.17.2023.09.27.07.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:44:41 -0700 (PDT) Received: by nz.home (Postfix, from userid 1000) id 4E822110F4A1C6; Wed, 27 Sep 2023 15:44:40 +0100 (BST) From: Sergei Trofimovich To: gcc-patches@gcc.gnu.org, Jan Hubicka , Richard Biener Cc: Sergei Trofimovich Subject: [PATCH] ipa-utils: avoid generating uninitialized probabilities on merges. Date: Wed, 27 Sep 2023 15:44:38 +0100 Message-ID: <20230927144438.3337173-1-slyich@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, 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: 1778202356245580311 X-GMAIL-MSGID: 1778202356245580311 From: Sergei Trofimovich r14-3459-g0c78240fd7d519 "Check that passes do not forget to define profile" exposed check failures in cases when gcc produces uninitialized profile probabilities. In case of PR/111559 uninitialized profile is generated by edges executed 0 times during profile: __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(); } $ gcc -O2 -fprofile-generate bug.c -o b -fopt-info $ ./b $ gcc -O2 -fprofile-use -fprofile-correction bug.c -o b -fopt-info bug.c: In function 'rule1': bug.c:6:13: error: probability of edge 3->4 not initialized 6 | static void rule1(void) { if (p) edge(); } | ^~~~~ during GIMPLE pass: fixup_cfg bug.c:6:13: internal compiler error: verify_flow_info failed The change conservatively ignores updates with uninitialized values and uses initially assigned probabilities (`always` probability in case of the example). gcc/ PR/111283 PR/111559 * ipa-utils.cc (ipa_merge_profiles): Avoid producing uninitialized probabilities when merging counters with zero denominators. --- gcc/ipa-utils.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gcc/ipa-utils.cc b/gcc/ipa-utils.cc index 956c6294fd7..7c53ae9dd45 100644 --- a/gcc/ipa-utils.cc +++ b/gcc/ipa-utils.cc @@ -651,13 +651,17 @@ ipa_merge_profiles (struct cgraph_node *dst, { edge srce = EDGE_SUCC (srcbb, i); edge dste = EDGE_SUCC (dstbb, i); - dste->probability = + profile_probability merged = dste->probability * dstbb->count.ipa ().probability_in (dstbb->count.ipa () + srccount.ipa ()) + srce->probability * srcbb->count.ipa ().probability_in (dstbb->count.ipa () + srccount.ipa ()); + /* We produce uninitialized probabilities when + denominator is zero: https://gcc.gnu.org/PR111559. */ + if (merged.initialized_p ()) + dste->probability = merged; } dstbb->count = dstbb->count.ipa () + srccount.ipa (); }