From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 92641382CC17; Tue, 17 Aug 2021 12:15:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92641382CC17 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/PR80223-pgo-attr-do-not-inline-v2)] inline: do not einline when no_profile_instrument_function is different X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/users/marxin/heads/PR80223-pgo-attr-do-not-inline-v2 X-Git-Oldrev: 891bdbf2b0432b4aa3d3e76923617fcb4fd33cf6 X-Git-Newrev: 2e4fb87072abf07acd7384a338b1c83408c7985f Message-Id: <20210817121527.92641382CC17@sourceware.org> Date: Tue, 17 Aug 2021 12:15:27 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Aug 2021 12:15:27 -0000 https://gcc.gnu.org/g:2e4fb87072abf07acd7384a338b1c83408c7985f commit 2e4fb87072abf07acd7384a338b1c83408c7985f Author: Martin Liska Date: Tue Jun 22 10:09:01 2021 +0200 inline: do not einline when no_profile_instrument_function is different 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 in early inliner. It's fine to inline it after PGO instrumentation. gcc/testsuite/ChangeLog: * gcc.dg/no_profile_instrument_function-attr-2.c: New test. Diff: --- gcc/ipa-inline.c | 17 +++++++++++++++++ .../gcc.dg/no_profile_instrument_function-attr-2.c | 15 +++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/gcc/ipa-inline.c b/gcc/ipa-inline.c index 413446bcc46..012b326b5e9 100644 --- a/gcc/ipa-inline.c +++ b/gcc/ipa-inline.c @@ -396,6 +396,23 @@ 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)) == NULL_TREE) + != (lookup_attribute ("no_profile_instrument_function", + DECL_ATTRIBUTES (callee->decl)) == NULL_TREE)) + { + cgraph_node *origin = caller; + while (origin->clone_of) + origin = origin->clone_of; + + if (!DECL_STRUCT_FUNCTION (origin->decl)->always_inline_functions_inlined) + { + 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..472eca88efd --- /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-not" = foo \\(\\)" "optimized"} } */