https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98028
--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jeff Law <l...@gcc.gnu.org>: https://gcc.gnu.org/g:42a22b801d4ad654e420495fafc4d29d113f00eb commit r15-7571-g42a22b801d4ad654e420495fafc4d29d113f00eb Author: Jakub Jelinek <ja...@redhat.com> Date: Sat Feb 15 16:45:21 2025 -0700 [PR tree-optimization/98028] Use relationship between operands to simplify SUB_OVERFLOW So this is a fairly old regression, but with all the ranger work that's been done, it's become easy to resolve. The basic idea here is to use known relationships between two operands of a SUB_OVERFLOW IFN to statically compute the overflow state and ultimately allow turning the IFN into simple arithmetic (or for the tests in this BZ elide the arithmetic entirely). The regression example is when the two inputs are known equal. In that case the subtraction will never overflow. But there's a few other cases we can handle as well. a == b -> never overflows a > b -> never overflows when A and B are unsigned a >= b -> never overflows when A and B are unsigned a < b -> always overflows when A and B are unsigned Bootstrapped and regression tested on x86, and regression tested on the usual cross platforms. This is Jakub's version of the vr-values.cc fix rather than Jeff's. PR tree-optimization/98028 gcc/ * vr-values.cc (check_for_binary_op_overflow): Try to use a known relationship betwen op0/op1 to statically determine overflow state. gcc/testsuite * gcc.dg/tree-ssa/pr98028.c: New test.