codegen.c: allow constant folding for multiply with zero.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-03-26 11:11:00 +09:00
parent 90969cef4c
commit a91b55f5ca
+2 -1
View File
@@ -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);
}