Hello. During investigation of another issue, I accidentally came a profile inconsistency mentioned in the PR. Problem is that flag_ipa_bit_cp is enabled in use stage of PGO and not in instrumentation stage. That causes ccp1 to find nonzero bits and that leads to a CFG changes as a condition can be folded away.
Solution is to enable the same flag in generate phase. However I've got one more question: In -fprofile-generate we have 2 more functions available in symtab: _GLOBAL__sub_I_00100_0_c () { <bb 2> [0.00%]: __gcov_init (&*.LPBX0); return; } _GLOBAL__sub_D_00100_1_c () { <bb 2> [0.00%]: __gcov_exit (); return; } I'm wondering whether it can potentially influence early inlining decision? Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. Ready to be installed? Martin
>From 170193b48d41b90bc8b0f73a7dce2c1933430fc1 Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Mon, 30 Jan 2017 10:55:36 +0100 Subject: [PATCH] Fix profile corruption with -O1 (PR gcov-profile/79259) gcc/ChangeLog: 2017-01-30 Martin Liska <mli...@suse.cz> PR gcov-profile/79259 * opts.c (common_handle_option): Enable flag_ipa_bit_cp w/ -fprofile-generate. gcc/testsuite/ChangeLog: 2017-01-30 Martin Liska <mli...@suse.cz> PR gcov-profile/79259 * g++.dg/tree-prof/pr79259.C: New test. --- gcc/opts.c | 2 ++ gcc/testsuite/g++.dg/tree-prof/pr79259.C | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 gcc/testsuite/g++.dg/tree-prof/pr79259.C diff --git a/gcc/opts.c b/gcc/opts.c index 5f573a16ff1..b38e9b4f3a7 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -2150,6 +2150,8 @@ common_handle_option (struct gcc_options *opts, opts->x_flag_profile_values = value; if (!opts_set->x_flag_inline_functions) opts->x_flag_inline_functions = value; + if (!opts_set->x_flag_ipa_bit_cp) + opts->x_flag_ipa_bit_cp = value; /* FIXME: Instrumentation we insert makes ipa-reference bitmaps quadratic. Disable the pass until better memory representation is done. */ diff --git a/gcc/testsuite/g++.dg/tree-prof/pr79259.C b/gcc/testsuite/g++.dg/tree-prof/pr79259.C new file mode 100644 index 00000000000..a55172b62d2 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-prof/pr79259.C @@ -0,0 +1,20 @@ +/* { dg-options "-O1" } */ + +inline bool +a (int b) +{ + return (b & 5) != b; +} +int c; +int +fn2 () +{ + if (a (c == 0)) + return 0; +} + +int main() +{ + fn2(); +} + -- 2.11.0