This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] PR middle-end/11823: Tune jump tables for -Os
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Arpad Beszedes <beszedes at cc dot u-szeged dot hu>, Steven Bosscher <steven at gcc dot gnu dot org>
- Date: Sat, 30 Aug 2003 10:11:14 -0600 (MDT)
- Subject: [PATCH] PR middle-end/11823: Tune jump tables for -Os
This patch is Steven Bossher's proposed fix to PR middle-end/11823 as
attached to that PR in bugzilla. It turns out that the heuristics
that are used to determine whether to emit a tablejump vs. a sequence
of comparisons doesn't currently consider whether we're optimizing
for size.
To determine the most appropriate threshold value, I evaluated a
series of switch table densities against the CSiBE GCC code-size
benchmark http://sed.inf.u-szeged.hu/csibe/ as described at the GCC
developers forum. The following table summarizes total executable sizes
compiled with "-Os" on i686-pc-linux-gnu for different co-efficients,
x, in the "range > x*count" equation used by stmt.c
Multiplier Total Size
0 988072
1 987689
2 985307
3 985233
4 985469
5 985881
6 986371
7 986371
8 987928
9 988545
10 989777
The results are that the value of "3" proposed by Steven is indeed
optimal for this benchmark. This intuitively makes sense that the
code size required for each additional comparison is approximately
equal to about the size of three additional entries in a jump table.
Hopefully, this should also hold up across multiple architectures.
The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all languages except treelang, and regression tested
with a top-level "make -k check" with no new failures.
Ok for mainline?
2003-08-30 Steven Bossher <steven@gcc.gnu.org>
Roger Sayle <roger@eyesopen.com>
PR middle-end/11823
* stmt.c (expand_end_case_type): Only use jump tables for dense
switch statements when optimizing for size.
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stmt.c,v
retrieving revision 1.325
diff -c -3 -p -r1.325 stmt.c
*** stmt.c 16 Aug 2003 13:32:03 -0000 1.325
--- stmt.c 29 Aug 2003 21:45:53 -0000
*************** expand_end_case_type (tree orig_index, t
*** 5437,5443 ****
because we can optimize it. */
else if (count < case_values_threshold ()
! || compare_tree_int (range, 10 * count) > 0
/* RANGE may be signed, and really large ranges will show up
as negative numbers. */
|| compare_tree_int (range, 0) < 0
--- 5437,5444 ----
because we can optimize it. */
else if (count < case_values_threshold ()
! || compare_tree_int (range,
! (optimize_size ? 3 : 10) * count) > 0
/* RANGE may be signed, and really large ranges will show up
as negative numbers. */
|| compare_tree_int (range, 0) < 0
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833