authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-10-15 19:08:08+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-10-16 15:54:17+02:00
logff1cab037c1a770fba558b9d888a01a5b71190b8
tree6473822c58adea83afda16b69fc720000385e07f
parent273b8e20ca086b62debc869e1c375cd834043e24
signaturelock-open Commit is signed but in an unrecognized format.

wasm: re-use operands

When we return an operand directly as a result, we must call `reuseOperand`. This commit ensures it's done for all currently- implemented AIR instructions.

1 files changed, 16 insertions(+), 14 deletions(-)

src/arch/wasm/CodeGen.zig+16-14
......@@ -3403,7 +3403,7 @@ fn airUnwrapErrUnionError(self: *Self, inst: Air.Inst.Index, op_is_ptr: bool) In
34033403 }
34043404
34053405 if (op_is_ptr or !payload_ty.hasRuntimeBitsIgnoreComptime()) {
3406 break :result operand;
3406 break :result self.reuseOperand(ty_op.operand, operand);
34073407 }
34083408
34093409 const error_val = try self.load(operand, Type.anyerror, @intCast(u32, errUnionErrorOffset(payload_ty, self.target)));
......@@ -3422,7 +3422,7 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) InnerError!void {
34223422 const pl_ty = self.air.typeOf(ty_op.operand);
34233423 const result = result: {
34243424 if (!pl_ty.hasRuntimeBitsIgnoreComptime()) {
3425 break :result operand;
3425 break :result self.reuseOperand(ty_op.operand, operand);
34263426 }
34273427
34283428 const err_union = try self.allocStack(err_ty);
......@@ -3449,7 +3449,7 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) InnerError!void {
34493449
34503450 const result = result: {
34513451 if (!pl_ty.hasRuntimeBitsIgnoreComptime()) {
3452 break :result operand;
3452 break :result self.reuseOperand(ty_op.operand, operand);
34533453 }
34543454
34553455 const err_union = try self.allocStack(err_ty);
......@@ -3481,7 +3481,7 @@ fn airIntcast(self: *Self, inst: Air.Inst.Index) InnerError!void {
34813481 }
34823482
34833483 const result = try (try self.intcast(operand, operand_ty, ty)).toLocal(self, ty);
3484 self.finishAir(inst, result, &.{ty_op.operand});
3484 self.finishAir(inst, result, &.{});
34853485}
34863486
34873487/// Upcasts or downcasts an integer based on the given and wanted types,
......@@ -3579,7 +3579,7 @@ fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) InnerError!void {
35793579
35803580 const result = result: {
35813581 const operand = try self.resolveInst(ty_op.operand);
3582 if (opt_ty.optionalReprIsPayload()) break :result operand;
3582 if (opt_ty.optionalReprIsPayload()) break :result self.reuseOperand(ty_op.operand, operand);
35833583
35843584 const offset = opt_ty.abiSize(self.target) - payload_ty.abiSize(self.target);
35853585
......@@ -3603,7 +3603,7 @@ fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) InnerError!void {
36033603 var buf: Type.Payload.ElemType = undefined;
36043604 const payload_ty = opt_ty.optionalChild(&buf);
36053605 if (!payload_ty.hasRuntimeBitsIgnoreComptime() or opt_ty.optionalReprIsPayload()) {
3606 break :result operand;
3606 break :result self.reuseOperand(ty_op.operand, operand);
36073607 }
36083608
36093609 const offset = opt_ty.abiSize(self.target) - payload_ty.abiSize(self.target);
......@@ -3656,7 +3656,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) InnerError!void {
36563656 const operand = try self.resolveInst(ty_op.operand);
36573657 const op_ty = self.air.typeOfIndex(inst);
36583658 if (op_ty.optionalReprIsPayload()) {
3659 break :result operand;
3659 break :result self.reuseOperand(ty_op.operand, operand);
36603660 }
36613661 const offset = std.math.cast(u32, op_ty.abiSize(self.target) - payload_ty.abiSize(self.target)) orelse {
36623662 const module = self.bin_file.base.options.module.?;
......@@ -3793,8 +3793,10 @@ fn airBoolToInt(self: *Self, inst: Air.Inst.Index) InnerError!void {
37933793 const un_op = self.air.instructions.items(.data)[inst].un_op;
37943794 const result = if (self.liveness.isUnused(inst))
37953795 WValue{ .none = {} }
3796 else
3797 try self.resolveInst(un_op);
3796 else result: {
3797 const operand = try self.resolveInst(un_op);
3798 break :result self.reuseOperand(un_op, operand);
3799 };
37983800
37993801 self.finishAir(inst, result, &.{un_op});
38003802}
......@@ -3939,7 +3941,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index) InnerError!void {
39393941 const len = try self.resolveInst(bin_op.rhs);
39403942 try self.memset(ptr, len, value);
39413943
3942 self.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
3944 self.finishAir(inst, .none, &.{pl_op.operand});
39433945}
39443946
39453947/// Sets a region of memory at `ptr` to the value of `value`
......@@ -4489,7 +4491,7 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) InnerError!void {
44894491 if (self.liveness.isUnused(inst)) break :result WValue{ .none = {} };
44904492
44914493 if (!payload_ty.hasRuntimeBitsIgnoreComptime()) {
4492 break :result operand;
4494 break :result self.reuseOperand(ty_op.operand, operand);
44934495 }
44944496
44954497 break :result try self.buildPointerOffset(operand, @intCast(u32, errUnionPayloadOffset(payload_ty, self.target)), .new);
......@@ -4513,7 +4515,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) InnerError!void {
45134515 try self.addTag(.i32_sub);
45144516 try self.addLabel(.local_set, base.local.value);
45154517 break :result base;
4516 } else field_ptr;
4518 } else self.reuseOperand(extra.field_ptr, field_ptr);
45174519
45184520 self.finishAir(inst, result, &.{extra.field_ptr});
45194521}
......@@ -4526,7 +4528,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) InnerError!void {
45264528 const len = try self.resolveInst(bin_op.rhs);
45274529 try self.memcpy(dst, src, len);
45284530
4529 self.finishAir(inst, .none, &.{ pl_op.operand, bin_op.lhs, bin_op.rhs });
4531 self.finishAir(inst, .none, &.{pl_op.operand});
45304532}
45314533
45324534fn airPopcount(self: *Self, inst: Air.Inst.Index) InnerError!void {
......@@ -5220,7 +5222,7 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) InnerError!void {
52205222
52215223 // bytes are no-op
52225224 if (int_info.bits == 8) {
5223 return self.finishAir(inst, operand, &.{ty_op.operand});
5225 return self.finishAir(inst, self.reuseOperand(ty_op.operand, operand), &.{ty_op.operand});
52245226 }
52255227
52265228 const result = result: {