I'm going to install the following 3 tested backports.
Martin
>From 0d91a9613ca1c4b8b11d668a1b8e1a6a37c41b7a Mon Sep 17 00:00:00 2001 From: Martin Liska <mli...@suse.cz> Date: Fri, 25 Sep 2020 16:21:34 +0200 Subject: [PATCH 3/3] gcov: fix streaming of HIST_TYPE_IOR histogram type. gcc/ChangeLog: PR gcov-profile/64636 * value-prof.c (stream_out_histogram_value): Allow negative values for HIST_TYPE_IOR. (cherry picked from commit 1921ebcaf6467996aede69e1bbe32400d8a20fe7) --- gcc/value-prof.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gcc/value-prof.c b/gcc/value-prof.c index 45677be46b1..9d60b56c43a 100644 --- a/gcc/value-prof.c +++ b/gcc/value-prof.c @@ -332,7 +332,10 @@ stream_out_histogram_value (struct output_block *ob, histogram_value hist) /* When user uses an unsigned type with a big value, constant converted to gcov_type (a signed type) can be negative. */ gcov_type value = hist->hvalue.counters[i]; - if (hist->type == HIST_TYPE_TOPN_VALUES) + if (hist->type == HIST_TYPE_TOPN_VALUES + || hist->type == HIST_TYPE_IOR) + /* Note that the IOR counter tracks pointer values and these can have + sign bit set. */ ; else gcc_assert (value >= 0); -- 2.28.0
>From 4c2be1627f6b78dff9209b979b26080f5b929d89 Mon Sep 17 00:00:00 2001 From: Martin Liska <mli...@suse.cz> Date: Thu, 24 Sep 2020 13:34:13 +0200 Subject: [PATCH 2/3] switch conversion: make a rapid speed up gcc/ChangeLog: PR tree-optimization/96979 * tree-switch-conversion.c (jump_table_cluster::can_be_handled): Make a fast bail out. (bit_test_cluster::can_be_handled): Likewise here. * tree-switch-conversion.h (get_range): Use wi::to_wide instead of a folding. gcc/testsuite/ChangeLog: PR tree-optimization/96979 * g++.dg/tree-ssa/pr96979.C: New test. (cherry picked from commit e46858e4eeee45d35ca4a7df1996186fe884879b) --- gcc/testsuite/g++.dg/tree-ssa/pr96979.C | 48 +++++++++++++++++++++++++ gcc/tree-switch-conversion.c | 37 ++++++++++++++----- gcc/tree-switch-conversion.h | 7 ++-- 3 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/g++.dg/tree-ssa/pr96979.C diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr96979.C b/gcc/testsuite/g++.dg/tree-ssa/pr96979.C new file mode 100644 index 00000000000..ec0f57a8548 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/pr96979.C @@ -0,0 +1,48 @@ +/* PR tree-optimization/96979 */ +/* { dg-do compile } */ +/* { dg-options "-std=c++17 -O2" } */ + +using u64 = unsigned long long; + +constexpr inline u64 +foo (const char *str) noexcept +{ + u64 value = 0xcbf29ce484222325ULL; + for (u64 i = 0; str[i]; i++) + value = (value ^ u64(str[i])) * 0x100000001b3ULL; + return value; +} + +struct V +{ + enum W + { +#define A(n) n, +#define B(n) A(n##0) A(n##1) A(n##2) A(n##3) A(n##4) A(n##5) A(n##6) A(n##7) A(n##8) A(n##9) +#define C(n) B(n##0) B(n##1) B(n##2) B(n##3) B(n##4) B(n##5) B(n##6) B(n##7) B(n##8) B(n##9) +#define D(n) C(n##0) C(n##1) C(n##2) C(n##3) C(n##4) C(n##5) C(n##6) C(n##7) C(n##8) C(n##9) +#define E D(foo1) D(foo2) D(foo3) + E + last + }; + + constexpr static W + bar (const u64 h) noexcept + { + switch (h) + { +#undef A +#define F(n) #n +#define A(n) case foo (F(n)): return n; + E + } + return last; + } +}; + +int +baz (const char *s) +{ + const u64 h = foo (s); + return V::bar (h); +} diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c index bf910dd62b5..8da1be1cd99 100644 --- a/gcc/tree-switch-conversion.c +++ b/gcc/tree-switch-conversion.c @@ -1271,6 +1271,18 @@ jump_table_cluster::can_be_handled (const vec<cluster *> &clusters, if (range == 0) return false; + if (range > HOST_WIDE_INT_M1U / 100) + return false; + + unsigned HOST_WIDE_INT lhs = 100 * range; + if (lhs < range) + return false; + + /* First make quick guess as each cluster + can add at maximum 2 to the comparison_count. */ + if (lhs > 2 * max_ratio * (end - start + 1)) + return false; + unsigned HOST_WIDE_INT comparison_count = 0; for (unsigned i = start; i <= end; i++) { @@ -1278,10 +1290,6 @@ jump_table_cluster::can_be_handled (const vec<cluster *> &clusters, comparison_count += sc->m_range_p ? 2 : 1; } - unsigned HOST_WIDE_INT lhs = 100 * range; - if (lhs < range) - return false; - return lhs <= max_ratio * comparison_count; } @@ -1367,12 +1375,12 @@ bit_test_cluster::can_be_handled (unsigned HOST_WIDE_INT range, { /* Check overflow. */ if (range == 0) - return 0; + return false; if (range >= GET_MODE_BITSIZE (word_mode)) return false; - return uniq <= 3; + return uniq <= m_max_case_bit_tests; } /* Return true when cluster starting at START and ending at END (inclusive) @@ -1382,6 +1390,7 @@ bool bit_test_cluster::can_be_handled (const vec<cluster *> &clusters, unsigned start, unsigned end) { + auto_vec<int, m_max_case_bit_tests> dest_bbs; /* For algorithm correctness, bit test for a single case must return true. We bail out in is_beneficial if it's called just for a single case. */ @@ -1390,15 +1399,25 @@ bit_test_cluster::can_be_handled (const vec<cluster *> &clusters, unsigned HOST_WIDE_INT range = get_range (clusters[start]->get_low (), clusters[end]->get_high ()); - auto_bitmap dest_bbs; + + /* Make a guess first. */ + if (!can_be_handled (range, m_max_case_bit_tests)) + return false; for (unsigned i = start; i <= end; i++) { simple_cluster *sc = static_cast<simple_cluster *> (clusters[i]); - bitmap_set_bit (dest_bbs, sc->m_case_bb->index); + /* m_max_case_bit_tests is very small integer, thus the operation + is constant. */ + if (!dest_bbs.contains (sc->m_case_bb->index)) + { + if (dest_bbs.length () >= m_max_case_bit_tests) + return false; + dest_bbs.quick_push (sc->m_case_bb->index); + } } - return can_be_handled (range, bitmap_count_bits (dest_bbs)); + return true; } /* Return true when COUNT of cases of UNIQ labels is beneficial for bit test diff --git a/gcc/tree-switch-conversion.h b/gcc/tree-switch-conversion.h index 9ebcf109319..dbfd9eecba2 100644 --- a/gcc/tree-switch-conversion.h +++ b/gcc/tree-switch-conversion.h @@ -84,11 +84,10 @@ public: then return 0. */ static unsigned HOST_WIDE_INT get_range (tree low, tree high) { - tree r = fold_build2 (MINUS_EXPR, TREE_TYPE (low), high, low); - if (!tree_fits_uhwi_p (r)) + wide_int w = wi::to_wide (high) - wi::to_wide (low); + if (wi::neg_p (w, TYPE_SIGN (TREE_TYPE (low))) || !wi::fits_uhwi_p (w)) return 0; - - return tree_to_uhwi (r) + 1; + return w.to_uhwi () + 1; } /* Case label. */ -- 2.28.0
>From 4c0b4be28c6a8d8cab91ca234cdc5c410936141d Mon Sep 17 00:00:00 2001 From: Martin Liska <mli...@suse.cz> Date: Mon, 21 Sep 2020 16:26:10 +0200 Subject: [PATCH 1/3] gcov: fix streaming corruption gcc/ChangeLog: PR gcov-profile/97069 * profile.c (branch_prob): Line number must be at least 1. gcc/testsuite/ChangeLog: PR gcov-profile/97069 * g++.dg/gcov/pr97069.C: New test. (cherry picked from commit 6b4e8bf88f1172ce8561f57b12fb81063b21a78f) --- gcc/profile.c | 6 +++--- gcc/testsuite/g++.dg/gcov/pr97069.C | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/gcov/pr97069.C diff --git a/gcc/profile.c b/gcc/profile.c index cd754c4c66a..2e5ab0d3415 100644 --- a/gcc/profile.c +++ b/gcc/profile.c @@ -1367,7 +1367,7 @@ branch_prob (bool thunk) seen_locations.add (loc); expanded_location curr_location = expand_location (loc); output_location (&streamed_locations, curr_location.file, - curr_location.line, &offset, bb); + MAX (1, curr_location.line), &offset, bb); } for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) @@ -1378,7 +1378,7 @@ branch_prob (bool thunk) { seen_locations.add (loc); output_location (&streamed_locations, gimple_filename (stmt), - gimple_lineno (stmt), &offset, bb); + MAX (1, gimple_lineno (stmt)), &offset, bb); } } @@ -1393,7 +1393,7 @@ branch_prob (bool thunk) { expanded_location curr_location = expand_location (loc); output_location (&streamed_locations, curr_location.file, - curr_location.line, &offset, bb); + MAX (1, curr_location.line), &offset, bb); } if (offset) diff --git a/gcc/testsuite/g++.dg/gcov/pr97069.C b/gcc/testsuite/g++.dg/gcov/pr97069.C new file mode 100644 index 00000000000..040e336662a --- /dev/null +++ b/gcc/testsuite/g++.dg/gcov/pr97069.C @@ -0,0 +1,20 @@ +// PR gcov-profile/97069 +// { dg-options "--coverage" } +// { dg-do run { target native } } + +# 0 "pr97069.C" +# 0 "<built-in>" +# 0 "<command-line>" +# 1 "/usr/include/stdc-predef.h" 1 3 4 +# 0 "<command-line>" 2 +# 1 "pr97069.C" +int main() +{ + return 0; +} +# 0 "pr97069.C" +void zero_line_directive() +{ +} + +// { dg-final { run-gcov pr97069.C } } -- 2.28.0