From 26f36b50ead92836710b0ae799abaf4f000a6f88 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Fri, 10 May 2019 08:32:31 +0200 Subject: [PATCH] Add params for jump-table expansion params (PR middle-end/90340). 2019-05-10 Martin Liska PR middle-end/90340 * doc/invoke.texi: New params. * params.def (PARAM_JUMP_TABLE_MAX_GROWTH_RATIO_FOR_SIZE): New. (PARAM_JUMP_TABLE_MAX_GROWTH_RATIO_FOR_SPEED): Likewise. * tree-switch-conversion.c (jump_table_cluster::can_be_handled): Use it. * tree-switch-conversion.h (struct jump_table_cluster): Likewise. 2019-05-10 Martin Liska PR middle-end/90340 * gcc.dg/tree-ssa/pr90340-2.c: New test. * gcc.dg/tree-ssa/pr90340.c: New test. From-SVN: r271053 --- gcc/ChangeLog | 11 ++++++++ gcc/doc/invoke.texi | 10 ++++++++ gcc/params.def | 14 ++++++++++ gcc/testsuite/ChangeLog | 6 +++++ gcc/testsuite/gcc.dg/tree-ssa/pr90340-2.c | 31 +++++++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr90340.c | 31 +++++++++++++++++++++++ gcc/tree-switch-conversion.c | 11 +++----- gcc/tree-switch-conversion.h | 6 ----- 8 files changed, 107 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr90340-2.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr90340.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4d2dc8cc117..3c2c13d4830 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2019-05-10 Martin Liska + + PR middle-end/90340 + * doc/invoke.texi: New params. + * params.def (PARAM_JUMP_TABLE_MAX_GROWTH_RATIO_FOR_SIZE): New. + (PARAM_JUMP_TABLE_MAX_GROWTH_RATIO_FOR_SPEED): Likewise. + * tree-switch-conversion.c (jump_table_cluster::can_be_handled): + Use it. + * tree-switch-conversion.h (struct jump_table_cluster): + Likewise. + 2019-05-09 Segher Boessenkool * combine.c (combine_simplify_rtx): Don't make IF_THEN_ELSE RTL. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 8e4a8a880ef..5e3e8873d35 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -11889,6 +11889,16 @@ The smallest number of different values for which it is best to use a jump-table instead of a tree of conditional branches. If the value is 0, use the default for the machine. +@item jump-table-max-growth-ratio-for-size +The maximum code size growth ratio when expanding +into a jump table (in percent). The parameter is used when +optimizing for size. + +@item jump-table-max-growth-ratio-for-speed +The maximum code size growth ratio when expanding +into a jump table (in percent). The parameter is used when +optimizing for speed. + @item tree-reassoc-width Set the maximum number of instructions executed in parallel in reassociated tree. This parameter overrides target dependent diff --git a/gcc/params.def b/gcc/params.def index 5830cb5d6e4..23b8743786c 100644 --- a/gcc/params.def +++ b/gcc/params.def @@ -1175,6 +1175,20 @@ DEFPARAM (PARAM_CASE_VALUES_THRESHOLD, "if 0, use the default for the machine.", 0, 0, 0) +DEFPARAM (PARAM_JUMP_TABLE_MAX_GROWTH_RATIO_FOR_SIZE, + "jump-table-max-growth-ratio-for-size", + "The maximum code size growth ratio when expanding " + "into a jump table (in percent). The parameter is used when " + "optimizing for size.", + 300, 0, 0) + +DEFPARAM (PARAM_JUMP_TABLE_MAX_GROWTH_RATIO_FOR_SPEED, + "jump-table-max-growth-ratio-for-speed", + "The maximum code size growth ratio when expanding " + "into a jump table (in percent). The parameter is used when " + "optimizing for speed.", + 800, 0, 0) + /* Data race flags for C++0x memory model compliance. */ DEFPARAM (PARAM_ALLOW_STORE_DATA_RACES, "allow-store-data-races", diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4959d2abf79..24f09796e28 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-05-10 Martin Liska + + PR middle-end/90340 + * gcc.dg/tree-ssa/pr90340-2.c: New test. + * gcc.dg/tree-ssa/pr90340.c: New test. + 2019-05-09 Cherry Zhang * go.dg/mapstring.go: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr90340-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr90340-2.c new file mode 100644 index 00000000000..21099821786 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr90340-2.c @@ -0,0 +1,31 @@ +/* { dg-do compile { target { { x86_64-*-* aarch64-*-* ia64-*-* powerpc64-*-* } && lp64 } } } */ +/* { dg-options "-Os --param jump-table-max-growth-ratio-for-size=200 -fdump-tree-switchlower1" } */ + +int a; + +int foo(char c) { + switch (c) { + case 'c': + return a; + case 's': + return 3; + case 'n': + return 1; + case '%': + return -2; + case 'o': + return a + 2; + break; + case 'X': + case 'x': + return 2222; + case 'd': + case 'i': + case 'u': + return 3333; + default: + return 0; + } +} + +/* { dg-final { scan-tree-dump ";; GIMPLE switch case clusters: 37 88 99 100 105 110 111 115 117 120" "switchlower1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr90340.c b/gcc/testsuite/gcc.dg/tree-ssa/pr90340.c new file mode 100644 index 00000000000..8f3b87c1916 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr90340.c @@ -0,0 +1,31 @@ +/* { dg-do compile { target { { x86_64-*-* aarch64-*-* ia64-*-* powerpc64-*-* } && lp64 } } } */ +/* { dg-options "-Os -fdump-tree-switchlower1" } */ + +int a; + +int foo(char c) { + switch (c) { + case 'c': + return a; + case 's': + return 3; + case 'n': + return 1; + case '%': + return -2; + case 'o': + return a + 2; + break; + case 'X': + case 'x': + return 2222; + case 'd': + case 'i': + case 'u': + return 3333; + default: + return 0; + } +} + +/* { dg-final { scan-tree-dump ";; GIMPLE switch case clusters: 37 88 JT:99-120" "switchlower1" } } */ diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c index c3f2baf39d7..bedeb2fd865 100644 --- a/gcc/tree-switch-conversion.c +++ b/gcc/tree-switch-conversion.c @@ -1268,7 +1268,9 @@ jump_table_cluster::can_be_handled (const vec &clusters, return true; unsigned HOST_WIDE_INT max_ratio - = optimize_insn_for_size_p () ? max_ratio_for_size : max_ratio_for_speed; + = (optimize_insn_for_size_p () + ? PARAM_VALUE (PARAM_JUMP_TABLE_MAX_GROWTH_RATIO_FOR_SIZE) + : PARAM_VALUE (PARAM_JUMP_TABLE_MAX_GROWTH_RATIO_FOR_SPEED)); unsigned HOST_WIDE_INT range = get_range (clusters[start]->get_low (), clusters[end]->get_high ()); /* Check overflow. */ @@ -1282,7 +1284,7 @@ jump_table_cluster::can_be_handled (const vec &clusters, comparison_count += sc->m_range_p ? 2 : 1; } - return range <= max_ratio * comparison_count; + return 100 * range <= max_ratio * comparison_count; } /* Return true if cluster starting at START and ending at END (inclusive) @@ -1299,11 +1301,6 @@ jump_table_cluster::is_beneficial (const vec &, return end - start + 1 >= case_values_threshold (); } -/* Definition of jump_table_cluster constants. */ - -const unsigned HOST_WIDE_INT jump_table_cluster::max_ratio_for_size; -const unsigned HOST_WIDE_INT jump_table_cluster::max_ratio_for_speed; - /* Find bit tests of given CLUSTERS, where all members of the vector are of type simple_cluster. New clusters are returned. */ diff --git a/gcc/tree-switch-conversion.h b/gcc/tree-switch-conversion.h index b3bc4b9ddf7..a9a959c39db 100644 --- a/gcc/tree-switch-conversion.h +++ b/gcc/tree-switch-conversion.h @@ -269,12 +269,6 @@ struct jump_table_cluster: public group_cluster /* Return whether jump table expansion is allowed. */ static bool is_enabled (void); - - /* Max growth ratio for code that is optimized for size. */ - static const unsigned HOST_WIDE_INT max_ratio_for_size = 3; - - /* Max growth ratio for code that is optimized for speed. */ - static const unsigned HOST_WIDE_INT max_ratio_for_speed = 8; }; /* A GIMPLE switch statement can be expanded to a short sequence of bit-wise -- 2.30.2