https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79818
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P3 |P1 Status|NEW |ASSIGNED Component|c |middle-end --- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> --- Hum, not sure how it escaped my review, but /* Transform comparisons of the form X +- C1 CMP C2 to X CMP C2 -+ C1. */ (for cmp (eq ne) (for op (plus minus) rop (minus plus) (simplify (cmp (op@3 @0 INTEGER_CST@1) INTEGER_CST@2) (if (!TREE_OVERFLOW (@1) && !TREE_OVERFLOW (@2) && !TYPE_OVERFLOW_SANITIZED (TREE_TYPE (@0)) && !TYPE_OVERFLOW_TRAPS (TREE_TYPE (@0)) && !TYPE_SATURATING (TREE_TYPE (@0))) (with { tree res = int_const_binop (rop, @2, @1); } (if (TREE_OVERFLOW (res)) { constant_boolean_node (cmp == NE_EXPR, type); } is quite different from /* Transform comparisons of the form X +- C1 CMP C2 to X CMP C2 -+ C1. */ if ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR) && (equality_code || (ANY_INTEGRAL_TYPE_P (TREE_TYPE (arg0)) && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg0)))) && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST && !TREE_OVERFLOW (TREE_OPERAND (arg0, 1)) && TREE_CODE (arg1) == INTEGER_CST && !TREE_OVERFLOW (arg1)) ... /* If the constant operation overflowed this can be simplified as a comparison against INT_MAX/INT_MIN. */ if (TREE_OVERFLOW (new_const) && !TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg0))) I belive it has to be && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg0)), otherwise we'd fold for -fno-strict-overflow. Testing the following. Index: gcc/match.pd =================================================================== --- gcc/match.pd (revision 245837) +++ gcc/match.pd (working copy) @@ -3688,7 +3688,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && !TYPE_OVERFLOW_TRAPS (TREE_TYPE (@0)) && !TYPE_SATURATING (TREE_TYPE (@0))) (with { tree res = int_const_binop (rop, @2, @1); } - (if (TREE_OVERFLOW (res)) + (if (TREE_OVERFLOW (res) + && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))) { constant_boolean_node (cmp == NE_EXPR, type); } (if (single_use (@3)) (cmp @0 { res; }))))))))