From 70f31d4bb4b251d13c959557552e1c285878f5f3 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 16 Jul 2021 07:55:25 +0900 Subject: codegen.c: add new peephole optimization for `OP_MOVE`. If `OP_MOVE` comes after `OP_GETUPVAR`, you can skip move and redirect the destination register of `OP_GETUPVAR`. --- mrbgems/mruby-compiler/core/codegen.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index fce55999d..f3d6d2d25 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -488,6 +488,11 @@ gen_move(codegen_scope *s, uint16_t dst, uint16_t src, int nopeep) s->pc = s->lastpc; genop_2(s, data.insn, dst, data.b); break; + case OP_GETUPVAR: + if (nopeep || data.a != src || data.a < s->nlocals) goto normal; + s->pc = s->lastpc; + genop_3(s, data.insn, dst, data.b, data.c); + break; default: goto normal; } -- cgit v1.2.3