Skip to content

Commit 0859e5e

Browse files
committed
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.
1 parent dcaeb6a commit 0859e5e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/librustc_trans/trans/intrinsic.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,11 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
361361
}
362362
(_, "init") => {
363363
let tp_ty = *substs.types.get(FnSpace, 0);
364-
let lltp_ty = type_of::arg_type_of(ccx, tp_ty);
365-
if return_type_is_void(ccx, tp_ty) {
366-
C_nil(ccx)
367-
} else {
368-
C_null(lltp_ty)
364+
if !return_type_is_void(ccx, tp_ty) {
365+
// Just zero out the stack slot
366+
zero_mem(bcx, llresult, tp_ty);
369367
}
368+
C_nil(ccx)
370369
}
371370
// Effectively no-ops
372371
(_, "uninit") | (_, "forget") => {

0 commit comments

Comments
 (0)