https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61045
--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> --- /* Put the constant on the side where it doesn't overflow and is of lower absolute value than before. */ cst = int_const_binop (TREE_CODE (arg0) == TREE_CODE (arg1) ? MINUS_EXPR : PLUS_EXPR, const2, const1); if (!TREE_OVERFLOW (cst) && tree_int_cst_compare (const2, cst) == tree_int_cst_sgn (const2)) const2 is -1 here and cst is 1. So that means just checking for "lower absolute value" is wrong. A sign-change is obviously not ok either.