Skip to content

Commit d0825ad

Browse files
Merge pull request #72494 from nate-chandler/rdar125182396
[SILGen] Load trivial in consuming switch.
2 parents 336750e + 12c91d8 commit d0825ad

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

lib/SILGen/SILGenPattern.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2705,7 +2705,10 @@ void PatternMatchEmission::emitDestructiveCaseBlocks() {
27052705
mv.forward(SGF),
27062706
enumCase);
27072707
if (payload->getType().isLoadable(SGF.F)) {
2708-
payload = SGF.B.createLoad(loc, payload, LoadOwnershipQualifier::Take);
2708+
payload = SGF.B.createLoad(loc, payload,
2709+
payload->getType().isTrivial(SGF.F)
2710+
? LoadOwnershipQualifier::Trivial
2711+
: LoadOwnershipQualifier::Take);
27092712
}
27102713
visit(subPattern,
27112714
SGF.emitManagedRValueWithCleanup(payload));
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %target-swift-frontend \
2+
// RUN: -emit-silgen \
3+
// RUN: %s \
4+
// RUN: -enable-experimental-feature BorrowingSwitch \
5+
// RUN: -enable-experimental-feature MoveOnlyPartialConsumption \
6+
// RUN: -enable-experimental-feature NoncopyableGenerics \
7+
// RUN: | %FileCheck %s
8+
9+
enum MaybeMaybeVoid<Wrapped: ~Copyable>: ~Copyable {
10+
case none(())
11+
case some(Wrapped)
12+
}
13+
14+
// CHECK-LABEL: sil {{.*}}[ossa] @maybeMaybeVoid2Optional {{.*}} {
15+
// CHECK: [[STACK:%[^,]+]] = alloc_stack
16+
// CHECK: [[ADDR:%[^,]+]] = mark_unresolved_non_copyable_value [consumable_and_assignable] [[STACK]]
17+
// CHECK: [[ACCESS:%[^,]+]] = begin_access [read] [static] [no_nested_conflict] [[ADDR]]
18+
// CHECK: switch_enum_addr [[ACCESS]]
19+
// CHECK-SAME: case #MaybeMaybeVoid.none!enumelt: [[NONE_BLOCK:bb[0-9]+]]
20+
// CHECK: [[NONE_BLOCK]]:
21+
// CHECK: [[REGISTER_14:%[^,]+]] = tuple ()
22+
// CHECK: end_access [[ACCESS]]
23+
// CHECK: [[ACCESS_AGAIN:%[^,]+]] = begin_access [deinit] [static] [no_nested_conflict] [[ADDR]]
24+
// CHECK: [[NONE_ADDR:%[^,]+]] = unchecked_take_enum_data_addr [[ACCESS_AGAIN]]
25+
// CHECK-SAME: #MaybeMaybeVoid.none!enumelt
26+
// Verify that the load is trivial.
27+
// CHECK: load [trivial] [[NONE_ADDR]]
28+
// CHECK-LABEL: } // end sil function 'maybeMaybeVoid2Optional'
29+
@_silgen_name("maybeMaybeVoid2Optional")
30+
func maybeMaybeVoid2Optional<Wrapped: ~Copyable>(_ o2: consuming MaybeMaybeVoid<Wrapped>) -> Optional<Wrapped> {
31+
switch consume o2 {
32+
case .none(let void):
33+
return .none
34+
case .some(let wrapped):
35+
return .some(wrapped)
36+
}
37+
}

0 commit comments

Comments
 (0)