codegen.c: peephole optimize consecutive MOVE instructions.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-03-29 22:36:40 +09:00
parent 9593c15603
commit 60cf382ff9
+11 -2
View File
@@ -594,9 +594,18 @@ gen_move(codegen_scope *s, uint16_t dst, uint16_t src, int nopeep)
switch (data.insn) {
case OP_MOVE:
if (dst == src) return; /* remove useless MOVE */
if (data.b == dst && data.a == src) /* skip swapping MOVE */
if (dst == src) return; /* remove useless MOVE */
if (data.a == src) {
if (data.b == dst) /* skip swapping MOVE */
return;
if (data.a < s->nlocals) goto normal;
rewind_pc(s);
genop_2(s, OP_MOVE, dst, data.b);
return;
}
if (dst == data.a) { /* skip overwritten move */
rewind_pc(s);
}
goto normal;
case OP_LOADNIL: case OP_LOADSELF: case OP_LOADT: case OP_LOADF:
case OP_LOADI__1: