From 63c25cc1cc4aef1ae5c7425496d99b30db2f44d7 Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Tue, 16 Aug 2022 20:41:48 +0200 Subject: [PATCH] wasm: fix callInstrinsic return value Rather than storing it in a local and returning that, we now keep this on the stack as all internal functions expect it to be on the stack already and therefore were generating extra `local.set` instructions. --- src/arch/wasm/CodeGen.zig | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 8eb3e2175b..95a0a8e4aa 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -4106,7 +4106,6 @@ fn fpext(self: *Self, operand: WValue, given: Type, wanted: Type) InnerError!WVa return f32_result; } if (wanted_bits == 64) { - try self.emitWValue(f32_result); try self.addTag(.f64_promote_f32); return WValue{ .stack = {} }; } @@ -4628,7 +4627,6 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) InnerError!WValue { Type.f32, &.{ rhs_ext, lhs_ext, addend_ext }, ); - defer result.free(self); return try (try self.fptrunc(result, Type.f32, ty)).toLocal(self, ty); } @@ -5353,6 +5351,7 @@ fn airShlSat(self: *Self, inst: Air.Inst.Index) InnerError!WValue { /// This function call assumes the C-ABI. /// Asserts arguments are not stack values when the return value is /// passed as the first parameter. +/// May leave the return value on the stack. fn callIntrinsic( self: *Self, name: []const u8, @@ -5398,8 +5397,6 @@ fn callIntrinsic( } else if (want_sret_param) { return sret; } else { - const result_local = try self.allocLocal(return_type); - try self.addLabel(.local_set, result_local.local); - return result_local; + return WValue{ .stack = {} }; } }