From patchwork Sun Oct 1 19:29:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Trofimovich X-Patchwork-Id: 147149 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1023425vqb; Sun, 1 Oct 2023 12:30:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZquHhy/mQuj65pTOxOG8LUleSJjXsH/lG1WlvksQlklhujckAYe8OLpJSAGztbzGCI+Nz X-Received: by 2002:a05:6402:6d4:b0:52c:92e3:1d12 with SMTP id n20-20020a05640206d400b0052c92e31d12mr9448693edy.11.1696188621524; Sun, 01 Oct 2023 12:30:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696188621; cv=none; d=google.com; s=arc-20160816; b=vk7YrArD/zqrcqkDJKSiilijDZl438Hy0Xkm4gopBazZyhLSLQJw1d1D5j+dKnOd33 X2bFPFh+nIe8N/oihQU2cDxvLx6MXlzBXoDwBqfKYb9P1vVN7CG9T1Qlca1Cxl/743Lq VCBBdhETY9A2qNYJ4Ewy0VxEZ8z5yOJB19EkgUhFYRBFAgL2X+m18laySzDurA2LcruZ AuQN28tGPG86MkYfs+N3NYWWJaYCWQX8keI9li+EBJVANOqgEtj/qhW6MduDq2LwZQdm PyGNMgRZfE/Cd8bYOhAeySR5d15LzhnRqCQ5pHx3ls/L1wPNQ+W6yATcgEmjZjqubTTy x6CA== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=mlpMjRl8M0lvOUwt/+TvMrpQ27r8orFgGNPWH8B68fA=; fh=aWBIgxscryt6mLxFLSQBo8sCMKOUleEdeDWlYkCGkmY=; b=v+X/sBK0wUfWNCAJexSUMNC1mvdbDLNPyhGN069/qey9pKLxJr5atM/8fk4Fq9TWfb zW6uEuEKyZNPd/sA/Q2+aso4PLeZe+9isMKNW6IOWBiZS111TA2OIKyXholEFToImfoL tKi2d+7TZf9jCUTbqFld4q7nWFIvuWjO5M3mpIl++bV0pWXuDuduqxZp5z0ocXmRf2Q/ T8jw8D+V5pS1h0wZXbXHPpLxC7gLvTsnZ/06Zsi4I9lpnGNWCjbP/QI6zPxjUGkRoaWw zzLDchh+8FaL4yJZ9GimsWA2+d6VcBsm7yjuCANHFd6gLSuqwKraett0gHB6t97TStri YLKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jeq27dwA; 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 e4-20020a056402148400b00532d2b51266si17823610edv.468.2023.10.01.12.30.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 12:30:21 -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=jeq27dwA; 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 A0AB9385B512 for ; Sun, 1 Oct 2023 19:30:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id B01783858C2A for ; Sun, 1 Oct 2023 19:29:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B01783858C2A 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-wr1-x42f.google.com with SMTP id ffacd0b85a97d-32336a30d18so7648639f8f.2 for ; Sun, 01 Oct 2023 12:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696188590; x=1696793390; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mlpMjRl8M0lvOUwt/+TvMrpQ27r8orFgGNPWH8B68fA=; b=jeq27dwAglYMYVtfIfGuI4ckeuSbg82WBL+gwolq5HluTGXwGfzJa4Xa654DaX2Wgb ka1+CEoDjINsjq17S0Uiilz8esTKr7GlybpefDwvsw16avTHIeXchgMCIfAHTTuLbo4c PIAUQ9jXt1vPMZRPraBkX27a0IyZwUOqGlDal4hsP0OxXo3M+EuOItnlORl1i9NRvQPB 5rgMS067wCUTkPP5nWt4x01vnOTjr2YE84cstFHJnE2u6FHhA9xt9kxUC6oA4O5Q/JBA ujDiJkwoSmIkxAYzyQOZ3moTJUmuHfJYjWb3vFo/57zDCB4eh6p2Sp0bEEhz5XN3FkLM We3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696188590; x=1696793390; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mlpMjRl8M0lvOUwt/+TvMrpQ27r8orFgGNPWH8B68fA=; b=ZfiRjnNbGPgw4xzNLC4CuS6NT3EawJ0C/6QROoQuy+KSm9+lW2x3qH/LNbrRHccgRj oVm1d0xJVBmXNyVy6fxxXziHEveY/ssdIpmzatUugdnFBzt1P26Ya7hbFHiJVOWB65zV OB8QSTjEtLnI5zU/AVlQf1zSBz/A/fpSb3Ueod8YwvleseBrw/59R+DcgCtL6siCeXwa lb+q41fg+uXDOcY4TVVmx/vMDR3OayM0KAyJ9T22ksaH8ypWFfj5ApNloS3rvQGKfhQb pX4N4QP0gIwc6v5nJN2svfd63C4cPOCpYbPVBcSOU7JAxE1mkW5gtde++eJePuAZ4DoI QtRQ== X-Gm-Message-State: AOJu0Yzg98MrVhIr8wBHQOW8OObGOF/aqiBCcAF3K+cWk+V9CllQO6wB 3Kk3I8ywyE5evDPJkl8yfqPuD9I7lkVCxQ== X-Received: by 2002:a5d:5082:0:b0:319:68ce:2c53 with SMTP id a2-20020a5d5082000000b0031968ce2c53mr8095281wrt.25.1696188589888; Sun, 01 Oct 2023 12:29:49 -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 o5-20020adfeac5000000b0031984b370f2sm26295265wrn.47.2023.10.01.12.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 12:29:49 -0700 (PDT) Received: by nz.home (Postfix, from userid 1000) id E293C11293C102; Sun, 1 Oct 2023 20:29:48 +0100 (BST) From: Sergei Trofimovich To: gcc-patches@gcc.gnu.org Cc: slyich@gmail.com, hubicka@ucw.cz, rguenther@suse.de, siarheit@google.com Subject: [PATCH v2] ipa-utils: avoid uninitialized probabilities on ICF [PR111559] Date: Sun, 1 Oct 2023 20:29:43 +0100 Message-ID: <20231001192943.3473530-1-slyich@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230927144438.3337173-1-slyich@gmail.com> References: <20230927144438.3337173-1-slyich@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 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: 1778582680055339012 X-GMAIL-MSGID: 1778582680055339012 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 reported by IPA profile: $ gcc -O2 -fprofile-generate pr111559.c -o b -fopt-info $ ./b $ gcc -O2 -fprofile-use -fprofile-correction pr111559.c -o b -fopt-info pr111559.c: In function 'rule1': pr111559.c:6:13: error: probability of edge 3->4 not initialized 6 | static void rule1(void) { if (p) edge(); } | ^~~~~ during GIMPLE pass: fixup_cfg pr111559.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). PR ipa/111283 PR gcov-profile/111559 gcc/ * ipa-utils.cc (ipa_merge_profiles): Avoid producing uninitialized probabilities when merging counters with zero denominators. gcc/testsuite/ * gcc.dg/tree-prof/pr111559.c: New test. --- gcc/ipa-utils.cc | 6 +++++- gcc/testsuite/gcc.dg/tree-prof/pr111559.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-prof/pr111559.c 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 (); } 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(); +}