https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81148
--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> --- Seems like we need something similar to --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -874,9 +874,23 @@ split_tree (location_t loc, tree in, tree type, enum tree_code code, } if (var) { - /* Convert to TYPE before negating. */ - var = fold_convert_loc (loc, type, var); - var = negate_expr (var); + if ((*litp == NULL_TREE + && *conp == NULL_TREE + && *minus_litp == NULL_TREE) + || negate_expr_p (var)) + { + /* Convert to TYPE before negating. */ + var = fold_convert_loc (loc, type, var); + var = negate_expr (var); + } + else + { + /* Go back to blank slate. */ + var = in; + *conp = NULL_TREE; + *litp = NULL_TREE; + *minus_litp = NULL_TREE; + } } }