From: Martin Liska Date: Mon, 2 Sep 2019 07:09:39 +0000 (+0200) Subject: Fix thinko in early bail out in tree-switch-conversion. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1acbaa7530d7ec1e38fe8f5f1c5313b0d12a4f97;p=gcc.git Fix thinko in early bail out in tree-switch-conversion. 2019-09-02 Martin Liska * tree-switch-conversion.c (jump_table_cluster::find_jump_tables): Bail out when we'll end up with the same number of clusters as at the beginning. (bit_test_cluster::find_bit_tests): Likewise for bit tests. (jump_table_cluster::can_be_handled): Remove the guard as it's already handled in ::is_enabled. Allocate output after early bail out. From-SVN: r275293 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6a4f02dcf3e..990c895f69d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2019-09-02 Martin Liska + + * tree-switch-conversion.c (jump_table_cluster::find_jump_tables): + Bail out when we'll end up with the same number of clusters as + at the beginning. + (bit_test_cluster::find_bit_tests): Likewise for bit tests. + (jump_table_cluster::can_be_handled): Remove the guard + as it's already handled in ::is_enabled. Allocate output + after early bail out. + 2019-09-02 Martin Liska PR gcov-profile/91601 diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c index e8692a7fffe..b7149039ae4 100644 --- a/gcc/tree-switch-conversion.c +++ b/gcc/tree-switch-conversion.c @@ -1214,14 +1214,14 @@ jump_table_cluster::find_jump_tables (vec &clusters) } /* No result. */ - if (min[l].m_count == INT_MAX) + if (min[l].m_count == l) return clusters.copy (); vec output; output.create (4); /* Find and build the clusters. */ - for (int end = l;;) + for (unsigned int end = l;;) { int start = min[end].m_start; @@ -1258,11 +1258,9 @@ jump_table_cluster::can_be_handled (const vec &clusters, make a sequence of conditional branches instead of a dispatch. The definition of "much bigger" depends on whether we are - optimizing for size or for speed. */ - if (!flag_jump_tables) - return false; + optimizing for size or for speed. - /* For algorithm correctness, jump table for a single case must return + For algorithm correctness, jump table for a single case must return true. We bail out in is_beneficial if it's called just for a single case. */ if (start == end) @@ -1312,9 +1310,6 @@ jump_table_cluster::is_beneficial (const vec &, vec bit_test_cluster::find_bit_tests (vec &clusters) { - vec output; - output.create (4); - unsigned l = clusters.length (); auto_vec min; min.reserve (l + 1); @@ -1337,9 +1332,12 @@ bit_test_cluster::find_bit_tests (vec &clusters) } /* No result. */ - if (min[l].m_count == INT_MAX) + if (min[l].m_count == l) return clusters.copy (); + vec output; + output.create (4); + /* Find and build the clusters. */ for (unsigned end = l;;) {