diff options
| author | gingerBill <bill@gingerbill.org> | 2022-07-24 20:22:50 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-07-24 20:22:50 +0100 |
| commit | e6ab4f48567175cc192a658fb6d7b067e38912d8 (patch) | |
| tree | 0090f00932eff38514622702419322340ed4fd1b /src/llvm_backend_general.cpp | |
| parent | c8ab1b7ee1b1ba6444a057c6afa6a9d6eb7a7dae (diff) | |
Force memset instead of store zeroinitializer when the value is large
Diffstat (limited to 'src/llvm_backend_general.cpp')
| -rw-r--r-- | src/llvm_backend_general.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index a4c2ce370..52787d427 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -855,7 +855,11 @@ void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value) { if (LLVMIsNull(value.value)) { LLVMTypeRef src_t = LLVMGetElementType(LLVMTypeOf(ptr.value)); - LLVMBuildStore(p->builder, LLVMConstNull(src_t), ptr.value); + if (lb_sizeof(src_t) <= lb_max_zero_init_size()) { + LLVMBuildStore(p->builder, LLVMConstNull(src_t), ptr.value); + } else { + lb_mem_zero_ptr(p, ptr.value, a, LLVMGetAlignment(ptr.value)); + } return; } if (is_type_boolean(a)) { @@ -2737,13 +2741,15 @@ lbAddr lb_add_local(lbProcedure *p, Type *type, Entity *e, bool zero_init, i32 p if (!zero_init && !force_no_init) { // If there is any padding of any kind, just zero init regardless of zero_init parameter LLVMTypeKind kind = LLVMGetTypeKind(llvm_type); + if (kind == LLVMArrayTypeKind) { + kind = LLVMGetTypeKind(lb_type(p->module, core_array_type(type))); + } + if (kind == LLVMStructTypeKind) { i64 sz = type_size_of(type); if (type_size_of_struct_pretend_is_packed(type) != sz) { zero_init = true; } - } else if (kind == LLVMArrayTypeKind) { - zero_init = true; } } |