Skip to content

Commit 422ab07

Browse files
Merge pull request swiftlang#8932 from aschwaighofer/irgen_enum_primitive_copy_as_memcpy
IRGen: Enums - Use memcpy for indirectly primitive copying fixed size types
2 parents aa0ce22 + ba0299b commit 422ab07

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

lib/IRGen/GenEnum.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,16 +1314,7 @@ namespace {
13141314
/// Do a primitive copy of the enum from one address to another.
13151315
void emitPrimitiveCopy(IRGenFunction &IGF, Address dest, Address src,
13161316
SILType T) const {
1317-
// If the layout is fixed, load and store the fixed-size payload and tag.
1318-
if (TIK >= Fixed) {
1319-
EnumPayload payload;
1320-
llvm::Value *extraTag;
1321-
std::tie(payload, extraTag)
1322-
= emitPrimitiveLoadPayloadAndExtraTag(IGF, src);
1323-
emitPrimitiveStorePayloadAndExtraTag(IGF, dest, payload, extraTag);
1324-
return;
1325-
}
1326-
1317+
// If the layout is fixed, the size will be a constant.
13271318
// Otherwise, do a memcpy of the dynamic size of the type.
13281319
IGF.Builder.CreateMemCpy(dest.getAddress(), src.getAddress(),
13291320
TI->getSize(IGF, T),

test/IRGen/enum.sil

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,6 +2647,34 @@ bb4:
26472647
return %9 : $()
26482648
}
26492649

2650+
struct LargeStruct {
2651+
var x: Builtin.Int64
2652+
var x2: Builtin.Int64
2653+
var x3: Builtin.Int64
2654+
var x4: Builtin.Int64
2655+
var x5: Builtin.Int64
2656+
var x6: Builtin.NativeObject
2657+
}
2658+
2659+
enum MyOptional {
2660+
case None
2661+
case Some(LargeStruct)
2662+
}
2663+
2664+
// Make sure we use a memcpy for the none branch of the enum copy.
2665+
2666+
// CHECK-LABEL: define{{.*}} @test_large_optional
2667+
// CHECK: llvm.memcpy
2668+
// CHECK: ret void
2669+
sil @test_large_optional : $@convention(thin) (@in MyOptional) -> () {
2670+
entry(%x : $*MyOptional):
2671+
%stk = alloc_stack $MyOptional
2672+
copy_addr %x to [initialization] %stk : $*MyOptional
2673+
dealloc_stack %stk: $*MyOptional
2674+
%tuple = tuple ()
2675+
return %tuple : $()
2676+
}
2677+
26502678
// -- Fill function for dynamic singleton. The value witness table flags just
26512679
// get copied over from the element.
26522680
// CHECK: define{{( protected)?}} private %swift.type* @create_generic_metadata_DynamicSingleton(%swift.type_pattern*, i8**) {{.*}} {

0 commit comments

Comments
 (0)