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.
This is the current pattern that matches the non-CST case: ``` /* Testing for overflow is unnecessary if we already know the result. */ /* A - B > A */ (for cmp (gt le) out (ne eq) (simplify (cmp:c (realpart (IFN_SUB_OVERFLOW@2 @0 @1)) @0) (if (TYPE_UNSIGNED (TREE_TYPE (@0)) && types_match (TREE_TYPE (@0), TREE_TYPE (@1))) (out (imagpart @2) { build_zero_cst (TREE_TYPE (@0)); })))) /* A + B < A */ (for cmp (lt ge) out (ne eq) (simplify (cmp:c (realpart (IFN_ADD_OVERFLOW:c@2 @0 @1)) @0) (if (TYPE_UNSIGNED (TREE_TYPE (@0)) && types_match (TREE_TYPE (@0), TREE_TYPE (@1))) (out (imagpart @2) { build_zero_cst (TREE_TYPE (@0)); })))) ``` Mine for GCC 15.