Skip to content

Commit e87df13

Browse files
committed
[PartialApplyCombiner] Handled moved PAIs.
Look through `move_value` instructions when combining `partial_apply` instructions. rdar://108386395
1 parent f3e9ab6 commit e87df13

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,10 @@ static bool useHasTransitiveOwnership(const SILInstruction *inst) {
820820
if (isa<ConvertEscapeToNoEscapeInst>(inst))
821821
return true;
822822

823-
// Look through copy_value, begin_borrow. They are inert for our purposes, but
824-
// we need to look through it.
825-
return isa<CopyValueInst>(inst) || isa<BeginBorrowInst>(inst);
823+
// Look through copy_value, begin_borrow, move_value. They are inert for our
824+
// purposes, but we need to look through it.
825+
return isa<CopyValueInst>(inst) || isa<BeginBorrowInst>(inst) ||
826+
isa<MoveValueInst>(inst);
826827
}
827828

828829
static bool shouldDestroyPartialApplyCapturedArg(SILValue arg,

lib/SILOptimizer/Utils/PartialApplyCombiner.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,11 @@ bool PartialApplyCombiner::combine() {
239239
auto *use = worklist.pop_back_val();
240240
auto *user = use->getUser();
241241

242-
// Recurse through copy_value
243-
if (isa<CopyValueInst>(user) || isa<BeginBorrowInst>(user)) {
244-
for (auto *copyUse : cast<SingleValueInstruction>(user)->getUses())
245-
worklist.push_back(copyUse);
242+
// Recurse through ownership instructions.
243+
if (isa<CopyValueInst>(user) || isa<BeginBorrowInst>(user) ||
244+
isa<MoveValueInst>(user)) {
245+
for (auto *ownershipUse : cast<SingleValueInstruction>(user)->getUses())
246+
worklist.push_back(ownershipUse);
246247
continue;
247248
}
248249

test/SILOptimizer/mandatory_generic_specialization.sil

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import Builtin
44

55
sil @paable : $@convention(thin) (Builtin.Int64) -> ()
6+
sil @moved_pai_callee : $@convention(thin) (@inout_aliasable Builtin.Int64) -> ()
67

78
sil [ossa] [transparent] @partial_apply_on_stack_nesting_violator : $@convention(thin) <T> () -> () {
89
%paable = function_ref @paable : $@convention(thin) (Builtin.Int64) -> ()
@@ -34,4 +35,23 @@ sil [no_locks] @test_inline_stack_violating_ossa_func : $@convention(thin) () ->
3435
return %retval : $()
3536
}
3637

37-
38+
// CHECK-LABEL: sil hidden [no_allocation] [ossa] @moved_pai : {{.*}} {
39+
// CHECK-NOT: partial_apply
40+
// CHECK-LABEL: } // end sil function 'moved_pai'
41+
sil hidden [no_allocation] [ossa] @moved_pai : $@convention(thin) () -> Builtin.Int64 {
42+
bb0:
43+
%addr = alloc_stack $Builtin.Int64
44+
%42 = integer_literal $Builtin.Int64, 42
45+
store %42 to [trivial] %addr : $*Builtin.Int64
46+
%callee = function_ref @moved_pai_callee : $@convention(thin) (@inout_aliasable Builtin.Int64) -> ()
47+
%closure = partial_apply [callee_guaranteed] %callee(%addr) : $@convention(thin) (@inout_aliasable Builtin.Int64) -> ()
48+
%closure_lifetime = move_value [lexical] %closure : $@callee_guaranteed () -> ()
49+
debug_value %closure_lifetime : $@callee_guaranteed () -> ()
50+
%copy = copy_value %closure_lifetime : $@callee_guaranteed () -> ()
51+
apply %copy() : $@callee_guaranteed () -> ()
52+
destroy_value %copy : $@callee_guaranteed () -> ()
53+
%retval = load [trivial] %addr : $*Builtin.Int64
54+
destroy_value %closure_lifetime : $@callee_guaranteed () -> ()
55+
dealloc_stack %addr : $*Builtin.Int64
56+
return %retval : $Builtin.Int64
57+
}

0 commit comments

Comments
 (0)