summaryrefslogtreecommitdiffhomepage
path: root/mrbgems
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-12-01 14:29:44 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-12-01 14:29:44 +0900
commit76659a66ae43ae18211b1050fcf724168508c2d8 (patch)
tree7186384db39761c571e832af38b6ca02c83c4d08 /mrbgems
parent7d6b8024b56f59289baba5bc94a4ab5bf82f8298 (diff)
downloadmruby-76659a66ae43ae18211b1050fcf724168508c2d8.tar.gz
mruby-76659a66ae43ae18211b1050fcf724168508c2d8.zip
codegen.c: skip `ADDI/SUBI` for zero operand.
Diffstat (limited to 'mrbgems')
-rw-r--r--mrbgems/mruby-compiler/core/codegen.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c
index a1cde4d7d..fa7a98921 100644
--- a/mrbgems/mruby-compiler/core/codegen.c
+++ b/mrbgems/mruby-compiler/core/codegen.c
@@ -781,6 +781,7 @@ gen_addsub(codegen_scope *s, uint8_t op, uint16_t dst)
/* OP_ADDI/OP_SUBI takes upto 16bits */
if (n > INT16_MAX || n < INT16_MIN) goto normal;
rewind_pc(s);
+ if (n == 0) return;
if (n > 0) {
if (op == OP_ADD) genop_2(s, OP_ADDI, dst, (uint16_t)n);
else genop_2(s, OP_SUBI, dst, (uint16_t)n);