From patchwork Wed Jun 23 11:53:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1496077 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=f1eLCH66; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=5F5fx8uO; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=f1eLCH66; dkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=5F5fx8uO; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G91qv0yBbz9sCD for ; Wed, 23 Jun 2021 21:53:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B85193985425 for ; Wed, 23 Jun 2021 11:53:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id C64C8384F003 for ; Wed, 23 Jun 2021 11:53:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C64C8384F003 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8502E21954; Wed, 23 Jun 2021 11:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1624449182; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=V+hGAP/UIyGEgGeOz+Mj40n5IPoFIxXrKycYmz2rGkg=; b=f1eLCH66gS1MODKbYCGMnVnhwe1aY6coSZ7zowBnpbr6YxzGxg+QH0c0zU+PcAfPhYATSc g+tC7vKICUmKZXY3z0E77UCVSzaALjqTpHbo76+iWDna4UzlBbmZX9kkFTiA0kOrKq1qbD oatmYHGIu9H0Ay0RkdZXgJAb+BIjZAY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1624449182; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=V+hGAP/UIyGEgGeOz+Mj40n5IPoFIxXrKycYmz2rGkg=; b=5F5fx8uOvQ5BZbDrGWuoAGAfY8mWC79xclugZpS8OGSzG2dYbJ7QpxQ7OgvbmqkpU2vjFI FQNF7FfrjOutwEAg== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 5B6F611A97; Wed, 23 Jun 2021 11:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1624449182; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=V+hGAP/UIyGEgGeOz+Mj40n5IPoFIxXrKycYmz2rGkg=; b=f1eLCH66gS1MODKbYCGMnVnhwe1aY6coSZ7zowBnpbr6YxzGxg+QH0c0zU+PcAfPhYATSc g+tC7vKICUmKZXY3z0E77UCVSzaALjqTpHbo76+iWDna4UzlBbmZX9kkFTiA0kOrKq1qbD oatmYHGIu9H0Ay0RkdZXgJAb+BIjZAY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1624449182; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=V+hGAP/UIyGEgGeOz+Mj40n5IPoFIxXrKycYmz2rGkg=; b=5F5fx8uOvQ5BZbDrGWuoAGAfY8mWC79xclugZpS8OGSzG2dYbJ7QpxQ7OgvbmqkpU2vjFI FQNF7FfrjOutwEAg== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id SWLpFJ4g02ClCQAALh3uQQ (envelope-from ); Wed, 23 Jun 2021 11:53:02 +0000 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] inline: do not inline when no_profile_instrument_function is different To: gcc-patches@gcc.gnu.org Message-ID: <4a46257d-91cd-427e-1b11-7599ad36d07f@suse.cz> Date: Wed, 23 Jun 2021 13:53:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Cc: Nick Desaulniers , Jan Hubicka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hello. Similarly to e.g. sanitizer attributes, we sould prevent inlining when one function is marked as not instrumented. We should do that with -fprofile-generate only. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin Adds test-case for: PR gcov-profile/80223 gcc/ChangeLog: * ipa-inline.c (can_inline_edge_p): Similarly to sanitizer options, do not inline when no_profile_instrument_function attributes are different. gcc/testsuite/ChangeLog: * gcc.dg/no_profile_instrument_function-attr-2.c: New test. --- gcc/ipa-inline.c | 10 ++++++++++ .../no_profile_instrument_function-attr-2.c | 15 +++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-2.c diff --git a/gcc/ipa-inline.c b/gcc/ipa-inline.c index 9d896beb2ac..786ab2e7f7f 100644 --- a/gcc/ipa-inline.c +++ b/gcc/ipa-inline.c @@ -396,6 +396,16 @@ can_inline_edge_p (struct cgraph_edge *e, bool report, e->inline_failed = CIF_SANITIZE_ATTRIBUTE_MISMATCH; inlinable = false; } + else if (profile_arc_flag + && lookup_attribute ("no_profile_instrument_function", + DECL_ATTRIBUTES (caller->decl)) + != lookup_attribute ("no_profile_instrument_function", + DECL_ATTRIBUTES (callee->decl))) + { + e->inline_failed = CIF_UNSPECIFIED; + inlinable = false; + } + if (!inlinable && report) report_inline_failed_reason (e); return inlinable; diff --git a/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-2.c b/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-2.c new file mode 100644 index 00000000000..586962a1c76 --- /dev/null +++ b/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-2.c @@ -0,0 +1,15 @@ +/* { dg-require-effective-target global_constructor } */ +/* { dg-options "-O2 -fprofile-generate -fprofile-update=single -fdump-tree-optimized" } */ + +__attribute__ ((no_profile_instrument_function)) +int foo() +{ + return 0; +} + +int bar() +{ + return foo(); +} + +/* { dg-final { scan-tree-dump-times " = foo \\(\\)" 1 "optimized"} } */