https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70992
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> --- We can simply do: --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -9387,6 +9387,11 @@ fold_binary_loc (location_t loc, TREE_TYPE (arg0), arg0, cst0)); } + /* Adding anything to a division-by-zero makes no sense and + can confuse extract_muldiv and fold_plusminus_mult_expr. */ + else if (TREE_CODE (arg0) == TRUNC_DIV_EXPR + && integer_zerop (TREE_OPERAND (arg0, 1))) + return fold_convert_loc (loc, type, arg0); } /* Handle (A1 * C1) + (A2 * C2) with A1, A2 or C1, C2 being the same or (In reply to Alexander Monakov from comment #6) > We can simply fold A / 0 * B and A / 0 + B to 1 / 0 or 0 / 0. > > I wonder why fold_plusminus_mult_expr puts the addition inside, that doesn't > appear useful? fold_plusminus_mult_expr tries to turn e.g. 2*a + a into 3*a, so that's where the + 1 comes from.