Skip to content

Commit b01694e

Browse files
Returns values up to 2*usize by value
1 parent 8fe73e8 commit b01694e

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

compiler/rustc_middle/src/ty/layout.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2787,8 +2787,9 @@ where
27872787
_ => return,
27882788
}
27892789

2790-
let max_by_val_size =
2791-
if is_ret { call::max_ret_by_val(cx) } else { Pointer.size(cx) };
2790+
// Return structures up to 2 pointers in size by value, matching `ScalarPair`. LLVM
2791+
// will usually return these in 2 registers, which is more efficient than by-ref.
2792+
let max_by_val_size = if is_ret { Pointer.size(cx) * 2 } else { Pointer.size(cx) };
27922793
let size = arg.layout.size;
27932794

27942795
if arg.layout.is_unsized() || size > max_by_val_size {

compiler/rustc_target/src/abi/call/mod.rs

-12
Original file line numberDiff line numberDiff line change
@@ -610,15 +610,3 @@ impl<'a, Ty> FnAbi<'a, Ty> {
610610
Ok(())
611611
}
612612
}
613-
614-
/// Returns the maximum size of return values to be passed by value in the Rust ABI.
615-
///
616-
/// Return values beyond this size will use an implicit out-pointer instead.
617-
pub fn max_ret_by_val<C: HasTargetSpec + HasDataLayout>(spec: &C) -> Size {
618-
match spec.target_spec().arch.as_str() {
619-
// System-V will pass return values up to 128 bits in RAX/RDX.
620-
"x86_64" => Size::from_bits(128),
621-
622-
_ => spec.data_layout().pointer_size,
623-
}
624-
}

0 commit comments

Comments
 (0)