From 4aae0b09cfdc444a0b4e98d3ed7f83bfe421c06f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 3 Dec 2022 19:30:08 -0700 Subject: CBE and LLVM: handle unused try instructions In both backends they did not observe the Liveness information for try instructions. Now they do. For the C backend this is necessary for correctness; for the LLVM backend, it improves code generation. --- src/codegen/c.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/codegen/c.zig') diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 372e89bac7..ac22ac3fa6 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -4092,9 +4092,14 @@ fn lowerTry( } } + try reap(f, inst, &.{operand}); + + if (f.liveness.isUnused(inst)) { + return CValue.none; + } + const target = f.object.dg.module.getTarget(); const is_array = lowersToArray(payload_ty, target); - try reap(f, inst, &.{operand}); const local = try f.allocLocal(inst, result_ty); if (is_array) { try writer.writeAll("memcpy("); -- cgit v1.2.3