Remove no-op OP_swap+OP_swap bytecode sequence (#143)

Observed in generated code for static initializers. We could in theory
track and correct it in js_parse_class() but doing it as a peephole
optimization is both easier and more general.
This commit is contained in:
Ben Noordhuis 2023-11-26 16:54:43 +01:00 committed by GitHub
parent fb1b1ced26
commit 51633afe56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29675,6 +29675,15 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s)
}
goto no_change;
case OP_swap:
// transformation: swap swap -> nothing!
if (code_match(&cc, pos_next, OP_swap, -1, -1)) {
if (cc.line_num >= 0) line_num = cc.line_num;
pos_next = cc.pos;
break;
}
goto no_change;
case OP_get_loc:
{
/* transformation: