https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80536
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> --- Yeah, it helps with this particular testcase (and I agree we want to get rid of that fold() call in save_expr -- I'll take care of it), but I wonder if this issue is something separate: starting with r230506 we can generate expressions such as i * ((unsigned long) -0 + 1) * 2 and given how fold() works we don't get to simplify the sub-expression "(unsigned long) -0 + 1)" so this expression isn't folded to "i * 2". So I wonder if we want something like --- a/gcc/convert.c +++ b/gcc/convert.c @@ -524,7 +524,13 @@ convert_to_integer_1 (tree type, tree expr, bool dofold) return expr; return build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR, TREE_TYPE (t), TREE_OPERAND (expr, 0), t); - } + } + + /* -0 is 0, so get rid of the NEGATE_EXPR. */ + if (0 && ex_form == NEGATE_EXPR + && TREE_CODE (TREE_OPERAND (expr, 0)) == INTEGER_CST + && integer_zerop (TREE_OPERAND (expr, 0))) + return convert_to_integer_maybe_fold (type, TREE_OPERAND (expr, 0), dofold); /* Convert e.g. (long)round(d) -> lround(d). */ /* If we're converting to char, we may encounter differing behavior