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

Pass arguments up to 2*usize by value #79547

Merged
merged 2 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2818,7 +2818,7 @@ where
|| abi == SpecAbi::RustIntrinsic
|| abi == SpecAbi::PlatformIntrinsic
{
let fixup = |arg: &mut ArgAbi<'tcx, Ty<'tcx>>, is_ret: bool| {
let fixup = |arg: &mut ArgAbi<'tcx, Ty<'tcx>>| {
if arg.is_ignore() {
return;
}
Expand Down Expand Up @@ -2856,9 +2856,9 @@ where
_ => return,
}

// 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) };
// Pass and return structures up to 2 pointers in size by value, matching `ScalarPair`.
// LLVM will usually pass these in 2 registers, which is more efficient than by-ref.
let max_by_val_size = Pointer.size(cx) * 2;
let size = arg.layout.size;

if arg.layout.is_unsized() || size > max_by_val_size {
Expand All @@ -2870,9 +2870,9 @@ where
arg.cast_to(Reg { kind: RegKind::Integer, size });
}
};
fixup(&mut self.ret, true);
fixup(&mut self.ret);
for arg in &mut self.args {
fixup(arg, false);
fixup(arg);
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This test checks that types of up to 128 bits are returned by-value instead of via out-pointer.
//! Check that types of up to 128 bits are passed and returned by-value instead of via pointer.

// compile-flags: -C no-prepopulate-passes -O
// only-x86_64
Expand All @@ -11,7 +11,7 @@ pub struct S {
c: u32,
}

// CHECK: define i128 @modify(%S* noalias nocapture dereferenceable(16) %s)
// CHECK: define i128 @modify(i128 %0)
#[no_mangle]
pub fn modify(s: S) -> S {
S { a: s.a + s.a, b: s.b + s.b, c: s.c + s.c }
Expand Down
11 changes: 8 additions & 3 deletions src/test/codegen/union-abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@ pub union UnionU128{a:u128}
#[no_mangle]
pub fn test_UnionU128(_: UnionU128) -> UnionU128 { loop {} }

pub union UnionU128x2{a:(u128, u128)}
// CHECK: define void @test_UnionU128x2(i128 %_1.0, i128 %_1.1)
#[no_mangle]
pub fn test_UnionU128x2(_: UnionU128x2) { loop {} }

#[repr(C)]
pub union CUnionU128{a:u128}
// CHECK: define void @test_CUnionU128(%CUnionU128* {{.*}} %_1)
pub union CUnionU128x2{a:(u128, u128)}
// CHECK: define void @test_CUnionU128x2(%CUnionU128x2* {{.*}} %_1)
#[no_mangle]
pub fn test_CUnionU128(_: CUnionU128) { loop {} }
pub fn test_CUnionU128x2(_: CUnionU128x2) { loop {} }
Comment on lines +66 to +75
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was testing that single-field #[repr(C)] unions don't forward that field's ABI, but after this change CUnionU128 would get passed by value, making it impossible to distinguish between i128 [forwarded from inner field] vs i128 [passing entire union by value]. So I had to make it bigger.


pub union UnionBool { b:bool }
// CHECK: define zeroext i1 @test_UnionBool(i8 %b)
Expand Down