Skip to content

Commit 96b3163

Browse files
committed
auto merge of #7717 : dotdash/rust/transmute, r=pcwalton
Currently, immediate values are copied into an alloca only to have an addressable storage so that it can be used with memcpy. Obviously we can skip the memcpy in this case.
2 parents ad70813 + 7e97277 commit 96b3163

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/librustc/middle/trans/foreign.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -725,24 +725,21 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
725725
}
726726

727727
if !ty::type_is_nil(out_type) {
728-
// NB: Do not use a Load and Store here. This causes massive
729-
// code bloat when `transmute` is used on large structural
730-
// types.
731728
let lldestptr = fcx.llretptr.get();
732-
let lldestptr = PointerCast(bcx, lldestptr, Type::i8p());
733-
734729
let llsrcval = get_param(decl, first_real_arg);
735-
let llsrcptr = if ty::type_is_immediate(ccx.tcx, in_type) {
736-
let llsrcptr = alloca(bcx, llintype, "__llsrcptr");
737-
Store(bcx, llsrcval, llsrcptr);
738-
llsrcptr
730+
if ty::type_is_immediate(ccx.tcx, in_type) {
731+
let lldestptr = PointerCast(bcx, lldestptr, llintype.ptr_to());
732+
Store(bcx, llsrcval, lldestptr);
739733
} else {
740-
llsrcval
734+
// NB: Do not use a Load and Store here. This causes massive
735+
// code bloat when `transmute` is used on large structural
736+
// types.
737+
let lldestptr = PointerCast(bcx, lldestptr, Type::i8p());
738+
let llsrcptr = PointerCast(bcx, llsrcval, Type::i8p());
739+
740+
let llsize = llsize_of(ccx, llintype);
741+
call_memcpy(bcx, lldestptr, llsrcptr, llsize, 1);
741742
};
742-
let llsrcptr = PointerCast(bcx, llsrcptr, Type::i8p());
743-
744-
let llsize = llsize_of(ccx, llintype);
745-
call_memcpy(bcx, lldestptr, llsrcptr, llsize, 1);
746743
}
747744
}
748745
"needs_drop" => {

0 commit comments

Comments
 (0)