GCC expands switch statements in a very simplistic way and tries to use a table
commit4e0ff2190553433a1472af3760017f4bfd32f797
authorwilco <wilco@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 26 May 2016 12:25:51 +0000 (26 12:25 +0000)
committerwilco <wilco@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 26 May 2016 12:25:51 +0000 (26 12:25 +0000)
tree9cb928a5a7d1097002b87cf821c6a825fd65ac24
parentd2ad5fae89d0eb32378a01cc5bf3a94454ebcd47
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@236771 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ChangeLog
gcc/config/aarch64/aarch64.c