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

--- Comment #4 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:ffc389cb11a2a61fb89b6034d3f3fe0896b29064

commit r15-4024-gffc389cb11a2a61fb89b6034d3f3fe0896b29064
Author: Filip Kastl <fka...@suse.cz>
Date:   Wed Oct 2 14:14:44 2024 +0200

    gimple ssa: Don't use __builtin_popcount in switch exp transform [PR116616]

    Switch exponential transformation in the switch conversion pass
    currently generates

    tmp1 = __builtin_popcount (var);
    tmp2 = tmp1 == 1;

    when inserting code to determine if var is power of two.  If the target
    doesn't support expanding the builtin as special instructions switch
    conversion relies on this whole pattern being expanded as bitmagic.
    However, it is possible that other GIMPLE optimizations move the two
    statements of the pattern apart.  In that case the builtin becomes a
    libgcc call in the final binary.  The call is slow and in case of
    freestanding programs can result in linking error (this bug was
    originally found while compiling Linux kernel).

    This patch modifies switch conversion to insert the bitmagic
    (var ^ (var - 1)) > (var - 1) instead of the builtin.

    gcc/ChangeLog:

            PR tree-optimization/116616
            * tree-switch-conversion.cc (can_pow2p): Remove this function.
            (gen_pow2p): Generate bitmagic instead of a builtin.  Remove the
            TYPE parameter.
            (switch_conversion::is_exp_index_transform_viable): Don't call
            can_pow2p.
            (switch_conversion::exp_index_transform): Call gen_pow2p without
            the TYPE parameter.
            * tree-switch-conversion.h: Remove
            m_exp_index_transform_pow2p_type.

    gcc/testsuite/ChangeLog:

            PR tree-optimization/116616
            * gcc.target/i386/switch-exp-transform-1.c: Don't test for
            presence of the POPCOUNT internal fn call.

    Signed-off-by: Filip Kastl <fka...@suse.cz>

Reply via email to