zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit f2860bb4f40565e43f51757e6cb604bb2df16ae0 (tree)
parent 67d27dbe631d1292be363f4121217d66e2d7fd0f
Author: Luuk de Gram <luuk@degram.dev>
Date:   Sun,  7 May 2023 18:48:25 +0200

wasm: more liveness fixes

Diffstat:
Msrc/arch/wasm/CodeGen.zig | 7++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig @@ -880,10 +880,11 @@ fn processDeath(func: *CodeGen, ref: Air.Inst.Ref) void { // TODO: Upon branch consolidation free any locals if needed. const value = func.currentBranch().values.getPtr(ref) orelse return; if (value.* != .local) return; - log.debug("Decreasing reference for ref: %{?d}\n", .{Air.refToIndex(ref)}); - if (value.local.value < func.arg_index) { + const reserved_indexes = func.args.len + @boolToInt(func.return_value != .none); + if (value.local.value < reserved_indexes) { return; // function arguments can never be re-used } + log.debug("Decreasing reference for ref: %{?d}, using local '{d}'\n", .{ Air.refToIndex(ref), value.local.value }); value.local.references -= 1; // if this panics, a call to `reuseOperand` was forgotten by the developer if (value.local.references == 0) { value.free(func); @@ -4024,7 +4025,7 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { return func.fail("todo Wasm intcast for bitsize > 128", .{}); } - const op_bits = toWasmBits(@intCast(u16, ty.bitSize(func.target))).?; + const op_bits = toWasmBits(@intCast(u16, operand_ty.bitSize(func.target))).?; const wanted_bits = toWasmBits(@intCast(u16, ty.bitSize(func.target))).?; const result = if (op_bits == wanted_bits) func.reuseOperand(ty_op.operand, operand)