[Bug tree-optimization/126171] [16 Regression] miscompilation at -O2 on x86_64-linux-gnu

"cvs-commit at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126171

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

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

commit r16-9382-ga32b49435b4e3d6bb2510197f2ee4b3ff887cd62
Author: Richard Biener <[email protected]>
Date:   Wed Jul 15 10:04:18 2026 +0200

    tree-optimization/126171 - SCEV and minus of INT_MIN

    The following fixes the existing mitigation against UB for handling
    of subtraction of the most negative value in a type.  We've only
    guarded the negation itself which is effective for avoiding UB in
    that but it does not help in fixing a wrong scev_direction that
    results from flipping the operation from minus to plus.  So the
    patch, instead of only promoting the negation to unsigned, promotes
    the whole operation.

            PR tree-optimization/126171
            * tree-scalar-evolution.cc (scev_dfs::add_to_evolution):
            Remove code argument.  Remove MINUS_EXPR handling here.
            (scev_dfs::follow_ssa_edge_binary): Likewise.
            (scev_dfs::follow_ssa_edge_expr): Handle MINUS_EXPR
            separately here, promoting the whole operation to unsigned
            instead of just the addend.

            * gcc.dg/pr126171-1.c: New testcase.
            * gcc.dg/torture/pr126171-2.c: Likewise.

    (cherry picked from commit 2fcbe075ec3b32f4a523ebae68a8a32381bb46a9)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.