https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117091

--- Comment #21 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Filip Kastl <phe...@gcc.gnu.org>:

https://gcc.gnu.org/g:56946c801a7cf3a831a11870b7e11ba08bf9bd87

commit r15-6120-g56946c801a7cf3a831a11870b7e11ba08bf9bd87
Author: Filip Kastl <fka...@suse.cz>
Date:   Wed Dec 11 19:57:04 2024 +0100

    gimple: Add limit after which slower switchlower algs are used [PR117091]
[PR117352]

    This patch adds a limit on the number of cases of a switch.  When this
    limit is exceeded, switch lowering decides to use faster but less
    powerful algorithms.

    In particular this means that for finding bit tests switch lowering
    decides between the old dynamic programming O(n^2) algorithm and the
    new greedy algorithm that Andi Kleen recently added but then reverted
    due to PR117352.  It also means that switch lowering may bail out on
    finding jump tables if the switch is too large  (Btw it also may not
    bail!  It can happen that the greedy algorithms finds some bit tests
    which then basically split the switch into multiple smaller switches and
    those may be small enough to fit under the limit.)

    The limit is implemented as --param switch-lower-slow-alg-max-cases.
    Exceeding the limit is reported through -Wdisabled-optimization.

    This patch fixes the issue with the greedy algorithm described in
    PR117352.  The problem was incorrect usage of the is_beneficial()
    heuristic.

    gcc/ChangeLog:

            PR middle-end/117091
            PR middle-end/117352
            * doc/invoke.texi: Add switch-lower-slow-alg-max-cases.
            * params.opt: Add switch-lower-slow-alg-max-cases.
            * tree-switch-conversion.cc (jump_table_cluster::find_jump_tables):
            Note in a comment that we are looking for jump tables in
            case sequences delimited by the already found bit tests.
            (bit_test_cluster::find_bit_tests): Decide between
            find_bit_tests_fast() and find_bit_tests_slow().
            (bit_test_cluster::find_bit_tests_fast): New function.
            (bit_test_cluster::find_bit_tests_slow): New function.
            (switch_decision_tree::analyze_switch_statement): Report
            exceeding the limit.
            * tree-switch-conversion.h: Add find_bit_tests_fast() and
            find_bit_tests_slow().

    Co-Authored-By: Andi Kleen <a...@gcc.gnu.org>
    Signed-off-by: Filip Kastl <fka...@suse.cz>

Reply via email to