From 0859e5ebb319ceddcce01ddb63470d8f59860aba Mon Sep 17 00:00:00 2001 From: James Miller Date: Sat, 17 Jan 2015 17:04:15 +1300 Subject: [PATCH] Use `zero_mem` instead of a zerointializer for `init` intrinsic LLVM gets overwhelmed when presented with a zeroinitializer for a large type. In unoptimised builds, it generates a long sequence of stores to memory. In optmised builds, it manages to generate a standard memset of zero values, but takes a long time doing so. Call out to the `llvm.memset` function to zero out the memory instead. --- src/librustc_trans/trans/intrinsic.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/librustc_trans/trans/intrinsic.rs b/src/librustc_trans/trans/intrinsic.rs index 91c7409182d..eaf9b4a6bf7 100644 --- a/src/librustc_trans/trans/intrinsic.rs +++ b/src/librustc_trans/trans/intrinsic.rs @@ -361,12 +361,11 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, } (_, "init") => { let tp_ty = *substs.types.get(FnSpace, 0); - let lltp_ty = type_of::arg_type_of(ccx, tp_ty); - if return_type_is_void(ccx, tp_ty) { - C_nil(ccx) - } else { - C_null(lltp_ty) + if !return_type_is_void(ccx, tp_ty) { + // Just zero out the stack slot + zero_mem(bcx, llresult, tp_ty); } + C_nil(ccx) } // Effectively no-ops (_, "uninit") | (_, "forget") => {