about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2020-10-02 00:23:25 +0200
committerJonas Schievink <jonasschievink@gmail.com>2020-10-02 00:23:25 +0200
commitb01694e0a2f36cee14e5844e1b4abae965dee627 (patch)
treed28eaf9d193ca7bc3dbd985326b13f66238678ae
parent8fe73e80d762bc575040239fc05fb1c612873554 (diff)
downloadrust-b01694e0a2f36cee14e5844e1b4abae965dee627.tar.gz
rust-b01694e0a2f36cee14e5844e1b4abae965dee627.zip
Returns values up to 2*usize by value
-rw-r--r--compiler/rustc_middle/src/ty/layout.rs5
-rw-r--r--compiler/rustc_target/src/abi/call/mod.rs12
2 files changed, 3 insertions, 14 deletions
diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs
index ee669ed2289..b61fde32c9c 100644
--- a/compiler/rustc_middle/src/ty/layout.rs
+++ b/compiler/rustc_middle/src/ty/layout.rs
@@ -2787,8 +2787,9 @@ where
                     _ => return,
                 }
 
-                let max_by_val_size =
-                    if is_ret { call::max_ret_by_val(cx) } else { Pointer.size(cx) };
+                // 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 {
diff --git a/compiler/rustc_target/src/abi/call/mod.rs b/compiler/rustc_target/src/abi/call/mod.rs
index 602c424a043..8f7e2bba5aa 100644
--- a/compiler/rustc_target/src/abi/call/mod.rs
+++ b/compiler/rustc_target/src/abi/call/mod.rs
@@ -610,15 +610,3 @@ impl<'a, Ty> FnAbi<'a, Ty> {
         Ok(())
     }
 }
-
-/// Returns the maximum size of return values to be passed by value in the Rust ABI.
-///
-/// Return values beyond this size will use an implicit out-pointer instead.
-pub fn max_ret_by_val<C: HasTargetSpec + HasDataLayout>(spec: &C) -> Size {
-    match spec.target_spec().arch.as_str() {
-        // System-V will pass return values up to 128 bits in RAX/RDX.
-        "x86_64" => Size::from_bits(128),
-
-        _ => spec.data_layout().pointer_size,
-    }
-}