authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-08-16 20:41:48+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-08-18 14:17:01+02:00
log63c25cc1cc4aef1ae5c7425496d99b30db2f44d7
tree4601f32c41590e381b2249e3a90739371c01cb91
parentdf507edffe6c1087b5f4786cb64ccaffd02b6848

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.

1 files changed, 2 insertions(+), 5 deletions(-)

src/arch/wasm/CodeGen.zig+2-5
...@@ -4106,7 +4106,6 @@ fn fpext(self: *Self, operand: WValue, given: Type, wanted: Type) InnerError!WVa...@@ -4106,7 +4106,6 @@ fn fpext(self: *Self, operand: WValue, given: Type, wanted: Type) InnerError!WVa
4106 return f32_result;4106 return f32_result;
4107 }4107 }
4108 if (wanted_bits == 64) {4108 if (wanted_bits == 64) {
4109 try self.emitWValue(f32_result);
4110 try self.addTag(.f64_promote_f32);4109 try self.addTag(.f64_promote_f32);
4111 return WValue{ .stack = {} };4110 return WValue{ .stack = {} };
4112 }4111 }
...@@ -4628,7 +4627,6 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) InnerError!WValue {...@@ -4628,7 +4627,6 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
4628 Type.f32,4627 Type.f32,
4629 &.{ rhs_ext, lhs_ext, addend_ext },4628 &.{ rhs_ext, lhs_ext, addend_ext },
4630 );4629 );
4631 defer result.free(self);
4632 return try (try self.fptrunc(result, Type.f32, ty)).toLocal(self, ty);4630 return try (try self.fptrunc(result, Type.f32, ty)).toLocal(self, ty);
4633 }4631 }
46344632
...@@ -5353,6 +5351,7 @@ fn airShlSat(self: *Self, inst: Air.Inst.Index) InnerError!WValue {...@@ -5353,6 +5351,7 @@ fn airShlSat(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
5353/// This function call assumes the C-ABI.5351/// This function call assumes the C-ABI.
5354/// Asserts arguments are not stack values when the return value is5352/// Asserts arguments are not stack values when the return value is
5355/// passed as the first parameter.5353/// passed as the first parameter.
5354/// May leave the return value on the stack.
5356fn callIntrinsic(5355fn callIntrinsic(
5357 self: *Self,5356 self: *Self,
5358 name: []const u8,5357 name: []const u8,
...@@ -5398,8 +5397,6 @@ fn callIntrinsic(...@@ -5398,8 +5397,6 @@ fn callIntrinsic(
5398 } else if (want_sret_param) {5397 } else if (want_sret_param) {
5399 return sret;5398 return sret;
5400 } else {5399 } else {
5401 const result_local = try self.allocLocal(return_type);5400 return WValue{ .stack = {} };
5402 try self.addLabel(.local_set, result_local.local);
5403 return result_local;
5404 }5401 }
5405}5402}