re PR middle-end/9707 (Unnecessary range test in switches with less than 4 cases)
authorKazu Hirata <kazu@cs.umass.edu>
Thu, 25 Mar 2004 16:16:41 +0000 (16:16 +0000)
committerKazu Hirata <kazu@gcc.gnu.org>
Thu, 25 Mar 2004 16:16:41 +0000 (16:16 +0000)
PR optimization/9707.
* stmt.c (emit_case_nodes): Emit equality comparisons instead
of recursing if both children are single-valued cases with no
children.

From-SVN: r79954

gcc/ChangeLog
gcc/stmt.c

index 505adaca56e93d818972bd9ee3b34bbd39fc2a61..e63bbffaf125710e665a09fdc4094329ae587587 100644 (file)
@@ -1,3 +1,10 @@
+2004-03-25  Kazu Hirata  <kazu@cs.umass.edu>
+
+       PR optimization/9707.
+       * stmt.c (emit_case_nodes): Emit equality comparisons instead
+       of recursing if both children are single-valued cases with no
+       children.
+
 2004-03-25  Paul Brook  <paul@codesourcery.com>
 
        * config/arm/arm.c (vfp_print_multi): Remove.
index 3d5da37e8ccaf015217ac5551de2dfc222b14029..a28a01484d77ee04e27068ef01022f58bca1ee36 100644 (file)
@@ -6200,6 +6200,42 @@ emit_case_nodes (rtx index, case_node_ptr node, rtx default_label,
              emit_case_nodes (index, node->right, default_label, index_type);
            }
 
+         /* If both children are single-valued cases with no
+            children, finish up all the work.  This way, we can save
+            one ordered comparison.  */
+         else if (tree_int_cst_equal (node->right->low, node->right->high)
+                  && node->right->left == 0
+                  && node->right->right == 0
+                  && tree_int_cst_equal (node->left->low, node->left->high)
+                  && node->left->left == 0
+                  && node->left->right == 0)
+           {
+             /* Neither node is bounded.  First distinguish the two sides;
+                then emit the code for one side at a time.  */
+
+             /* See if the value matches what the right hand side
+                wants.  */
+             do_jump_if_equal (index,
+                               convert_modes (mode, imode,
+                                              expand_expr (node->right->low,
+                                                           NULL_RTX,
+                                                           VOIDmode, 0),
+                                              unsignedp),
+                               label_rtx (node->right->code_label),
+                               unsignedp);
+
+             /* See if the value matches what the left hand side
+                wants.  */
+             do_jump_if_equal (index,
+                               convert_modes (mode, imode,
+                                              expand_expr (node->left->low,
+                                                           NULL_RTX,
+                                                           VOIDmode, 0),
+                                              unsignedp),
+                               label_rtx (node->left->code_label),
+                               unsignedp);
+           }
+
          else
            {
              /* Neither node is bounded.  First distinguish the two sides;