]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add params for jump-table expansion params (PR middle-end/90340).
authorMartin Liska <mliska@suse.cz>
Fri, 10 May 2019 06:32:31 +0000 (08:32 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Fri, 10 May 2019 06:32:31 +0000 (06:32 +0000)
2019-05-10  Martin Liska  <mliska@suse.cz>

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  <mliska@suse.cz>

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
gcc/doc/invoke.texi
gcc/params.def
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr90340-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr90340.c [new file with mode: 0644]
gcc/tree-switch-conversion.c
gcc/tree-switch-conversion.h

index 4d2dc8cc117530ed798402efe92fa44c40130bd1..3c2c13d48301f6dc763bf7d326238b099ff9af91 100644 (file)
@@ -1,3 +1,14 @@
+2019-05-10  Martin Liska  <mliska@suse.cz>
+
+       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  <segher@kernel.crashing.org>
 
        * combine.c (combine_simplify_rtx): Don't make IF_THEN_ELSE RTL.
index 8e4a8a880efdce54bbc735f817c11c9021d45e90..5e3e8873d355b443a01fceb5c3df4cb98dd26d60 100644 (file)
@@ -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
index 5830cb5d6e4b5dad77448d3ecbbf3e58a1a1eba8..23b8743786c0e36f6c0ae67b32c00d967f38a86e 100644 (file)
@@ -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",
index 4959d2abf79a45f63f082da0ef9bb6a8901885f6..24f09796e288340358afa4bcebd5922d0e366b8e 100644 (file)
@@ -1,3 +1,9 @@
+2019-05-10  Martin Liska  <mliska@suse.cz>
+
+       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  <cherryyz@google.com>
 
        * 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 (file)
index 0000000..2109982
--- /dev/null
@@ -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 (file)
index 0000000..8f3b87c
--- /dev/null
@@ -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" } } */
index c3f2baf39d70de39180311c7cc36dfe282b865eb..bedeb2fd86553349fc289a1f2d7512c7e3779be5 100644 (file)
@@ -1268,7 +1268,9 @@ jump_table_cluster::can_be_handled (const vec<cluster *> &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<cluster *> &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<cluster *> &,
   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.  */
 
index b3bc4b9ddf74b19d69fde0ac32a689d58ea7d90d..a9a959c39dba5af1fd9a768164b3fc40aacc438a 100644 (file)
@@ -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