Group switch cases in switch lowering (PR tree-optimization/87205).
authorMartin Liska <mliska@suse.cz>
Wed, 5 Sep 2018 11:28:49 +0000 (13:28 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Wed, 5 Sep 2018 11:28:49 +0000 (11:28 +0000)
2018-09-05  Martin Liska  <mliska@suse.cz>

PR tree-optimization/87205
* tree-switch-conversion.c (pass_lower_switch::execute):
Group cases for switch statements.
2018-09-05  Martin Liska  <mliska@suse.cz>

PR tree-optimization/87205
* gcc.dg/tree-ssa/pr87205-2.c: New test.
* gcc.dg/tree-ssa/pr87205.c: New test.

From-SVN: r264124

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr87205-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr87205.c [new file with mode: 0644]
gcc/tree-switch-conversion.c

index 47bc612b82081393391a67c56027389ecc8b748a..8386829287d74353d523ac50d735a0d401158ea8 100644 (file)
@@ -1,3 +1,9 @@
+2018-09-05  Martin Liska  <mliska@suse.cz>
+
+       PR tree-optimization/87205
+       * tree-switch-conversion.c (pass_lower_switch::execute):
+       Group cases for switch statements.
+
 2018-09-05  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/87217
index 12bb8a29d8928fe95cb407b4e238e7af4a75239c..fc40df045f41777b3aec5d5fd3adb6c479e653ab 100644 (file)
@@ -1,3 +1,9 @@
+2018-09-05  Martin Liska  <mliska@suse.cz>
+
+       PR tree-optimization/87205
+       * gcc.dg/tree-ssa/pr87205-2.c: New test.
+       * gcc.dg/tree-ssa/pr87205.c: New test.
+
 2018-09-05  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/87217
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr87205-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr87205-2.c
new file mode 100644 (file)
index 0000000..fb1879e
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+void f(int);
+void h(unsigned i)
+{
+  switch (i) {
+    default: __builtin_unreachable();
+    case 0: f(42); break;
+    case 1: f(42); break;
+    case 2: f(42); break;
+    case 3: f(42); break;
+    case 4: f(42); break;
+    case 5: f(42); break;
+  }
+} 
+
+/* { dg-final { scan-tree-dump-not "if" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "switch" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr87205.c b/gcc/testsuite/gcc.dg/tree-ssa/pr87205.c
new file mode 100644 (file)
index 0000000..129e607
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+void f( int x );
+
+void h( unsigned ix )
+{
+  switch( ix )
+  {
+    case 0: f(42); break;
+    case 1: f(42); break;
+    case 2: f(42); break;
+    case 3: f(42); break;
+    case 4: f(42); break;
+    case 5: f(42); break;
+    default: __builtin_unreachable();
+  }
+}
+
+
+/* { dg-final { scan-tree-dump-not "if" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "switch" "optimized" } } */
index 1f543b2ecc8a55329402712a3413a9648125895b..64169a6cd3d725e683773299c02fd9ff1efa3cba 100644 (file)
@@ -2419,8 +2419,13 @@ pass_lower_switch<O0>::execute (function *fun)
   FOR_EACH_BB_FN (bb, fun)
     {
       gimple *stmt = last_stmt (bb);
-      if (stmt && gimple_code (stmt) == GIMPLE_SWITCH)
-       switch_statements.safe_push (stmt);
+      gswitch *swtch;
+      if (stmt && (swtch = dyn_cast<gswitch *> (stmt)))
+       {
+         if (!O0)
+           group_case_labels_stmt (swtch);
+         switch_statements.safe_push (swtch);
+       }
     }
 
   for (unsigned i = 0; i < switch_statements.length (); i++)