re PR tree-optimization/17343 (a dispatch table can be shortened for certain switch...
authorAndrew Pinski <pinskia@physics.uc.edu>
Fri, 1 Oct 2004 15:22:26 +0000 (15:22 +0000)
committerAndrew Pinski <pinskia@gcc.gnu.org>
Fri, 1 Oct 2004 15:22:26 +0000 (08:22 -0700)
2004-10-01  Andrew Pinski  <pinskia@physics.uc.edu>

        PR tree-opt/17343
        * gcc.dg/tree-ssa/pr17343.c: New test.

2004-10-01  Andrew Pinski  <pinskia@physics.uc.edu>

        PR tree-opt/17343
        * tree-cfg.c (group_case_labels): Get the label and not
        the case expr for the default case.
        When the label we looking at is the default, decrement the
        new_size.

From-SVN: r88397

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr17343.c [new file with mode: 0644]
gcc/tree-cfg.c

index 80912c3eb1d59d6e282fef6b3f9b202e83412223..f32a14bd156a97d71ff94ea795811e8a085e2067 100644 (file)
@@ -1,3 +1,11 @@
+2004-10-01  Andrew Pinski  <pinskia@physics.uc.edu>
+
+       PR tree-opt/17343
+       * tree-cfg.c (group_case_labels): Get the label and not
+       the case expr for the default case.
+       When the label we looking at is the default, decrement the
+       new_size.
+
 2004-10-01  Jan Hubicka  <jh@suse.cz>
 
        * c-decl.c (c_expand_body): Update call tree_rest_of_compilation.
index 6b3b270aa40dba9c6bfbe81b5df3b4f733e8f795..cf4646c1c41788fc33e5b9b6ba1e9d86a65586ed 100644 (file)
@@ -1,3 +1,8 @@
+2004-10-01  Andrew Pinski  <pinskia@physics.uc.edu>
+
+       PR tree-opt/17343
+       * gcc.dg/tree-ssa/pr17343.c: New test.
+
 2004-10-01  Jakub Jelinek  <jakub@redhat.com>
 
        * gcc.dg/tree-ssa/stdarg-1.c: Removed.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr17343.c b/gcc/testsuite/gcc.dg/tree-ssa/pr17343.c
new file mode 100644 (file)
index 0000000..b415d66
--- /dev/null
@@ -0,0 +1,36 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+void foo0(void);
+void foo1(void);
+void foo2(void);
+void foo3(void);
+
+void
+foo (int a)
+{
+  switch (a)
+    {
+    case 10:
+    case 11:
+    case 12:
+    case 13:
+      goto ddd;
+    case 14:
+      foo1();
+      break;
+    case 15:
+      foo2();
+      break;
+    case 16:
+      foo3();
+      break;
+    default:
+    ddd:
+      foo0();
+      break;
+    }
+}
+/* There should be precisely two references to ddd.  One in the switch
+   and one for the label, we used not to combine the case 10-13 into
+   the default case.  */
+/* { dg-final { scan-tree-dump-times "ddd" 1 "optimized"} } */
index 72f73784d6055289ad1c5c78398a9edf92aeff32..e047943cb42a27e31d10fcc0d56cb5436997d3f8 100644 (file)
@@ -941,7 +941,12 @@ group_case_labels (void)
          tree labels = SWITCH_LABELS (stmt);
          int old_size = TREE_VEC_LENGTH (labels);
          int i, j, new_size = old_size;
-         tree default_label = TREE_VEC_ELT (labels, old_size - 1);
+         tree default_case = TREE_VEC_ELT (labels, old_size - 1);
+         tree default_label;
+
+         /* The default lable is always the last case in a switch
+            statement after gimplification.  */
+         default_label = CASE_LABEL (default_case);
 
          /* Look for possible opportunities to merge cases.
             Ignore the last element of the label vector because it
@@ -961,6 +966,7 @@ group_case_labels (void)
                {
                  TREE_VEC_ELT (labels, i) = NULL_TREE;
                  i++;
+                 new_size--;
                  continue;
                }