gimple: Make bit-test switch lowering more powerful
A reasonable goal for bit-test lowering is to produce the least amount
of clusters for a given switch (a cluster is basically a group of cases
that can be handled by constantly many operations).
The current algorithm doesn't always give optimal solutions in that
sense. This patch should fix this. The important thing is basically
just to ask if a cluster is_beneficial() more proactively.
The patch also has a fix for a mistake which made bit-test lowering only
create BITS_IN_WORD - 1 big clusters. There are also some new comments
that go into more detail on the dynamic programming algorithm.
gcc/ChangeLog:
* tree-switch-conversion.cc (bit_test_cluster::find_bit_tests):
Modify the dynamic programming algorithm to take is_beneficial()
into account earlier. To do this efficiently, copy some logic
from is_beneficial() here. Add detailed comments about how the
DP algorithm works.
(bit_test_cluster::can_be_handled): Check that the cluster range
is >, not >= BITS_IN_WORD. Remove the
"vec<cluster *> &, unsigned, unsigned" overloaded variant since
we no longer need it.
(bit_test_cluster::is_beneficial): Add a comment that this
function is closely tied to m_max_case_bit_tests. Remove the
"vec<cluster *> &, unsigned, unsigned" overloaded variant since
we no longer need it.
* tree-switch-conversion.h: Remove the vec overloaded variants
of bit_test_cluster::is_beneficial and
bit_test_cluster::can_be_handled.