https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126171
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Richard Biener <[email protected]>: https://gcc.gnu.org/g:2fcbe075ec3b32f4a523ebae68a8a32381bb46a9 commit r17-2412-g2fcbe075ec3b32f4a523ebae68a8a32381bb46a9 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.
