This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] stmt.c: Speed/clean up expand_case.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 23 Oct 2004 16:58:08 -0400 (EDT)
- Subject: [patch] stmt.c: Speed/clean up expand_case.
Hi,
Attached is a patch to speed/clean up expand_case.
Now that we gimplify a switch statment,
1. we always have exactly one default label, and
2. the default label is at the end of TREE_VEC of CASE_LABEL_EXPRs.
By using the above facts, we can speed/clean up expand_case a little
bit. Specifically, we can take care of the default label outside the
for loop in the second hunk of the patch. In addition, we don't have
to worry about a missing default label (see the third hunk).
Taking an "if" outside of a "for" loop is a good thing.
Tested on i686-pc-linux-gnu. OK to apply?
Kazu Hirata
2004-10-23 Kazu Hirata <kazu@cs.umass.edu>
* stmt.c (expand_case): Handle the default label outside of
the for loop. Remove code to handle a missing default label.
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stmt.c,v
retrieving revision 1.401
diff -c -p -r1.401 stmt.c
*** stmt.c 22 Oct 2004 18:52:19 -0000 1.401
--- stmt.c 23 Oct 2004 01:22:03 -0000
*************** expand_case (tree exp)
*** 2341,2347 ****
struct case_node *case_list = 0;
/* Label to jump to if no case matches. */
! tree default_label_decl = 0;
/* The switch body is lowered in gimplify.c, we should never have
switches with a non-NULL SWITCH_BODY here. */
--- 2341,2347 ----
struct case_node *case_list = 0;
/* Label to jump to if no case matches. */
! tree default_label_decl;
/* The switch body is lowered in gimplify.c, we should never have
switches with a non-NULL SWITCH_BODY here. */
*************** expand_case (tree exp)
*** 2353,2372 ****
/* An ERROR_MARK occurs for various reasons including invalid data type. */
if (index_type != error_mark_node)
{
! for (i = TREE_VEC_LENGTH (vec); --i >= 0; )
! {
! tree elt = TREE_VEC_ELT (vec, i);
! /* Handle default labels specially. */
! if (!CASE_HIGH (elt) && !CASE_LOW (elt))
! {
! gcc_assert (!default_label_decl);
! default_label_decl = CASE_LABEL (elt);
! }
! else
! case_list = add_case_node (case_list, index_type,
! CASE_LOW (elt), CASE_HIGH (elt),
! CASE_LABEL (elt));
}
--- 2353,2373 ----
/* An ERROR_MARK occurs for various reasons including invalid data type. */
if (index_type != error_mark_node)
{
! tree elt;
! /* The default case is at the end of TREE_VEC. */
! elt = TREE_VEC_ELT (vec, TREE_VEC_LENGTH (vec) - 1);
! gcc_assert (!CASE_HIGH (elt));
! gcc_assert (!CASE_LOW (elt));
! default_label_decl = CASE_LABEL (elt);
!
! for (i = TREE_VEC_LENGTH (vec) - 1; --i >= 0; )
! {
! elt = TREE_VEC_ELT (vec, i);
! gcc_assert (CASE_LOW (elt));
! case_list = add_case_node (case_list, index_type,
! CASE_LOW (elt), CASE_HIGH (elt),
! CASE_LABEL (elt));
}
*************** expand_case (tree exp)
*** 2379,2392 ****
start = get_last_insn ();
}
- /* If we don't have a default-label, create one here,
- after the body of the switch. */
- if (default_label_decl == 0)
- {
- default_label_decl
- = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
- expand_label (default_label_decl);
- }
default_label = label_rtx (default_label_decl);
before_case = get_last_insn ();
--- 2380,2385 ----