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

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrea Pinski <[email protected]>:

https://gcc.gnu.org/g:d8164f4da406c5061075472961b3c448604eb686

commit r17-4852-gd8164f4da406c5061075472961b3c448604eb686
Author: Andrea Pinski <[email protected]>
Date:   Fri Oct 2 05:36:15 2026 -0700

    match: Fix `(convert)abs((convert)a)` pattern for integer overflow
[PR127689]

    There are 2 patterns that are similar in match.pd for changing into
    a smaller abs. One handles `abs((ext)a)` and one for `(trunc)abs((ext)a)`.
    The one with the truncate afterwards does not use absu for integer types
    which can introduce undefined behavior in some cases.
    So let's restrict the second one to non integral types as the first one
    will handle those always; the check for casting from unsigned is another
    difference but the casting from unsigned is handled by a different abs
    pattern for non-negative values.

    Bootstrapped and tested on x86_64-linux-gnu.

            PR tree-optimization/127689

    gcc/ChangeLog:

            * match.pd (`(trunc)abs((ext)a)`): Move right
            after `abs((ext)a)` pattern.  Restrict to
            non integral types.

    gcc/testsuite/ChangeLog:

            * gcc.dg/torture/pr127689-1.c: New test.

    Signed-off-by: Andrea Pinski <[email protected]>

Reply via email to