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: 66986 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 60D283858431 for ; Tue, 28 Mar 2023 08:06:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 60D283858431 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679990802; bh=bSnmicrcN4gfnn3elUjGcChrDfmh6D3LOeRjkBLneeg=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=lnnsSCNjyTlqvBx2tPtb9QktUmCwO+XgGbKpEdeQ2iSie31Xg0SwEuIHTi2BEpHG8 MrEjShGsclaBPcJHjsGUuerqaMyc9L2BZaxL1ulv/eeAvzWu5nhv+nq4MLtzBghgTS 7pGcxd9Ur4Rca7lxuUYiMwv+o2WmLEHAJoB15NAc= 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230328080642.60D283858431@sourceware.org> 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