https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114539
Bug ID: 114539 Summary: `__builtin_add_overflow(unsigned, b, &r); r < b` where b is a CST is not optimized to using the overflow Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` bool f(unsigned v, unsigned tt) { unsigned r; unsigned t = __builtin_add_overflow(v, tt, &r); return (r < tt) == t; } bool f1(unsigned v, unsigned tt) { tt = 3; unsigned r; unsigned t = __builtin_add_overflow(v, tt, &r); return (r < tt) == t; } ``` f is able to be optimized to 1 but f1 is not due to the `r < 3` being Canonical form being `r <= 2` (or in the case of 1, `r == 0`). I found this while looking into PR 114538 if we change things slightly.