diff options
author | Martin Liska <mliska@suse.cz> | 2020-09-22 12:23:35 +0200 |
---|---|---|
committer | Martin Liska <mliska@suse.cz> | 2020-09-22 14:38:46 +0200 |
commit | c6df6039e9180c580945266302ec14047d358364 (patch) | |
tree | ea9ad4ba2f0a9a04b8b9e39e9a553b12366b9cb6 /gcc/tree-switch-conversion.c | |
parent | 1a84651d164e9ebf080e0b64f0ad300eaae46297 (diff) |
switch lowering: limit number of cluster attemps
gcc/ChangeLog:
PR tree-optimization/96979
* doc/invoke.texi: Document new param max-switch-clustering-attempts.
* params.opt: Add new parameter.
* tree-switch-conversion.c (jump_table_cluster::find_jump_tables):
Limit number of attempts.
(bit_test_cluster::find_bit_tests): Likewise.
gcc/testsuite/ChangeLog:
PR tree-optimization/96979
* g++.dg/tree-ssa/pr96979.C: New test.
Diffstat (limited to 'gcc/tree-switch-conversion.c')
-rw-r--r-- | gcc/tree-switch-conversion.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c index 186411ff3c4..e6a2c7a6a84 100644 --- a/gcc/tree-switch-conversion.c +++ b/gcc/tree-switch-conversion.c @@ -1183,6 +1183,7 @@ jump_table_cluster::find_jump_tables (vec<cluster *> &clusters) min.quick_push (min_cluster_item (0, 0, 0)); + HOST_WIDE_INT attempts = 0; for (unsigned i = 1; i <= l; i++) { /* Set minimal # of clusters with i-th item to infinite. */ @@ -1194,6 +1195,14 @@ jump_table_cluster::find_jump_tables (vec<cluster *> &clusters) if (i - j < case_values_threshold ()) s += i - j; + if (attempts++ == param_max_switch_clustering_attempts) + { + if (dump_file) + fprintf (dump_file, ";; Bail out: " + "--param=max-switch-clustering-attempts reached\n"); + return clusters.copy (); + } + /* Prefer clusters with smaller number of numbers covered. */ if ((min[j].m_count + 1 < min[i].m_count || (min[j].m_count + 1 == min[i].m_count @@ -1308,6 +1317,7 @@ bit_test_cluster::find_bit_tests (vec<cluster *> &clusters) min.quick_push (min_cluster_item (0, 0, 0)); + HOST_WIDE_INT attempts = 0; for (unsigned i = 1; i <= l; i++) { /* Set minimal # of clusters with i-th item to infinite. */ @@ -1315,6 +1325,13 @@ bit_test_cluster::find_bit_tests (vec<cluster *> &clusters) for (unsigned j = 0; j < i; j++) { + if (attempts++ == param_max_switch_clustering_attempts) + { + if (dump_file) + fprintf (dump_file, ";; Bail out: " + "--param=max-switch-clustering-attempts reached\n"); + return clusters.copy (); + } if (min[j].m_count + 1 < min[i].m_count && can_be_handled (clusters, j, i - 1)) min[i] = min_cluster_item (min[j].m_count + 1, j, INT_MAX); |