diff options
author | Jakub Jelinek <jakub@redhat.com> | 2025-03-26 13:59:16 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2025-03-26 13:59:16 +0100 |
commit | fb71d7c8e7ce4b061e40cd29cd77a4cfd7a256af (patch) | |
tree | 845e5cbcfc2f94a2a4989c71d8031e93d085fed4 | |
parent | 7b7c0fe37332290fad9b31bf3ae05c28375e0a76 (diff) | |
download | gcc-fb71d7c8e7ce4b061e40cd29cd77a4cfd7a256af.zip gcc-fb71d7c8e7ce4b061e40cd29cd77a4cfd7a256af.tar.gz gcc-fb71d7c8e7ce4b061e40cd29cd77a4cfd7a256af.tar.bz2 |
profile: Don't instrument fake exit edges after musttail [PR118442]
When -fprofile-generate is used musttail often fails because the
compiler adds instrumentation after the tail calls.
This patch ignores EDGE_FAKE edges added from musttail calls to EXIT.
2025-03-26 Jakub Jelinek <jakub@redhat.com>
Andi Kleen <ak@gcc.gnu.org>
PR gcov-profile/118442
* profile.cc (branch_prob): Ignore EDGE_FAKE edges from musttail calls
to EXIT.
* c-c++-common/pr118442.c: New test.
-rw-r--r-- | gcc/profile.cc | 14 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/pr118442.c | 17 |
2 files changed, 31 insertions, 0 deletions
diff --git a/gcc/profile.cc b/gcc/profile.cc index acc0ae0..76fed35 100644 --- a/gcc/profile.cc +++ b/gcc/profile.cc @@ -1340,6 +1340,20 @@ branch_prob (bool thunk) EDGE_INFO (e)->ignore = 1; ignored_edges++; } + /* Ignore fake edges after musttail calls. */ + if ((e->flags & EDGE_FAKE) + && e->dest == EXIT_BLOCK_PTR_FOR_FN (cfun)) + { + gimple_stmt_iterator gsi = gsi_last_bb (e->src); + gimple *stmt = gsi_stmt (gsi); + if (stmt + && is_gimple_call (stmt) + && gimple_call_must_tail_p (as_a <const gcall *> (stmt))) + { + EDGE_INFO (e)->ignore = 1; + ignored_edges++; + } + } } /* Create spanning tree from basic block graph, mark each edge that is diff --git a/gcc/testsuite/c-c++-common/pr118442.c b/gcc/testsuite/c-c++-common/pr118442.c new file mode 100644 index 0000000..2472aa6 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr118442.c @@ -0,0 +1,17 @@ +/* PR118442 */ +/* { dg-do compile { target { struct_musttail && { external_musttail && { c || c++11 } } } } } */ +/* { dg-options "-fprofile-generate -O2" } */ +/* { dg-require-profiling "-fprofile-generate" } */ + +struct Span { + int test[5]; +}; + +extern void resolveToBufferSlow (struct Span *buffer); + +void +resolveToBuffer (struct Span *buffer) +{ + buffer->test[0] = 4; + [[clang::musttail]] return resolveToBufferSlow (buffer); +} |