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

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-16 branch has been updated by Jakub Jelinek
<[email protected]>:

https://gcc.gnu.org/g:55c6e77b50ac93f423086f1b4c87de7c2de3c6c4

commit r16-10056-g55c6e77b50ac93f423086f1b4c87de7c2de3c6c4
Author: Jakub Jelinek <[email protected]>
Date:   Wed Dec 2 11:51:23 2026 +0100

    combine: Fix up handling of TImode CONST_INT (-LONG_LONG_MAX-1) [PR129169]

    The combiner has lots of places where it checks if some rtx is
    CONST_INT_P and then calls exact_log2 on its UINTVAL and if that
    yields >= 0, great, we have a power of two and it performs
    some optimizations.

    Now, the problem is that this works reliably only if exact_log2
    returns something smaller than HOST_BITS_PER_WIDE_INT - 1 or
    if it returns HOST_BITS_PER_WIDE_INT - 1 if it is a DImode
    operation.  If it is larger than that, because CONST_INTs are
    always sign extended, it is actually not a power of two, e.g.
    (__int128) (-LONG_LONG_MAX - 1) has 65 bits set instead of
    just 1, ditto for unsigned __int128.

    Two spots have INTVAL (something) > 0 checks before the
    exact_log2 (UINTVAL (something)) calls, others don't.
    This patch just adds further INTVAL (something) > 0 checks.
    It will regress the DImode cases but it is odd that those
    work when for [QHS]Imode it doesn't because CONST_INTs are
    sign-extended from mode and so exact_log2 fails on those.
    And it fixes the TImode cases.

    2026-12-02  Jakub Jelinek  <[email protected]>

            PR rtl-optimization/129169
            * combine.cc (combine_simplify_rtx, simplify_shift_const_1):
            Don't use exact_log2 on CONST_INTs with MSB set.

            * gcc.dg/torture/pr129169.c: New test.

    Reviewed-by: Richard Biener <[email protected]>
    (cherry picked from commit 6159c16312c8670c7d523a1133821c8c74c9b772)

Reply via email to