[PATCH] Revert "Auto merge of #79547 - erikdesjardins:byval, r=nagisa"
authorJosh Stone <jistone@redhat.com>
Fri, 19 Feb 2021 03:14:58 +0000 (19:14 -0800)
committerXimin Luo <infinity0@debian.org>
Sat, 18 Sep 2021 10:45:21 +0000 (11:45 +0100)
This reverts commit a094ff9590b83c8f94d898f92c2964a5803ded06, reversing
changes made to d37afad0cc87bf709ad10c85319296ac53030f03.

See https://github.com/rust-lang/rust/issues/80810 for more background

Gbp-Pq: Name 0001-Revert-Auto-merge-of-79547.patch

compiler/rustc_middle/src/ty/layout.rs
src/test/codegen/arg-return-value-in-reg.rs [deleted file]
src/test/codegen/return-value-in-reg.rs [new file with mode: 0644]
src/test/codegen/union-abi.rs

index b545b92c9252a5efd36db54c96fe39d9253528f1..545f6aee1a2169d8921a182da721af5cc997ef59 100644 (file)
@@ -2849,7 +2849,7 @@ where
             || abi == SpecAbi::RustIntrinsic
             || abi == SpecAbi::PlatformIntrinsic
         {
-            let fixup = |arg: &mut ArgAbi<'tcx, Ty<'tcx>>| {
+            let fixup = |arg: &mut ArgAbi<'tcx, Ty<'tcx>>, is_ret: bool| {
                 if arg.is_ignore() {
                     return;
                 }
@@ -2887,9 +2887,9 @@ where
                     _ => return,
                 }
 
-                // 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;
+                // 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 {
@@ -2901,9 +2901,9 @@ where
                     arg.cast_to(Reg { kind: RegKind::Integer, size });
                 }
             };
-            fixup(&mut self.ret);
+            fixup(&mut self.ret, true);
             for arg in &mut self.args {
-                fixup(arg);
+                fixup(arg, false);
             }
             return;
         }
diff --git a/src/test/codegen/arg-return-value-in-reg.rs b/src/test/codegen/arg-return-value-in-reg.rs
deleted file mode 100644 (file)
index a69291d..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-//! 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
-
-#![crate_type = "lib"]
-
-pub struct S {
-    a: u64,
-    b: u32,
-    c: u32,
-}
-
-// 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 }
-}
-
-#[repr(packed)]
-pub struct TooBig {
-    a: u64,
-    b: u32,
-    c: u32,
-    d: u8,
-}
-
-// CHECK: define void @m_big(%TooBig* [[ATTRS:.*sret.*]], %TooBig* [[ATTRS2:.*]] %s)
-#[no_mangle]
-pub fn m_big(s: TooBig) -> TooBig {
-    TooBig { a: s.a + s.a, b: s.b + s.b, c: s.c + s.c, d: s.d + s.d }
-}
diff --git a/src/test/codegen/return-value-in-reg.rs b/src/test/codegen/return-value-in-reg.rs
new file mode 100644 (file)
index 0000000..4bc0136
--- /dev/null
@@ -0,0 +1,32 @@
+//! This test checks that types of up to 128 bits are returned by-value instead of via out-pointer.
+
+// compile-flags: -C no-prepopulate-passes -O
+// only-x86_64
+
+#![crate_type = "lib"]
+
+pub struct S {
+    a: u64,
+    b: u32,
+    c: u32,
+}
+
+// CHECK: define i128 @modify(%S* noalias nocapture dereferenceable(16) %s)
+#[no_mangle]
+pub fn modify(s: S) -> S {
+    S { a: s.a + s.a, b: s.b + s.b, c: s.c + s.c }
+}
+
+#[repr(packed)]
+pub struct TooBig {
+    a: u64,
+    b: u32,
+    c: u32,
+    d: u8,
+}
+
+// CHECK: define void @m_big(%TooBig* [[ATTRS:.*sret.*]], %TooBig* [[ATTRS2:.*]] %s)
+#[no_mangle]
+pub fn m_big(s: TooBig) -> TooBig {
+    TooBig { a: s.a + s.a, b: s.b + s.b, c: s.c + s.c, d: s.d + s.d }
+}
index f282fd237054c48e881048e25b3db786c352b696..afea01e9a2d035a75ac2125b7f3d4d8a87e825bb 100644 (file)
@@ -63,16 +63,11 @@ 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 CUnionU128x2{a:(u128, u128)}
-// CHECK: define void @test_CUnionU128x2(%CUnionU128x2* {{.*}} %_1)
+pub union CUnionU128{a:u128}
+// CHECK: define void @test_CUnionU128(%CUnionU128* {{.*}} %_1)
 #[no_mangle]
-pub fn test_CUnionU128x2(_: CUnionU128x2) { loop {} }
+pub fn test_CUnionU128(_: CUnionU128) { loop {} }
 
 pub union UnionBool { b:bool }
 // CHECK: define zeroext i1 @test_UnionBool(i8 %b)