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