Skip to content

Commit f3e9ab6

Browse files
committed
[AllocBoxToStack] Specialize moved PAIs.
Added move_value to the list of instructions looked through when determining whether a partial_apply instruction escapes. rdar://108376960
1 parent cfb3bad commit f3e9ab6

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

lib/SILOptimizer/Transforms/AllocBoxToStack.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,11 @@ static bool partialApplyEscapes(SILValue V, bool examineApply) {
254254

255255
auto *User = Op->getUser();
256256

257-
// If we have a copy_value, the copy value does not cause an escape, but its
258-
// uses might do so... so add the copy_value's uses to the worklist and
259-
// continue.
260-
if (isa<CopyValueInst>(User) || isa<BeginBorrowInst>(User)) {
257+
// If we have a copy_value, begin_borrow, or move_value, that instruction
258+
// does not cause an escape, but its uses might do so... so add the
259+
// its uses to the worklist and continue.
260+
if (isa<CopyValueInst>(User) || isa<BeginBorrowInst>(User) ||
261+
isa<MoveValueInst>(User)) {
261262
llvm::copy(cast<SingleValueInstruction>(User)->getUses(),
262263
std::back_inserter(Worklist));
263264
continue;

test/SILOptimizer/allocbox_to_stack.sil

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,3 +1194,35 @@ bb4:
11941194
%v = tuple ()
11951195
return %v : $()
11961196
}
1197+
1198+
1199+
sil [ossa] @move_closure_callee : $@convention(thin) (@guaranteed { var Builtin.Int32 }) -> () {
1200+
bb0(%box : @closureCapture @guaranteed ${ var Builtin.Int32 }):
1201+
%13 = integer_literal $Builtin.Int32, 13
1202+
%addr = project_box %box : ${ var Builtin.Int32 }, 0
1203+
store %13 to [trivial] %addr : $*Builtin.Int32
1204+
%retval = tuple ()
1205+
return %retval : $()
1206+
}
1207+
1208+
// CHECK-LABEL: sil [ossa] @move_closure : {{.*}} {
1209+
// CHECK: [[SPECIALIZED_CLOSURE:%[^,]+]] = function_ref @$s19move_closure_calleeTf0s_n : $@convention(thin) (@inout_aliasable Builtin.Int32) -> ()
1210+
// CHECK: partial_apply [callee_guaranteed] [[SPECIALIZED_CLOSURE]]
1211+
// CHECK-LABEL: } // end sil function 'move_closure'
1212+
sil [ossa] @move_closure : $@convention(thin) () -> Builtin.Int32 {
1213+
bb0:
1214+
%box = alloc_box ${ var Builtin.Int32 }
1215+
%addr = project_box %box : ${ var Builtin.Int32 }, 0
1216+
%42 = integer_literal $Builtin.Int32, 42
1217+
store %42 to [trivial] %addr : $*Builtin.Int32
1218+
%callee = function_ref @move_closure_callee : $@convention(thin) (@guaranteed { var Builtin.Int32 }) -> ()
1219+
%box_copy = copy_value %box : ${ var Builtin.Int32 }
1220+
mark_function_escape %addr : $*Builtin.Int32
1221+
%closure = partial_apply [callee_guaranteed] %callee(%box_copy) : $@convention(thin) (@guaranteed { var Builtin.Int32 }) -> ()
1222+
%closure_move = move_value %closure : $@callee_guaranteed () -> ()
1223+
apply %closure_move() : $@callee_guaranteed () -> ()
1224+
destroy_value %closure_move : $@callee_guaranteed () -> ()
1225+
%value = load [trivial] %addr : $*Builtin.Int32
1226+
destroy_value %box : ${ var Builtin.Int32 }
1227+
return %value : $Builtin.Int32
1228+
}

0 commit comments

Comments
 (0)