commit 83beed09e1ce5a15e2b9801a50cf601352d8383e (tree)
parent c3ef4ac15f4aa0a4bbf546fb46745d445b97d717
Author: Andrew Kelley <andrew@ziglang.org>
Date: Tue, 31 May 2022 00:39:14 -0700
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.
Diffstat:
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git 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);