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 - Part 3
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 26 Oct 2004 09:03:41 -0400 (EDT)
- Subject: [patch] stmt.c: Speed/clean up expand_case - Part 3
Hi,
Attached is a patch to speed/clean up expand_case.
cleanup_tree_cfg cleans up a SWITCH_EXPR with a single destination,
such as one with a default case only, and replaces it with an
unconditonal jump.
The patch uses the above fact and removes code in expand_case to
handle SWITCH_EXPR with a default case only.
Tested on i686-pc-linux-gnu. OK to apply?
Kazu Hirata
2004-10-26 Kazu Hirata <kazu@cs.umass.edu>
* stmt.c (expand_case): Remove code to handle SWITCH_EXPR with
a default case only.
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stmt.c,v
retrieving revision 1.402
diff -c -p -r1.402 stmt.c
*** stmt.c 24 Oct 2004 00:46:10 -0000 1.402
--- stmt.c 25 Oct 2004 15:39:56 -0000
*************** expand_case (tree exp)
*** 2420,2446 ****
}
}
! /* Compute span of values. */
! if (count != 0)
! range = fold (build2 (MINUS_EXPR, index_type, maxval, minval));
! if (count == 0)
! {
! expand_expr (index_expr, const0_rtx, VOIDmode, 0);
! emit_jump (default_label);
! }
/* Try implementing this switch statement by a short sequence of
bit-wise comparisons. However, we let the binary-tree case
below handle constant index expressions. */
! else if (CASE_USE_BIT_TESTS
! && ! TREE_CONSTANT (index_expr)
! && compare_tree_int (range, GET_MODE_BITSIZE (word_mode)) < 0
! && compare_tree_int (range, 0) > 0
! && lshift_cheap_p ()
! && ((uniq == 1 && count >= 3)
! || (uniq == 2 && count >= 5)
! || (uniq == 3 && count >= 6)))
{
/* Optimize the case where all the case values fit in a
word without having to subtract MINVAL. In this case,
--- 2420,2443 ----
}
}
! /* cleanup_tree_cfg removes all SWITCH_EXPR with a single
! destination, such as one with a default case only. */
! gcc_assert (count != 0);
! /* Compute span of values. */
! range = fold (build2 (MINUS_EXPR, index_type, maxval, minval));
/* Try implementing this switch statement by a short sequence of
bit-wise comparisons. However, we let the binary-tree case
below handle constant index expressions. */
! if (CASE_USE_BIT_TESTS
! && ! TREE_CONSTANT (index_expr)
! && compare_tree_int (range, GET_MODE_BITSIZE (word_mode)) < 0
! && compare_tree_int (range, 0) > 0
! && lshift_cheap_p ()
! && ((uniq == 1 && count >= 3)
! || (uniq == 2 && count >= 5)
! || (uniq == 3 && count >= 6)))
{
/* Optimize the case where all the case values fit in a
word without having to subtract MINVAL. In this case,