From 51633afe56eb1903bf025a29ba4af08fee9affc3 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 26 Nov 2023 16:54:43 +0100 Subject: [PATCH] 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. --- quickjs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/quickjs.c b/quickjs.c index 65a9026..e9f5197 100644 --- a/quickjs.c +++ b/quickjs.c @@ -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: