From 62dc98295c89c2553910c228dd55a47ba8b403b5 Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Mon, 6 May 2024 09:37:48 -0700 Subject: [PATCH] IRGen: memcpy instead of the outlined copy with take The outlined copy with take would instantiate metadata to call the value witness table's copy function. rdar://126751753 --- lib/IRGen/GenEnum.cpp | 5 ++++- test/IRGen/copy_addr_lowering.sil | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/IRGen/copy_addr_lowering.sil diff --git a/lib/IRGen/GenEnum.cpp b/lib/IRGen/GenEnum.cpp index f8e1c1de0a425..87e1eec265635 100644 --- a/lib/IRGen/GenEnum.cpp +++ b/lib/IRGen/GenEnum.cpp @@ -3283,7 +3283,10 @@ namespace { bool zeroizeIfSensitive) const override { if (!ElementsAreABIAccessible) { emitInitializeWithTakeCall(IGF, T, dest, src); - } else if (isOutlined || T.hasParameterizedExistential()) { + } else if (isOutlined || T.hasParameterizedExistential() || + (getPayloadTypeInfo().isFixedSize() && // can use memcpy + getPayloadTypeInfo(). + isBitwiseTakable(ResilienceExpansion::Maximal))) { emitIndirectInitialize(IGF, dest, src, T, IsTake, isOutlined); } else { callOutlinedCopy(IGF, dest, src, T, IsInitialization, IsTake); diff --git a/test/IRGen/copy_addr_lowering.sil b/test/IRGen/copy_addr_lowering.sil new file mode 100644 index 0000000000000..63d3a4771df66 --- /dev/null +++ b/test/IRGen/copy_addr_lowering.sil @@ -0,0 +1,24 @@ +// RUN: %target-swift-frontend -module-name A -Xllvm -sil-disable-pass=LowerAggregateInstr -emit-ir %s | %FileCheck %s +sil_stage lowered + +import Builtin +import Swift +import SwiftShims + +struct S { + var s: ArraySlice + var i: ArraySlice.Index +} + + +// CHECK: define{{.*}} swiftcc void @copy_test( +// CHECK-NOT: call ptr @"$s1A1SVSgWOb"( +// CHECK: memcpy +// CHECK: ret void + +sil @copy_test : $@convention(thin) (@in Optional) -> @out Optional { +bb0(%0 : $*Optional, %1 : $*Optional): + copy_addr [take] %1 to [init] %0 : $*Optional + %5 = tuple () + return %5 : $() +}