https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117091
--- Comment #18 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andi Kleen <a...@gcc.gnu.org>: https://gcc.gnu.org/g:3d06e9c3e07e13eab715e19dafbcfc1a0b7e43d6 commit r15-4758-g3d06e9c3e07e13eab715e19dafbcfc1a0b7e43d6 Author: Andi Kleen <a...@gcc.gnu.org> Date: Fri Oct 25 15:04:06 2024 -0700 Simplify switch bit test clustering algorithm The current switch bit test clustering enumerates all possible case clusters combinations to find ones that fit the bit test constrains best. This causes performance problems with very large switches. For bit test clustering which happens naturally in word sized chunks I don't think such an expensive algorithm is really needed. This patch implements a simple greedy algorithm that walks the sorted list and examines word sized windows and tries to cluster them. Surprisingly the new algorithm gives consistly better clusters for the examples I tried. For example from the gcc bootstrap: old: 0-15 16-31 96-175 new: 0-31 96-175 I'm not fully sure why that is, probably some bug in the old algorithm? This shows even up in the test suite where if-to-switch-6 now can generate a switch, as well as a case in switch-1.c I don't have a proof that the new algorithm is always as good or better, but so far at least I don't see any counter examples. It also fixes the excessive compile time in PR117091, however this was already fixed by an earlier patch that doesn't run clustering when no targets have multiple values. gcc/ChangeLog: PR middle-end/117091 * tree-switch-conversion.cc (bit_test_cluster::find_bit_tests): Change clustering algorithm to simple greedy. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/if-to-switch-6.c: Allow condition chain. * gcc.dg/tree-ssa/switch-1.c: Allow more bit tests. * gcc.dg/pr21643.c: Use -fno-bit-tests * gcc.target/aarch64/pr99988.c: Use -fno-bit-tests