892f9b
From eaf7ea1fc339e1ff348ed941ed2e8c4d66f3e458 Mon Sep 17 00:00:00 2001
892f9b
From: Josh Stone <jistone@redhat.com>
892f9b
Date: Thu, 18 Feb 2021 19:14:58 -0800
892f9b
Subject: [PATCH] Revert "Auto merge of #79547 - erikdesjardins:byval,
892f9b
 r=nagisa"
892f9b
892f9b
This reverts commit a094ff9590b83c8f94d898f92c2964a5803ded06, reversing
892f9b
changes made to d37afad0cc87bf709ad10c85319296ac53030f03.
892f9b
---
892f9b
 compiler/rustc_middle/src/ty/layout.rs               | 12 ++++++------
892f9b
 ...return-value-in-reg.rs => return-value-in-reg.rs} |  4 ++--
892f9b
 src/test/codegen/union-abi.rs                        | 11 +++--------
892f9b
 3 files changed, 11 insertions(+), 16 deletions(-)
892f9b
 rename src/test/codegen/{arg-return-value-in-reg.rs => return-value-in-reg.rs} (74%)
892f9b
892f9b
diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs
892f9b
index b545b92c9252..545f6aee1a21 100644
892f9b
--- a/compiler/rustc_middle/src/ty/layout.rs
892f9b
+++ b/compiler/rustc_middle/src/ty/layout.rs
892f9b
@@ -2849,7 +2849,7 @@ fn adjust_for_abi(&mut self, cx: &C, abi: SpecAbi) {
892f9b
             || abi == SpecAbi::RustIntrinsic
892f9b
             || abi == SpecAbi::PlatformIntrinsic
892f9b
         {
892f9b
-            let fixup = |arg: &mut ArgAbi<'tcx, Ty<'tcx>>| {
892f9b
+            let fixup = |arg: &mut ArgAbi<'tcx, Ty<'tcx>>, is_ret: bool| {
892f9b
                 if arg.is_ignore() {
892f9b
                     return;
892f9b
                 }
892f9b
@@ -2887,9 +2887,9 @@ fn adjust_for_abi(&mut self, cx: &C, abi: SpecAbi) {
892f9b
                     _ => return,
892f9b
                 }
892f9b
 
892f9b
-                // Pass and return structures up to 2 pointers in size by value, matching `ScalarPair`.
892f9b
-                // LLVM will usually pass these in 2 registers, which is more efficient than by-ref.
892f9b
-                let max_by_val_size = Pointer.size(cx) * 2;
892f9b
+                // Return structures up to 2 pointers in size by value, matching `ScalarPair`. LLVM
892f9b
+                // will usually return these in 2 registers, which is more efficient than by-ref.
892f9b
+                let max_by_val_size = if is_ret { Pointer.size(cx) * 2 } else { Pointer.size(cx) };
892f9b
                 let size = arg.layout.size;
892f9b
 
892f9b
                 if arg.layout.is_unsized() || size > max_by_val_size {
892f9b
@@ -2901,9 +2901,9 @@ fn adjust_for_abi(&mut self, cx: &C, abi: SpecAbi) {
892f9b
                     arg.cast_to(Reg { kind: RegKind::Integer, size });
892f9b
                 }
892f9b
             };
892f9b
-            fixup(&mut self.ret);
892f9b
+            fixup(&mut self.ret, true);
892f9b
             for arg in &mut self.args {
892f9b
-                fixup(arg);
892f9b
+                fixup(arg, false);
892f9b
             }
892f9b
             return;
892f9b
         }
892f9b
diff --git a/src/test/codegen/arg-return-value-in-reg.rs b/src/test/codegen/return-value-in-reg.rs
892f9b
similarity index 74%
892f9b
rename from src/test/codegen/arg-return-value-in-reg.rs
892f9b
rename to src/test/codegen/return-value-in-reg.rs
892f9b
index a69291d47821..4bc0136c5e32 100644
892f9b
--- a/src/test/codegen/arg-return-value-in-reg.rs
892f9b
+++ b/src/test/codegen/return-value-in-reg.rs
892f9b
@@ -1,4 +1,4 @@
892f9b
-//! Check that types of up to 128 bits are passed and returned by-value instead of via pointer.
892f9b
+//! This test checks that types of up to 128 bits are returned by-value instead of via out-pointer.
892f9b
 
892f9b
 // compile-flags: -C no-prepopulate-passes -O
892f9b
 // only-x86_64
892f9b
@@ -11,7 +11,7 @@ pub struct S {
892f9b
     c: u32,
892f9b
 }
892f9b
 
892f9b
-// CHECK: define i128 @modify(i128{{( %0)?}})
892f9b
+// CHECK: define i128 @modify(%S* noalias nocapture dereferenceable(16) %s)
892f9b
 #[no_mangle]
892f9b
 pub fn modify(s: S) -> S {
892f9b
     S { a: s.a + s.a, b: s.b + s.b, c: s.c + s.c }
892f9b
diff --git a/src/test/codegen/union-abi.rs b/src/test/codegen/union-abi.rs
892f9b
index f282fd237054..afea01e9a2d0 100644
892f9b
--- a/src/test/codegen/union-abi.rs
892f9b
+++ b/src/test/codegen/union-abi.rs
892f9b
@@ -63,16 +63,11 @@ pub union UnionU128{a:u128}
892f9b
 #[no_mangle]
892f9b
 pub fn test_UnionU128(_: UnionU128) -> UnionU128 { loop {} }
892f9b
 
892f9b
-pub union UnionU128x2{a:(u128, u128)}
892f9b
-// CHECK: define void @test_UnionU128x2(i128 %_1.0, i128 %_1.1)
892f9b
-#[no_mangle]
892f9b
-pub fn test_UnionU128x2(_: UnionU128x2) { loop {} }
892f9b
-
892f9b
 #[repr(C)]
892f9b
-pub union CUnionU128x2{a:(u128, u128)}
892f9b
-// CHECK: define void @test_CUnionU128x2(%CUnionU128x2* {{.*}} %_1)
892f9b
+pub union CUnionU128{a:u128}
892f9b
+// CHECK: define void @test_CUnionU128(%CUnionU128* {{.*}} %_1)
892f9b
 #[no_mangle]
892f9b
-pub fn test_CUnionU128x2(_: CUnionU128x2) { loop {} }
892f9b
+pub fn test_CUnionU128(_: CUnionU128) { loop {} }
892f9b
 
892f9b
 pub union UnionBool { b:bool }
892f9b
 // CHECK: define zeroext i1 @test_UnionBool(i8 %b)
892f9b
-- 
892f9b
2.29.2
892f9b