diff options
author | Wilco Dijkstra <wdijkstr@arm.com> | 2016-05-26 12:25:51 +0000 |
---|---|---|
committer | Wilco Dijkstra <wilco@gcc.gnu.org> | 2016-05-26 12:25:51 +0000 |
commit | e79136e41af698ccdaec62ed842b4785162dde09 (patch) | |
tree | 9cb928a5a7d1097002b87cf821c6a825fd65ac24 /gcc/config | |
parent | 5e4d7abeeea05faaa19d97c4693d5ae6c660a831 (diff) | |
download | gcc-e79136e41af698ccdaec62ed842b4785162dde09.zip gcc-e79136e41af698ccdaec62ed842b4785162dde09.tar.gz gcc-e79136e41af698ccdaec62ed842b4785162dde09.tar.bz2 |
GCC expands switch statements in a very simplistic way and tries to use a table...
GCC expands switch statements in a very simplistic way and tries to use a table
expansion even when it is a bad idea for performance or codesize.
GCC typically emits extremely sparse tables that contain mostly default entries
(something which currently cannot be tuned by backends). Additionally the
computation of the minimum/maximum label offsets is too simplistic so the
tables are often twice as large as necessary.
The cost of a table switch is significant due to the setup overhead, the table
lookup (which due to being sparse and large adds unnecessary cachemisses)
and hard to predict indirect jump. Therefore it is best to avoid using a table
unless there are many real case labels.
This patch fixes that by setting the default aarch64_case_values_threshold to
16 when the per-CPU tuning is not set. On SPEC2006 this improves the switch
heavy benchmarks GCC and perlbench both in performance (1-2%) as well as size
(0.5-1% smaller).
gcc/
* config/aarch64/aarch64.c (aarch64_case_values_threshold):
Return a better case_values_threshold when optimizing.
From-SVN: r236771
Diffstat (limited to 'gcc/config')
-rw-r--r-- | gcc/config/aarch64/aarch64.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index bd45a7d..84dcb0b 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -3572,7 +3572,12 @@ aarch64_cannot_force_const_mem (machine_mode mode ATTRIBUTE_UNUSED, rtx x) return aarch64_tls_referenced_p (x); } -/* Implement TARGET_CASE_VALUES_THRESHOLD. */ +/* Implement TARGET_CASE_VALUES_THRESHOLD. + The expansion for a table switch is quite expensive due to the number + of instructions, the table lookup and hard to predict indirect jump. + When optimizing for speed, and -O3 enabled, use the per-core tuning if + set, otherwise use tables for > 16 cases as a tradeoff between size and + performance. When optimizing for size, use the default setting. */ static unsigned int aarch64_case_values_threshold (void) @@ -3583,7 +3588,7 @@ aarch64_case_values_threshold (void) && selected_cpu->tune->max_case_values != 0) return selected_cpu->tune->max_case_values; else - return default_case_values_threshold (); + return optimize_size ? default_case_values_threshold () : 17; } /* Return true if register REGNO is a valid index register. |