From: Brendan Hansen Date: Sat, 15 Aug 2020 15:42:13 +0000 (-0500) Subject: optimized local.set followed by local.get X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=4753d9d7e671924f224476651c3b6304afc0b652;p=onyx.git optimized local.set followed by local.get --- diff --git a/onyx b/onyx index 77ebf6e3..2a1eabd4 100755 Binary files a/onyx and b/onyx differ diff --git a/src/onyxwasm.c b/src/onyxwasm.c index 822480c5..edffc14a 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -1085,10 +1085,12 @@ COMPILE_FUNC(struct_load, Type* type, u64 offset) { } u64 tmp_idx = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); - WIL(WI_LOCAL_SET, tmp_idx); + WIL(WI_LOCAL_TEE, tmp_idx); + b32 first = 1; bh_arr_each(StructMember *, smem, type->Struct.memarr) { - WIL(WI_LOCAL_GET, tmp_idx); + if (first) first = 0; + else WIL(WI_LOCAL_GET, tmp_idx); compile_load_instruction(mod, &code, (*smem)->type, offset + (*smem)->offset); } @@ -1154,7 +1156,11 @@ COMPILE_FUNC(expression, AstTyped* expr) { case Ast_Kind_Local: { u64 tmp = bh_imap_get(&mod->local_map, (u64) expr); if (tmp & LOCAL_IS_WASM) { - WIL(WI_LOCAL_GET, tmp); + if (bh_arr_last(code).type == WI_LOCAL_SET && bh_arr_last(code).data.l == tmp) { + bh_arr_last(code).type = WI_LOCAL_TEE; + } else { + WIL(WI_LOCAL_GET, tmp); + } } else { u64 offset = 0;