https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127103
--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Dominic Plunkett <[email protected]>: https://gcc.gnu.org/g:c8aaf14bf6882705d2515a5eb9c15de7f4034c5b commit r17-4800-gc8aaf14bf6882705d2515a5eb9c15de7f4034c5b Author: Dominic P <[email protected]> Date: Tue Sep 29 09:20:27 2026 +0100 match.pd: Check that a - c does not wrap in minmax (a - c, b) + c [PR127103] r17-4378 folds minmax (a - c, b) + c to minmax (a, b + c) when b + c cannot overflow. The fold also needs a - c not to wrap: for unsigned a = 0, b = 0, c = 1, MIN (a - c, b) + c is 1 but MIN (a, b + c) is 0, and the MAX form gives 0 against 1. Require that with range_op_handler (MINUS_EXPR).overflow_free_p on the ranges of a and c. The std::vector::push_back case from the PR, where a is 2147483647, still folds. Bootstrapped and regression tested on x86_64-pc-linux-gnu, and dg.exp, tree-ssa.exp and execute.exp on aarch64-linux-gnu under qemu. Assisted-by: Claude Opus 5 (Anthropic) PR tree-optimization/127103 gcc/ChangeLog: * match.pd (minmax (a - c, b) + c): Also require that a - c does not overflow. gcc/testsuite/ChangeLog: * gcc.dg/torture/pr127103.c: New test. Signed-off-by: Dominic P <[email protected]>
