https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93742
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- One thing which could be done is take: _1 = a_10(D) > 0; _2 = a_10(D) < 0; _3 = 2147483647 - a_10(D); // INT_MAX - a _4 = _3 < b_11(D); _9 = _1 & _4; _5 = -2147483648 - a_10(D); // INT_MIN - a _6 = _5 > b_11(D); _13 = _2 & _6; _14 = _9 | _13; And recognize that as _5 = .ADD_OVERFLOW (a_3(D), b_4(D)); _1 = IMAGPART_EXPR <_5>; But that won't catch the original testcase right away though as the incoming gimple has a lot of branches. The above was provided by: bool add_overflow(int a, int b, int *res) { int t= 0; int t1; int ty = a > 0; int ty1 = a < 0; int tt = ty & b > INT_MAX - a; int tt1 = ty1 & b < INT_MIN - a; if (tt | tt1) { t1= 1; } else { *res = a + b; t1= 0; } return t1; } Note not even clang is able to detect the above really.