From patchwork Tue Mar 28 08:06:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 75888 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2046573vqo; Tue, 28 Mar 2023 01:06:58 -0700 (PDT) X-Google-Smtp-Source: AKy350ZJo3vk0gqCHypO6aL+UAsPV+BgRApS6qn+i2TH++sNlKcWrvRRIxHHE3TRCNC+HMd67Kdy X-Received: by 2002:a05:6402:194:b0:4fe:9bba:1d65 with SMTP id r20-20020a056402019400b004fe9bba1d65mr18769234edv.21.1679990818803; Tue, 28 Mar 2023 01:06:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679990818; cv=none; d=google.com; s=arc-20160816; b=aoxhJfbbbOB6NHr71bcV66TTUHkoPDt8z5tOB4kytKwBgqbA9N2+LzZhy3TrRemLiA R9HiwgiScK3zHnIjtQYxbpkVAO1/2qv0Q/eRVupt1mE5IVpVmeHN6RrCeRSQrrYGA3vJ IPduF9/rhqgZ2Zovjh6O1MG9Nj7RSjbq+i5jEggtydhuNA2pUG++3yXF5dsT8R8ja2LN KUFi4FRsZdFH7rNA+hRKGToKviMtXB609tqzeN0rPjCIP8dvGFc/jDGK7X7Gka6usMPG ec6rawq9Sy/VV4J3TwInHh2dMxJNN1MXE61GpNnk3vd+Apcdc3LKEMwWnE3utOKztaQs rLhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:cc:to:date:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=bSnmicrcN4gfnn3elUjGcChrDfmh6D3LOeRjkBLneeg=; b=x97DL/XN4A1px7/ol8Cd9/dW2KJY2oqpP9nakQkLYXpqJUuVYLeW8R0MTvu+zr7Vut wOLaa1G51Vb1UJiIqeMeMwCS3Q/Yb6iDF1rUGfhfGIvkwzN31fXKANFyvJvOvyOSHBre esggK+v2AkZ0aceUfRVeUBUqiyKXkJ/9/f/f/iThYzj7SF7O7FfHBfObX+smtxm4aOna QkQsmmc2IT6sZGbgA1Yja0HU2Wawv3hyktfxn7BeKOLMcpqUw8kOWprtGi8uTUARCFH2 yc6YJZvMh84oUpX6rt8KCrK7m7D07NM8nXY1To4GKJGDd2PWi3CO0BYp7W3DUbabfyko k+qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=H2Fok0Ly; 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g1-20020a056402180100b005021f0d5758si12278458edy.671.2023.03.28.01.06.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 01:06:58 -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=H2Fok0Ly; 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 773873858296 for ; Tue, 28 Mar 2023 08:06:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 773873858296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679990817; bh=bSnmicrcN4gfnn3elUjGcChrDfmh6D3LOeRjkBLneeg=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=H2Fok0LyP9yajO1z6lHF4kFYEiqzRIPP8Syy9dPYCDNcU2kZ66XUAEYVOOWF8V0Pq YegM1ty6Z3NJHli3r21YunFfbeNwy4KQ4dN+243NwpFmV+0KRZ90955TJjut5BRymK Tehf8vce1hj3Mys9tfQN/vH5p6N/BYTMsBF6NKSo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 849C53858281 for ; Tue, 28 Mar 2023 08:06:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 849C53858281 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 5299E1F8A6; Tue, 28 Mar 2023 08:06:12 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 405B22C141; Tue, 28 Mar 2023 08:06:12 +0000 (UTC) Date: Tue, 28 Mar 2023 08:06:12 +0000 (UTC) To: gcc-patches@gcc.gnu.org cc: Jan Hubicka Subject: [PATCH] tree-optimization/109304 - properly handle instrumented aliases User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230328080657.773873858296@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761598052809941225?= X-GMAIL-MSGID: =?utf-8?q?1761598052809941225?= When adjusting calls to reflect instrumentation we failed to handle calls to aliases since they appear to have no body. Instead resort to symtab node availability. The patch also avoids touching internal function calls in a more obvious way (builtins might have a body available). profiledbootstrap & regtest running on x86_64-unknown-linux-gnu. Honza - does this look OK? PR tree-optimization/109304 * tree-profile.cc (tree_profiling): Use symtab node availability to decide whether to skip adjusting calls. Do not adjust calls to internal functions. * gcc.dg/pr109304.c: New testcase. --- gcc/testsuite/gcc.dg/pr109304.c | 12 ++++++++++++ gcc/tree-profile.cc | 9 ++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr109304.c diff --git a/gcc/testsuite/gcc.dg/pr109304.c b/gcc/testsuite/gcc.dg/pr109304.c new file mode 100644 index 00000000000..d435b04d4d5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr109304.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-require-profiling "-fprofile-generate" } */ +/* { dg-require-effective-target fpic } */ +/* { dg-options "-O3 -fprofile-generate -fPIC -fno-semantic-interposition" } */ + +int PyUnicode_FindChar_i; +int PyUnicode_FindChar() +{ + while (PyUnicode_FindChar_i) + if (PyUnicode_FindChar()) + break; +} diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc index 6f9a43e4bd5..da300d5f9e8 100644 --- a/gcc/tree-profile.cc +++ b/gcc/tree-profile.cc @@ -808,7 +808,7 @@ tree_profiling (void) { if (!gimple_has_body_p (node->decl) || !(!node->clone_of - || node->decl != node->clone_of->decl)) + || node->decl != node->clone_of->decl)) continue; /* Don't profile functions produced for builtin stuff. */ @@ -842,12 +842,15 @@ tree_profiling (void) for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { gcall *call = dyn_cast (gsi_stmt (gsi)); - if (!call) + if (!call || gimple_call_internal_p (call)) continue; /* We do not clear pure/const on decls without body. */ tree fndecl = gimple_call_fndecl (call); - if (fndecl && !gimple_has_body_p (fndecl)) + cgraph_node *callee; + if (fndecl + && (callee = cgraph_node::get (fndecl)) + && callee->get_availability (node) == AVAIL_NOT_AVAILABLE) continue; /* Drop the const attribute from the call type (the pure