From dcb1e1379ea52c33e5025d6e5842c43888888afa Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Tue, 9 Aug 2016 22:57:14 +0200 Subject: [PATCH] Fix POW2 histogram * gcc.dg/tree-prof/val-prof-8.c: New test. * value-prof.c (dump_histogram_value): Swap pow2 and non-pow2 values. * libgcov-profiler.c (__gcov_pow2_profiler): Consider 0 as not power of two. From-SVN: r239304 --- gcc/ChangeLog | 5 +++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/tree-prof/val-prof-8.c | 19 +++++++++++++++++++ gcc/value-prof.c | 4 ++-- libgcc/ChangeLog | 5 +++++ libgcc/libgcov-profiler.c | 2 +- 6 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-prof/val-prof-8.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 40537cba7e7..dc14d6f10e7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-08-09 Martin Liska + + * value-prof.c (dump_histogram_value): Swap pow2 and non-pow2 + values. + 2016-08-09 Renlin Li PR middle-end/64971 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 34834693309..927f1e31a32 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-08-09 Martin Liska + + * gcc.dg/tree-prof/val-prof-8.c: New test. + 2016-08-09 Martin Jambor PR ipa/71981 diff --git a/gcc/testsuite/gcc.dg/tree-prof/val-prof-8.c b/gcc/testsuite/gcc.dg/tree-prof/val-prof-8.c new file mode 100644 index 00000000000..2c505e3d97d --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-prof/val-prof-8.c @@ -0,0 +1,19 @@ +/* { dg-options "-O0 -fdump-ipa-profile" } */ + +int +main (int argc, char **argv) +{ + unsigned u = (argc - 1); + int counter = 0; + + for (unsigned i = 0; i < 100; i++) + { + unsigned x = i < 10 ? 16 : 15; + counter += u % x; + } + + return counter; +} + +/* autofdo does not do value profiling so far */ +/* { dg-final-use-not-autofdo { scan-ipa-dump "Pow2 counter pow2:10 nonpow2:90." "profile" } } */ diff --git a/gcc/value-prof.c b/gcc/value-prof.c index 2976a86c794..0527c2cc738 100644 --- a/gcc/value-prof.c +++ b/gcc/value-prof.c @@ -264,8 +264,8 @@ dump_histogram_value (FILE *dump_file, histogram_value hist) { fprintf (dump_file, "pow2:%" PRId64 " nonpow2:%" PRId64, - (int64_t) hist->hvalue.counters[0], - (int64_t) hist->hvalue.counters[1]); + (int64_t) hist->hvalue.counters[1], + (int64_t) hist->hvalue.counters[0]); } fprintf (dump_file, ".\n"); break; diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog index aa9400d3d19..5b05a7cac7d 100644 --- a/libgcc/ChangeLog +++ b/libgcc/ChangeLog @@ -1,3 +1,8 @@ +2016-08-09 Martin Liska + + * libgcov-profiler.c (__gcov_pow2_profiler): Consider 0 as not + power of two. + 2016-07-29 Bill Schmidt * config/rs6000/_divkc3.c: Add copyright/license boilerplate. diff --git a/libgcc/libgcov-profiler.c b/libgcc/libgcov-profiler.c index e94718834e7..6da8a940660 100644 --- a/libgcc/libgcov-profiler.c +++ b/libgcc/libgcov-profiler.c @@ -53,7 +53,7 @@ __gcov_interval_profiler (gcov_type *counters, gcov_type value, void __gcov_pow2_profiler (gcov_type *counters, gcov_type value) { - if (value & (value - 1)) + if (value == 0 || (value & (value - 1))) counters[0]++; else counters[1]++; -- 2.30.2