mruby-compiler (gen_move): avoid optimization of ADDI/SUBI
authorYukihiro "Matz" Matsumoto <[email protected]>
Tue, 20 May 2025 09:26:30 +0000 (20 18:26 +0900)
committerYukihiro "Matz" Matsumoto <[email protected]>
Tue, 20 May 2025 09:31:21 +0000 (20 18:31 +0900)
ADDI/SUBI may fall back to method call that may clear block argument
place holder, which may be a live register. So we cannot directly call
ADDI/SUBI over local variables.

mrbgems/mruby-compiler/core/codegen.c

index 0b68200..842214a 100644 (file)
@@ -663,8 +663,7 @@ gen_move(codegen_scope *s, uint16_t dst, uint16_t src, int nopeep)
       if (addr_pc(s, data.addr) == s->lastlabel || data.a != src || data.a < s->nlocals) goto normal;
       else {
         struct mrb_insn_data data0 = mrb_decode_insn(mrb_prev_pc(s, data.addr));
-        if (data0.insn != OP_MOVE || data0.a != data.a || data0.b != dst) goto normal;
-        s->pc = addr_pc(s, data0.addr);
+        if (data0.insn != OP_MOVE || data0.a != data.a || data0.b != dst) break;
         if (addr_pc(s, data0.addr) != s->lastlabel) {
           /* constant folding */
           data0 = mrb_decode_insn(mrb_prev_pc(s, data0.addr));
@@ -679,13 +678,12 @@ gen_move(codegen_scope *s, uint16_t dst, uint16_t src, int nopeep)
           }
         }
       }
-      genop_2(s, data.insn, dst, data.b);
-      return;
+      break;
     default:
       break;
     }
   }
- normal:
+
   genop_2(s, OP_MOVE, dst, src);
   return;
 }