Skip to content

Commit 62be878

Browse files
committed
rustc: Use memmove in unsafe::reinterpret_cast (issue #3025).
This was causing a bunch of structural copies, which when inlined was leading to enormous register pressure. Often this is seen in code which makes use of result::unwrap.
1 parent ff9151f commit 62be878

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/rustc/middle/trans/foreign.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,12 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item,
937937
ty_to_str(ccx.tcx, substs.tys[1]), out_sz));
938938
}
939939
if !ty::type_is_nil(substs.tys[1]) {
940-
let cast = PointerCast(bcx, get_param(decl, first_real_arg),
941-
T_ptr(llout_ty));
942-
Store(bcx, Load(bcx, cast), fcx.llretptr);
940+
// NB: Do not use a Load and Store here. This causes massive code
941+
// bloat when reinterpret_cast is used on large structural types.
942+
let llretptr = PointerCast(bcx, fcx.llretptr, T_ptr(T_i8()));
943+
let llcast = get_param(decl, first_real_arg);
944+
let llcast = PointerCast(bcx, llcast, T_ptr(T_i8()));
945+
call_memmove(bcx, llretptr, llcast, llsize_of(ccx, lltp_ty));
943946
}
944947
}
945948
~"addr_of" => {

0 commit comments

Comments
 (0)