Skip to content

Commit

Permalink
codegen.c: allow constant folding for multiply with zero.
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Mar 26, 2022
1 parent 90969ce commit a91b55f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mrbgems/mruby-compiler/core/codegen.c
Expand Up @@ -844,13 +844,14 @@ gen_muldiv(codegen_scope *s, uint8_t op, uint16_t dst)
goto normal;
}
struct mrb_insn_data data0 = mrb_decode_insn(mrb_prev_pc(s, data.addr));
if (!get_int_operand(s, &data0, &n0) || n == 0) {
if (!get_int_operand(s, &data0, &n0)) {
goto normal;
}
if (op == OP_MUL) {
if (mrb_int_mul_overflow(n0, n, &n)) goto normal;
}
else { /* OP_DIV */
if (n == 0) goto normal;
if (n0 == MRB_INT_MIN && n == -1) goto normal;
n = mrb_div_int(s->mrb, n0, n);
}
Expand Down

0 comments on commit a91b55f

Please sign in to comment.