From 83beed09e1ce5a15e2b9801a50cf601352d8383e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 31 May 2022 00:39:14 -0700 Subject: [PATCH] LLVM: omit memset of 0xaa bytes in unsafe optimization modes This is one out of three changes I intend to make to address #11498. However I will put these changes in separate branches and merge them separately so that we can have three independent points on the perf charts. --- src/codegen/llvm.zig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index f958fdfbb3..8cfa833cdd 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -6944,6 +6944,23 @@ pub const FuncGen = struct { // possibly do the safety 0xaa bytes for undefined. const val_is_undef = if (self.air.value(bin_op.rhs)) |val| val.isUndefDeep() else false; if (val_is_undef) { + { + // TODO let's handle this in AIR rather than by having each backend + // check the optimization mode of the compilation because the plan is + // to support setting the optimization mode at finer grained scopes + // which happens in Sema. Codegen should not be aware of this logic. + // I think this comment is basically the same as the other TODO comment just + // above but I'm leaving them both here to make it look super messy and + // thereby bait contributors (or let's be honest, probably myself) into + // fixing this instead of letting it rot. + const safety = switch (self.dg.module.comp.bin_file.options.optimize_mode) { + .ReleaseSmall, .ReleaseFast => false, + .Debug, .ReleaseSafe => true, + }; + if (!safety) { + return null; + } + } const target = self.dg.module.getTarget(); const operand_size = operand_ty.abiSize(target); const u8_llvm_ty = self.context.intType(8);