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

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

https://gcc.gnu.org/g:3744f0db5dc3b9d290b1a7e58e1865fdbfbf8532

commit r17-4949-g3744f0db5dc3b9d290b1a7e58e1865fdbfbf8532
Author: Jakub Jelinek <[email protected]>
Date:   Wed Oct 7 10:14:06 2026 +0200

    match.pd: Check for overflow in x != CST1 ? x + CST2 : CST3 -> x + CST2
[PR126459]

    r17-126 has changed the simplification in a way where it can now
    introduce signed integer overflow into a program which didn't have it
before,
    e.g. x != (INT_MAX - 3) ? x + 5 : (INT_MIN + 1) when x is int
    doesn't invoke signed integer overflow for x equal to INT_MAX - 3 (it does
    for various other values and for many doesn't), while the simplified
    x + 5 invokes it even for that value.

    The following patch fixes it by checking for overflow on the CST1 + CST2
    addition, if TYPE_OVERFLOW_WRAPS or if CST1 + CST2 doesn't overflow,
    it does what it previously did, otherwise rewrites x + CST2 into
    unsigned.

    2026-10-07  Jakub Jelinek  <[email protected]>

            PR tree-optimization/126459
            * match.pd (x != CST1 ? x + CST2 : CST3 -> x + CST2): If
            CST1 + CST2 overflows and type overflow doesn't wrap,
            simplify into corresponding unsigned addition.

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

    Reviewed-by: Andrea Pinski <[email protected]>

Reply via email to