From 3a9375cae9a3385278e43a2785f4ccfe0dc47c2e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 2 Dec 2022 23:05:27 -0700 Subject: [PATCH] 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. --- src/arch/wasm/CodeGen.zig | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 1d240761540e1f5701f095adf61e685aca4a4111..d4e3559006b09e97a881cab477a87f2e884db367 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -2001,7 +2001,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { try func.restoreStackPointer(); try func.addTag(.@"return"); - return func.finishAir(inst, .none, &.{}); + return func.finishAir(inst, .none, &.{un_op}); } fn 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 { } break :result func.reuseOperand(ty_op.operand, operand); } else WValue{ .none = {} }; - func.finishAir(inst, result, &.{}); + func.finishAir(inst, result, &.{ty_op.operand}); } fn 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 { const len = try func.resolveInst(bin_op.rhs); try func.memset(ptr, len, value); - func.finishAir(inst, .none, &.{pl_op.operand}); + func.finishAir(inst, .none, &.{ pl_op.operand, bin_op.lhs, bin_op.rhs }); } /// 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 { else => unreachable, } }; + // TODO: this is incorrect Liveness handling code func.finishAir(inst, result, &.{}); } @@ -4747,7 +4748,7 @@ fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { const len = try func.resolveInst(bin_op.rhs); try func.memcpy(dst, src, len); - func.finishAir(inst, .none, &.{pl_op.operand}); + func.finishAir(inst, .none, &.{ pl_op.operand, bin_op.lhs, bin_op.rhs }); } fn 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 fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { const pl_op = func.air.instructions.items(.data)[inst].pl_op; const bin_op = func.air.extraData(Air.Bin, pl_op.payload).data; - if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs }); + if (func.liveness.isUnused(inst)) + return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs, pl_op.operand }); const ty = func.air.typeOfIndex(inst); if (ty.zigTypeTag() == .Vector) { @@ -5186,7 +5188,7 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { break :result try (try func.binOp(mul_result, addend, ty, .add)).toLocal(func, ty); }; - func.finishAir(inst, result, &.{ bin_op.lhs, bin_op.rhs }); + func.finishAir(inst, result, &.{ bin_op.lhs, bin_op.rhs, pl_op.operand }); } fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { -- 2.54.0