Skip to content

Commit

Permalink
Prefer an element-wise copy over memcpy for fat pointers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dotdash committed Jul 22, 2015
1 parent e8f5955 commit df042e0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/librustc_trans/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,9 @@ pub fn memcpy_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
t: Ty<'tcx>) {
let _icx = push_ctxt("memcpy_ty");
let ccx = bcx.ccx();
if t.is_structural() {
if common::type_is_fat_ptr(bcx.tcx(), t) {
expr::copy_fat_ptr(bcx, src, dst, t);
} else if t.is_structural() {
let llty = type_of::type_of(ccx, t);
let llsz = llsize_of(ccx, llty);
let llalign = type_of::align_of(ccx, t);
Expand Down

0 comments on commit df042e0

Please sign in to comment.