Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returns values up to 2*usize by value #77434

Merged
merged 1 commit into from
Oct 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it makes sense to limit this to returns, but also whether 3 might work better than 2 as the multiplier.
But I guess there's a risk it might get downgraded from registers... I really wish LLVM modeled ABIs more precisely so we can control that.

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),
Comment on lines -618 to -620
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping removing this string comparison would help perf but I guess not?


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