Skip to content

Commit 0183b41

Browse files
Pass arguments up to 2*usize by value
1 parent 88b8197 commit 0183b41

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

Diff for: compiler/rustc_middle/src/ty/layout.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2818,7 +2818,7 @@ where
28182818
|| abi == SpecAbi::RustIntrinsic
28192819
|| abi == SpecAbi::PlatformIntrinsic
28202820
{
2821-
let fixup = |arg: &mut ArgAbi<'tcx, Ty<'tcx>>, is_ret: bool| {
2821+
let fixup = |arg: &mut ArgAbi<'tcx, Ty<'tcx>>| {
28222822
if arg.is_ignore() {
28232823
return;
28242824
}
@@ -2856,9 +2856,9 @@ where
28562856
_ => return,
28572857
}
28582858

2859-
// Return structures up to 2 pointers in size by value, matching `ScalarPair`. LLVM
2860-
// will usually return these in 2 registers, which is more efficient than by-ref.
2861-
let max_by_val_size = if is_ret { Pointer.size(cx) * 2 } else { Pointer.size(cx) };
2859+
// Pass and return structures up to 2 pointers in size by value, matching `ScalarPair`.
2860+
// LLVM will usually pass these in 2 registers, which is more efficient than by-ref.
2861+
let max_by_val_size = Pointer.size(cx) * 2;
28622862
let size = arg.layout.size;
28632863

28642864
if arg.layout.is_unsized() || size > max_by_val_size {
@@ -2870,9 +2870,9 @@ where
28702870
arg.cast_to(Reg { kind: RegKind::Integer, size });
28712871
}
28722872
};
2873-
fixup(&mut self.ret, true);
2873+
fixup(&mut self.ret);
28742874
for arg in &mut self.args {
2875-
fixup(arg, false);
2875+
fixup(arg);
28762876
}
28772877
return;
28782878
}

Diff for: src/test/codegen/return-value-in-reg.rs renamed to src/test/codegen/arg-return-value-in-reg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! This test checks that types of up to 128 bits are returned by-value instead of via out-pointer.
1+
//! Check that types of up to 128 bits are passed and returned by-value instead of via pointer.
22
33
// compile-flags: -C no-prepopulate-passes -O
44
// only-x86_64
@@ -11,7 +11,7 @@ pub struct S {
1111
c: u32,
1212
}
1313

14-
// CHECK: define i128 @modify(%S* noalias nocapture dereferenceable(16) %s)
14+
// CHECK: define i128 @modify(i128 %0)
1515
#[no_mangle]
1616
pub fn modify(s: S) -> S {
1717
S { a: s.a + s.a, b: s.b + s.b, c: s.c + s.c }

Diff for: src/test/codegen/union-abi.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,16 @@ pub union UnionU128{a:u128}
6363
#[no_mangle]
6464
pub fn test_UnionU128(_: UnionU128) -> UnionU128 { loop {} }
6565

66+
pub union UnionU128x2{a:(u128, u128)}
67+
// CHECK: define void @test_UnionU128x2(i128 %_1.0, i128 %_1.1)
68+
#[no_mangle]
69+
pub fn test_UnionU128x2(_: UnionU128x2) { loop {} }
70+
6671
#[repr(C)]
67-
pub union CUnionU128{a:u128}
68-
// CHECK: define void @test_CUnionU128(%CUnionU128* {{.*}} %_1)
72+
pub union CUnionU128x2{a:(u128, u128)}
73+
// CHECK: define void @test_CUnionU128x2(%CUnionU128x2* {{.*}} %_1)
6974
#[no_mangle]
70-
pub fn test_CUnionU128(_: CUnionU128) { loop {} }
75+
pub fn test_CUnionU128x2(_: CUnionU128x2) { loop {} }
7176

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

0 commit comments

Comments
 (0)