From a91b55f5ca6828f5a15fbb6a673c7b2da3ff6647 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 26 Mar 2022 11:11:00 +0900 Subject: [PATCH] codegen.c: allow constant folding for multiply with zero. --- mrbgems/mruby-compiler/core/codegen.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 1a4f6b213..258aee8ae 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -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); }