Skip to content

Commit

Permalink
Auto merge of rust-lang#77434 - jonas-schievink:ret-in-reg-2-electric…
Browse files Browse the repository at this point in the history
…-boogalo, r=nagisa

Returns values up to 2*usize by value

Addresses rust-lang#76986 (comment) and rust-lang#76986 (comment) by doing the optimization on all targets.

This matches what we do for functions returning `&[T]` and other fat pointers, so it should be Harmless™
  • Loading branch information
bors committed Oct 3, 2020
2 parents 25c8c53 + b01694e commit bad9ad0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2787,8 +2787,9 @@ where
_ => return,
}

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

if arg.layout.is_unsized() || size > max_by_val_size {
Expand Down
12 changes: 0 additions & 12 deletions compiler/rustc_target/src/abi/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,15 +610,3 @@ impl<'a, Ty> FnAbi<'a, Ty> {
Ok(())
}
}

/// Returns the maximum size of return values to be passed by value in the Rust ABI.
///
/// Return values beyond this size will use an implicit out-pointer instead.
pub fn max_ret_by_val<C: HasTargetSpec + HasDataLayout>(spec: &C) -> Size {
match spec.target_spec().arch.as_str() {
// System-V will pass return values up to 128 bits in RAX/RDX.
"x86_64" => Size::from_bits(128),

_ => spec.data_layout().pointer_size,
}
}

0 comments on commit bad9ad0

Please sign in to comment.