Skip to content

Commit 4a485f8

Browse files
dotdashBjörn Steinbrink
authored and
Björn Steinbrink
committed
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.
1 parent 48ad726 commit 4a485f8

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/librustc/middle/trans/callee.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -672,15 +672,8 @@ pub fn trans_call_inner(in_cx: block,
672672
expr::Ignore => {
673673
// drop the value if it is not being saved.
674674
unsafe {
675-
if llvm::LLVMIsUndef(llretslot) != lib::llvm::True {
676-
if ty::type_is_nil(ret_ty) {
677-
// When implementing the for-loop sugar syntax, the
678-
// type of the for-loop is nil, but the function
679-
// it's invoking returns a bool. This is a special
680-
// case to ignore instead of invoking the Store
681-
// below into a scratch pointer of a mismatched
682-
// type.
683-
} else if ty::type_is_immediate(bcx.tcx(), ret_ty) {
675+
if ty::type_needs_drop(bcx.tcx(), ret_ty) {
676+
if ty::type_is_immediate(bcx.tcx(), ret_ty) {
684677
let llscratchptr = alloc_ty(bcx, ret_ty);
685678
Store(bcx, llresult, llscratchptr);
686679
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)
734727
match dest {
735728
expr::SaveIn(dst) => dst,
736729
expr::Ignore => {
737-
if ty::type_is_nil(retty) {
730+
if ty::type_is_immediate(bcx.tcx(), retty) {
738731
unsafe {
739732
llvm::LLVMGetUndef(Type::nil().ptr_to().to_ref())
740733
}

0 commit comments

Comments
 (0)