Commit 5da5ded743

Andrew Kelley <andrew@ziglang.org>
2020-07-14 08:48:26
stage2: detect unreferenced non-volatile asm and NOT
1 parent 4f5e065
Changed files (1)
src-self-hosted
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", .{});
         }