From 4a485f8cec524c8f3f57e4fd3248d5093ed3dc5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Mon, 8 Jul 2013 07:42:56 +0200 Subject: [PATCH] Avoid unused allocas for immediate return values There's no need to allocate a return slot for anykind of immediate return value, not just not for nils. Also, when the return value is ignored, we only have to copy it to a temporary alloca if it's actually required to call drop_ty on it. --- src/librustc/middle/trans/callee.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 05fe0bed3b6..2a5e8f2ddc0 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -672,15 +672,8 @@ pub fn trans_call_inner(in_cx: block, expr::Ignore => { // drop the value if it is not being saved. unsafe { - if llvm::LLVMIsUndef(llretslot) != lib::llvm::True { - if ty::type_is_nil(ret_ty) { - // When implementing the for-loop sugar syntax, the - // type of the for-loop is nil, but the function - // it's invoking returns a bool. This is a special - // case to ignore instead of invoking the Store - // below into a scratch pointer of a mismatched - // type. - } else if ty::type_is_immediate(bcx.tcx(), ret_ty) { + if ty::type_needs_drop(bcx.tcx(), ret_ty) { + if ty::type_is_immediate(bcx.tcx(), ret_ty) { let llscratchptr = alloc_ty(bcx, ret_ty); Store(bcx, llresult, llscratchptr); bcx = glue::drop_ty(bcx, llscratchptr, ret_ty); @@ -734,7 +727,7 @@ pub fn trans_ret_slot(bcx: block, fn_ty: ty::t, dest: expr::Dest) match dest { expr::SaveIn(dst) => dst, expr::Ignore => { - if ty::type_is_nil(retty) { + if ty::type_is_immediate(bcx.tcx(), retty) { unsafe { llvm::LLVMGetUndef(Type::nil().ptr_to().to_ref()) }