From 0ad97c042a1ae41652a0157d0ac148e6e90db6c2 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Mon, 11 Aug 2014 15:58:46 -0700 Subject: [PATCH] librustc: Don't use Load/Store for structural values. --- src/librustc/middle/trans/base.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 9c304f839db..22f8107a706 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1122,7 +1122,7 @@ pub fn memcpy_ty(bcx: &Block, dst: ValueRef, src: ValueRef, t: ty::t) { let llalign = llalign_of_min(ccx, llty); call_memcpy(bcx, dst, src, llsz, llalign as u32); } else { - Store(bcx, Load(bcx, src), dst); + store_ty(bcx, Load(bcx, src), dst, t); } } @@ -1546,7 +1546,7 @@ pub fn build_return_block(fcx: &FunctionContext, ret_cx: &Block, retty: ty::t) { let retslot = Load(ret_cx, fcx.llretslotptr.get().unwrap()); let retptr = Value(retslot); - let retval = match retptr.get_dominating_store(ret_cx) { + match retptr.get_dominating_store(ret_cx) { // If there's only a single store to the ret slot, we can directly return // the value that was stored and omit the store and the alloca Some(s) => { @@ -1557,21 +1557,28 @@ pub fn build_return_block(fcx: &FunctionContext, ret_cx: &Block, retty: ty::t) { retptr.erase_from_parent(); } - if ty::type_is_bool(retty) { + let retval = if ty::type_is_bool(retty) { Trunc(ret_cx, retval, Type::i1(fcx.ccx)) } else { retval + }; + + if fcx.caller_expects_out_pointer { + store_ty(ret_cx, retval, get_param(fcx.llfn, 0), retty); + return RetVoid(ret_cx); + } else { + return Ret(ret_cx, retval); + } + } + // Otherwise, copy the return value to the ret slot + None => { + if fcx.caller_expects_out_pointer { + memcpy_ty(ret_cx, get_param(fcx.llfn, 0), retslot, retty); + return RetVoid(ret_cx); + } else { + return Ret(ret_cx, load_ty(ret_cx, retslot, retty)); } } - // Otherwise, load the return value from the ret slot - None => load_ty(ret_cx, retslot, retty) - }; - - if fcx.caller_expects_out_pointer { - store_ty(ret_cx, retval, get_param(fcx.llfn, 0), retty); - RetVoid(ret_cx); - } else { - Ret(ret_cx, retval); } }