From 5da5ded74326fce0ca52c6cb00f22824f7beb7eb Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 13 Jul 2020 23:48:26 -0700 Subject: [PATCH] stage2: detect unreferenced non-volatile asm and NOT --- src-self-hosted/codegen.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src-self-hosted/codegen.zig b/src-self-hosted/codegen.zig index 731c039d9c..5753559ce1 100644 --- a/src-self-hosted/codegen.zig +++ b/src-self-hosted/codegen.zig @@ -412,6 +412,9 @@ const Function = struct { } fn genNot(self: *Function, inst: *ir.Inst.Not, comptime arch: std.Target.Cpu.Arch) !MCValue { + // No side effects, so if it's unreferenced, do nothing. + if (inst.base.isUnused()) + return MCValue.dead; switch (arch) { else => return self.fail(inst.base.src, "TODO implement NOT for {}", .{self.target.cpu.arch}), } @@ -819,6 +822,8 @@ const Function = struct { } fn genAsm(self: *Function, inst: *ir.Inst.Assembly, comptime arch: Target.Cpu.Arch) !MCValue { + if (!inst.args.is_volatile and inst.base.isUnused()) + return MCValue.dead; if (arch != .x86_64 and arch != .i386) { return self.fail(inst.base.src, "TODO implement inline asm support for more architectures", .{}); }