authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-02 23:05:27-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-04 15:57:40-07:00
log3a9375cae9a3385278e43a2785f4ccfe0dc47c2e
tree2f6795a701780942c6cd48eb5f76180dfeb84f56
parent954019983d17fad9dac1c80e2de92cb7ebe7cd08

wasm codegen: fix some missing Liveness reaps

I did not do a full audit, but I did notice a few issues which are resolved in this commit. Probably it would be worth adding debug infrastructure to assert that the number of reaps equals the number of calls to resolveInst() per air lowering function.

1 files changed, 8 insertions(+), 6 deletions(-)

src/arch/wasm/CodeGen.zig+8-6
......@@ -2001,7 +2001,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
20012001
20022002 try func.restoreStackPointer();
20032003 try func.addTag(.@"return");
2004 return func.finishAir(inst, .none, &.{});
2004 return func.finishAir(inst, .none, &.{un_op});
20052005}
20062006
20072007fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.Modifier) InnerError!void {
......@@ -3161,7 +3161,7 @@ fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
31613161 }
31623162 break :result func.reuseOperand(ty_op.operand, operand);
31633163 } else WValue{ .none = {} };
3164 func.finishAir(inst, result, &.{});
3164 func.finishAir(inst, result, &.{ty_op.operand});
31653165}
31663166
31673167fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) InnerError!WValue {
......@@ -4115,7 +4115,7 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41154115 const len = try func.resolveInst(bin_op.rhs);
41164116 try func.memset(ptr, len, value);
41174117
4118 func.finishAir(inst, .none, &.{pl_op.operand});
4118 func.finishAir(inst, .none, &.{ pl_op.operand, bin_op.lhs, bin_op.rhs });
41194119}
41204120
41214121/// Sets a region of memory at `ptr` to the value of `value`
......@@ -4424,6 +4424,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44244424 else => unreachable,
44254425 }
44264426 };
4427 // TODO: this is incorrect Liveness handling code
44274428 func.finishAir(inst, result, &.{});
44284429}
44294430
......@@ -4747,7 +4748,7 @@ fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47474748 const len = try func.resolveInst(bin_op.rhs);
47484749 try func.memcpy(dst, src, len);
47494750
4750 func.finishAir(inst, .none, &.{pl_op.operand});
4751 func.finishAir(inst, .none, &.{ pl_op.operand, bin_op.lhs, bin_op.rhs });
47514752}
47524753
47534754fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
......@@ -5158,7 +5159,8 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: enum { max, min }) InnerE
51585159fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51595160 const pl_op = func.air.instructions.items(.data)[inst].pl_op;
51605161 const bin_op = func.air.extraData(Air.Bin, pl_op.payload).data;
5161 if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
5162 if (func.liveness.isUnused(inst))
5163 return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs, pl_op.operand });
51625164
51635165 const ty = func.air.typeOfIndex(inst);
51645166 if (ty.zigTypeTag() == .Vector) {
......@@ -5186,7 +5188,7 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51865188 break :result try (try func.binOp(mul_result, addend, ty, .add)).toLocal(func, ty);
51875189 };
51885190
5189 func.finishAir(inst, result, &.{ bin_op.lhs, bin_op.rhs });
5191 func.finishAir(inst, result, &.{ bin_op.lhs, bin_op.rhs, pl_op.operand });
51905192}
51915193
51925194fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {