Skip to content

Commit d8f12cb

Browse files
Merge pull request #20916 from aschwaighofer/loadable_by_address_indirect_yields
LoadableByAddress: Only replace yielded values with a load if required by users
2 parents cc49e68 + ab32870 commit d8f12cb

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,8 +2453,10 @@ void LoadableByAddress::recreateSingleApply(SILInstruction *applyInst) {
24532453
SILValue oldValue = oldYieldedValues[i];
24542454
SILValue newValue = newYieldedValues[i];
24552455

2456-
// For now, just replace the value with an immediate load.
2457-
if (oldValue->getType() != newValue->getType()) {
2456+
// For now, just replace the value with an immediate load if the old value
2457+
// was direct.
2458+
if (oldValue->getType() != newValue->getType() &&
2459+
!oldValue->getType().isAddress()) {
24582460
LoadOwnershipQualifier ownership;
24592461
if (!F->hasQualifiedOwnership()) {
24602462
ownership = LoadOwnershipQualifier::Unqualified;

test/IRGen/big_types_coroutine.sil

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -loadable-address -enable-sil-verify-all %s | %FileCheck %s
1+
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -loadable-address -enable-sil-verify-all %s | %FileCheck %s
22

33
// REQUIRES: CPU=x86_64
44
// REQUIRES: OS=macosx
@@ -57,8 +57,8 @@ unwind:
5757
// CHECK-NEXT: [[CORO:%.*]] = function_ref @test_yield_big : $@yield_once @convention(thin) () -> @yields @in_constant BigStruct
5858
// CHECK-NEXT: ([[ADDR:%.*]], [[TOKEN:%.*]]) = begin_apply [[CORO]]()
5959
// TODO: this isn't very efficient
60-
// CHECK-NEXT: [[T0:%.*]] = load [trivial] [[ADDR]] : $*BigStruct
61-
// CHECK-NEXT: store [[T0]] to [trivial] [[TEMP]] : $*BigStruct
60+
// CHECK-NEXT: [[T0:%.*]] = load [[ADDR]] : $*BigStruct
61+
// CHECK-NEXT: store [[T0]] to [[TEMP]] : $*BigStruct
6262
// CHECK-NEXT: // function_ref
6363
// CHECK-NEXT: [[USE:%.*]] = function_ref @use_big_struct : $@convention(thin) (@in_constant BigStruct) -> ()
6464
// CHECK-NEXT: apply [[USE]]([[TEMP]])
@@ -76,3 +76,24 @@ entry:
7676
%ret = tuple ()
7777
return %ret : $()
7878
}
79+
80+
sil @yield_fun_ptr2 : $@yield_once @convention(thin) () -> @yields @inout Optional<@callee_guaranteed (@guaranteed BigStruct) -> ()>
81+
82+
// CHECK-LABEL: sil @yield_funptr : $
83+
// CHECK: (%1, %2) = begin_apply %0() : $@yield_once @convention(thin) () -> @yields @inout Optional<@callee_guaranteed (@in_guaranteed BigStruct) -> ()>
84+
// CHECK: yield %1
85+
sil @yield_funptr : $@yield_once @convention(thin) () -> @yields @inout Optional<@callee_guaranteed (@guaranteed BigStruct) -> ()> {
86+
bb0:
87+
%2 = function_ref @yield_fun_ptr2 : $@yield_once @convention(thin) () -> @yields @inout Optional<@callee_guaranteed (@guaranteed BigStruct) -> ()>
88+
(%3, %4) = begin_apply %2() : $@yield_once @convention(thin) () -> @yields @inout Optional<@callee_guaranteed (@guaranteed BigStruct) -> ()>
89+
yield %3 : $*Optional<@callee_guaranteed (@guaranteed BigStruct) -> ()>, resume bb1, unwind bb2
90+
91+
bb1:
92+
end_apply %4
93+
%7 = tuple ()
94+
return %7 : $()
95+
96+
bb2:
97+
abort_apply %4
98+
unwind
99+
}

0 commit comments

Comments
 (0)