https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70992

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
The bad recursion happens between extract_muldiv_1

      /* The last case is if we are a multiply.  In that case, we can
         apply the distributive law to commute the multiply and addition
         if the multiplication of the constants doesn't overflow
         and overflow is defined.  With undefined overflow
         op0 * c might overflow, while (op0 + orig_op1) * c doesn't.  */
      if (code == MULT_EXPR && TYPE_OVERFLOW_WRAPS (ctype))
        return fold_build2 (tcode, ctype,
                            fold_build2 (code, ctype,
                                         fold_convert (ctype, op0),
                                         fold_convert (ctype, c)),
                            op1);

which does (0 % 0 + 1) * 2 -> (0 % 0) * 2 + 2 and the reverse transformation
fold_plusminus_mult_expr does.

Reply via email to