Skip to content

Commit df042e0

Browse files
committed
Prefer an element-wise copy over memcpy for fat pointers
We currently copy fat pointers using memcpy intrinsics, which SROA will split up into load/store pairs. Unfortunately, nonnull metadata on loads from said fat pointers might get lost in the process. So instead of using memcpy we can go ahead and use load/store pairs right away including the appropriate nonnull metadata on the loads. That way the metadata doesn't get lost and LLVM has better chances of eliminating null checks. One example for this is the code in rust-lang#27130 that currently has an extra null check that disappears after this change.
1 parent e8f5955 commit df042e0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/librustc_trans/trans/base.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,9 @@ pub fn memcpy_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
979979
t: Ty<'tcx>) {
980980
let _icx = push_ctxt("memcpy_ty");
981981
let ccx = bcx.ccx();
982-
if t.is_structural() {
982+
if common::type_is_fat_ptr(bcx.tcx(), t) {
983+
expr::copy_fat_ptr(bcx, src, dst, t);
984+
} else if t.is_structural() {
983985
let llty = type_of::type_of(ccx, t);
984986
let llsz = llsize_of(ccx, llty);
985987
let llalign = type_of::align_of(ccx, t);

0 commit comments

Comments
 (0)