codegen.c: peephole optimize OP_MOVE after OP_ARRAY or OP_ARRAY2.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-02-22 17:27:24 +09:00
parent c37f648552
commit d4d29b21b3
+14 -1
View File
@@ -606,7 +606,7 @@ gen_move(codegen_scope *s, uint16_t dst, uint16_t src, int nopeep)
rewind_pc(s);
genop_1(s, data.insn, dst);
return;
case OP_HASH: case OP_ARRAY:
case OP_HASH:
if (data.b != 0) goto normal;
/* fall through */
case OP_LOADI: case OP_LOADINEG:
@@ -631,6 +631,19 @@ gen_move(codegen_scope *s, uint16_t dst, uint16_t src, int nopeep)
genop_2SS(s, data.insn, dst, i);
}
return;
case OP_ARRAY:
if (data.a != src || data.a < s->nlocals || data.a < dst) goto normal;
rewind_pc(s);
if (data.b == 0)
genop_2(s, OP_ARRAY, dst, 0);
else
genop_3(s, OP_ARRAY2, dst, data.a, data.b);
return;
case OP_ARRAY2:
if (data.a != src || data.a < s->nlocals || data.a < dst) goto normal;
rewind_pc(s);
genop_3(s, OP_ARRAY2, dst, data.b, data.c);
return;
case OP_AREF:
case OP_GETUPVAR:
if (data.a != src || data.a < s->nlocals) goto normal;