Skip to content

Commit 1621692

Browse files
committed
[CopyPropagation] Eliminate redundant moves.
SemanticARCOpts already eliminates move values that are redundant that block its optimizations. But it's always run after CopyPropagation. Because move_values divide copy-extended lifetimes, move_values obstruct lifetime canonicalization. If a move_value isn't separating lifetimes with different characteristics (specifically: lexicallity, escaping), then it is only obstructing lifetime canonicalization. Remove it before canonicalizing the lifetime of the moved-from value.
1 parent e929453 commit 1621692

File tree

4 files changed

+104
-43
lines changed

4 files changed

+104
-43
lines changed

lib/SILOptimizer/Transforms/CopyPropagation.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "swift/SIL/BasicBlockDatastructures.h"
4343
#include "swift/SIL/BasicBlockUtils.h"
4444
#include "swift/SIL/DebugUtils.h"
45+
#include "swift/SIL/OwnershipUtils.h"
4546
#include "swift/SIL/SILUndef.h"
4647
#include "swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h"
4748
#include "swift/SILOptimizer/Analysis/DeadEndBlocksAnalysis.h"
@@ -263,6 +264,24 @@ static bool convertExtractsToDestructures(CanonicalDefWorklist &copiedDefs,
263264
return changed;
264265
}
265266

267+
//===----------------------------------------------------------------------===//
268+
// MARK: Eliminate redundant moves
269+
//===----------------------------------------------------------------------===//
270+
271+
/// If the specified move_value is redundant (there's no benefit to separating
272+
/// the lifetime at it), replace its uses with uses of the moved-from value and
273+
/// delete it.
274+
static bool eliminateRedundantMove(MoveValueInst *mvi,
275+
InstructionDeleter &deleter) {
276+
if (!isRedundantMoveValue(mvi))
277+
return false;
278+
mvi->replaceAllUsesWith(mvi->getOperand());
279+
// Call InstructionDeleter::forceDeleteWithUsers to avoid "fixing up"
280+
// ownership of the moved-from value, i.e. inserting a destroy_value.
281+
deleter.forceDeleteWithUsers(mvi);
282+
return true;
283+
}
284+
266285
//===----------------------------------------------------------------------===//
267286
// MARK: Sink owned forwarding operations
268287
//===----------------------------------------------------------------------===//
@@ -420,6 +439,7 @@ void CopyPropagation::run() {
420439
bool changed = false;
421440

422441
StackList<BeginBorrowInst *> beginBorrowsToShrink(f);
442+
StackList<MoveValueInst *> moveValues(f);
423443

424444
// Driver: Find all copied or borrowed defs.
425445
for (auto &bb : *f) {
@@ -428,6 +448,8 @@ void CopyPropagation::run() {
428448
defWorklist.updateForCopy(copy);
429449
} else if (auto *borrow = dyn_cast<BeginBorrowInst>(&i)) {
430450
beginBorrowsToShrink.push_back(borrow);
451+
} else if (auto *move = dyn_cast<MoveValueInst>(&i)) {
452+
moveValues.push_back(move);
431453
} else if (canonicalizeAll) {
432454
if (auto *destroy = dyn_cast<DestroyValueInst>(&i)) {
433455
defWorklist.updateForCopy(destroy->getOperand());
@@ -480,9 +502,13 @@ void CopyPropagation::run() {
480502
hoistDestroysOfOwnedLexicalValue(folded, *f, deleter, calleeAnalysis);
481503
// Keep running even if the new move's destroys can't be hoisted.
482504
(void)hoisted;
505+
eliminateRedundantMove(folded, deleter);
483506
firstRun = false;
484507
}
485508
}
509+
for (auto *mvi : moveValues) {
510+
eliminateRedundantMove(mvi, deleter);
511+
}
486512
for (auto *argument : f->getArguments()) {
487513
if (argument->getOwnershipKind() == OwnershipKind::Owned) {
488514
hoistDestroysOfOwnedLexicalValue(argument, *f, deleter, calleeAnalysis);

test/SILOptimizer/copy_propagation.sil

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,16 +851,19 @@ bb0(%0 : @owned $C):
851851
// Test that copy propagation doesn't hoist a destroy_value corresponding to
852852
// a move value [lexical] over a barrier.
853853
// CHECK-LABEL: sil [ossa] @dont_hoist_move_value_lexical_destroy_over_barrier_apply : {{.*}} {
854-
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] : @owned $C):
854+
// CHECK: [[GET_OWNED_C:%.*]] = function_ref @getOwnedC
855+
// CHECK: [[INSTANCE:%.*]] = apply [[GET_OWNED_C]]
855856
// CHECK: [[LIFETIME:%[^,]+]] = move_value [lexical] [[INSTANCE]]
856857
// CHECK: [[BARRIER:%[^,]+]] = function_ref @barrier
857858
// CHECK: [[TAKE_GUARANTEED_C:%[^,]+]] = function_ref @takeGuaranteedC
858859
// CHECK: apply [[TAKE_GUARANTEED_C]]([[LIFETIME]])
859860
// CHECK: apply [[BARRIER]]()
860861
// CHECK: destroy_value [[LIFETIME]]
861862
// CHECK-LABEL: } // end sil function 'dont_hoist_move_value_lexical_destroy_over_barrier_apply'
862-
sil [ossa] @dont_hoist_move_value_lexical_destroy_over_barrier_apply : $@convention(thin) (@owned C) -> () {
863-
entry(%instance : @owned $C):
863+
sil [ossa] @dont_hoist_move_value_lexical_destroy_over_barrier_apply : $@convention(thin) () -> () {
864+
entry:
865+
%getOwnedC = function_ref @getOwnedC : $@convention(thin) () -> (@owned C)
866+
%instance = apply %getOwnedC() : $@convention(thin) () -> (@owned C)
864867
%lifetime = move_value [lexical] %instance : $C
865868
%barrier = function_ref @barrier : $@convention(thin) () -> ()
866869
%takeGuaranteedC = function_ref @takeGuaranteedC : $@convention(thin) (@guaranteed C) -> ()

test/SILOptimizer/lexical_destroy_folding.sil

Lines changed: 71 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ sil [ossa] @get_owned : $@convention(thin) () -> @owned C
2828
// with an apply.
2929
//
3030
// CHECK-LABEL: sil [ossa] @fold_simplest : {{.*}} {
31-
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
31+
// CHECK: [[GET_OWNED:%[^,]+]] = function_ref @get_owned
32+
// CHECK: [[INSTANCE:%[^,]+]] = apply [[GET_OWNED]]
3233
// CHECK: [[CALEE_OWNED:%[^,]+]] = function_ref @callee_owned
3334
// CHECK: [[MOVE:%[^,]+]] = move_value [lexical] [[INSTANCE]]
3435
// CHECK: apply [[CALEE_OWNED]]([[MOVE]])
3536
// CHECK-LABEL: } // end sil function 'fold_simplest'
36-
sil [ossa] @fold_simplest : $@convention(thin) (@owned C) -> () {
37-
entry(%instance : @owned $C):
37+
sil [ossa] @fold_simplest : $@convention(thin) () -> () {
38+
%get_owned = function_ref @get_owned : $@convention(thin) () -> (@owned C)
39+
%instance = apply %get_owned() : $@convention(thin) () -> (@owned C)
3840
%callee_owned = function_ref @callee_owned : $@convention(thin) (@owned C) -> ()
3941
%lifetime = begin_borrow [lexical] %instance : $C
4042
%copy = copy_value %lifetime : $C
@@ -83,7 +85,8 @@ entry(%instance : @owned $C):
8385
// borrowee intact on other paths.
8486
//
8587
// CHECK-LABEL: sil [ossa] @fold_left_only : {{.*}} {
86-
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
88+
// CHECK: [[GET_OWNED:%[^,]+]] = function_ref @get_owned
89+
// CHECK: [[INSTANCE:%[^,]+]] = apply [[GET_OWNED]]
8790
// CHECK: [[CALLEE_OWNED:%[^,]+]] = function_ref @callee_owned
8891
// CHECK: cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
8992
// CHECK: [[LEFT]]:
@@ -95,8 +98,10 @@ entry(%instance : @owned $C):
9598
// CHECK: br [[EXIT]]
9699
// CHECK: [[EXIT]]:
97100
// CHECK-LABEL: } // end sil function 'fold_left_only'
98-
sil [ossa] @fold_left_only : $@convention(thin) (@owned C) -> () {
99-
entry(%instance : @owned $C):
101+
sil [ossa] @fold_left_only : $@convention(thin) () -> () {
102+
entry:
103+
%get_owned = function_ref @get_owned : $@convention(thin) () -> (@owned C)
104+
%instance = apply %get_owned() : $@convention(thin) () -> (@owned C)
100105
%callee_owned = function_ref @callee_owned : $@convention(thin) (@owned C) -> ()
101106
cond_br undef, left, right
102107

@@ -122,7 +127,8 @@ exit:
122127
// independents owned lexical scopes.
123128
//
124129
// CHECK-LABEL: sil [ossa] @fold_two_independent_scopes : {{.*}} {
125-
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
130+
// CHECK: [[GET_OWNED:%[^,]+]] = function_ref @get_owned
131+
// CHECK: [[INSTANCE:%[^,]+]] = apply [[GET_OWNED]]
126132
// CHECK: [[CALLEE_OWNED:%[^,]+]] = function_ref @callee_owned
127133
// CHECK: cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
128134
// CHECK: [[LEFT]]:
@@ -135,8 +141,10 @@ exit:
135141
// CHECK: br [[EXIT]]
136142
// CHECK: [[EXIT]]:
137143
// CHECK-LABEL: } // end sil function 'fold_two_independent_scopes'
138-
sil [ossa] @fold_two_independent_scopes : $@convention(thin) (@owned C) -> () {
139-
entry(%instance : @owned $C):
144+
sil [ossa] @fold_two_independent_scopes : $@convention(thin) () -> () {
145+
entry:
146+
%get_owned = function_ref @get_owned : $@convention(thin) () -> (@owned C)
147+
%instance = apply %get_owned() : $@convention(thin) () -> (@owned C)
140148
%callee_owned = function_ref @callee_owned : $@convention(thin) (@owned C) -> ()
141149
cond_br undef, left, right
142150

@@ -211,7 +219,8 @@ exit:
211219
// within a single owned lexical scope.
212220
//
213221
// CHECK-LABEL: sil [ossa] @fold_two_parallel_applies___canonical_destroys : {{.*}} {
214-
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
222+
// CHECK: [[GET_OWNED:%[^,]+]] = function_ref @get_owned
223+
// CHECK: [[INSTANCE:%[^,]+]] = apply [[GET_OWNED]]
215224
// CHECK: [[CALLEE_OWNED:%[^,]+]] = function_ref @callee_owned
216225
// CHECK: [[MOVE:%[^,]+]] = move_value [lexical] [[INSTANCE]] : $C
217226
// CHECK: cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
@@ -223,8 +232,10 @@ exit:
223232
// CHECK: br [[EXIT]]
224233
// CHECK: [[EXIT]]:
225234
// CHECK-LABEL: } // end sil function 'fold_two_parallel_applies___canonical_destroys'
226-
sil [ossa] @fold_two_parallel_applies___canonical_destroys : $@convention(thin) (@owned C) -> () {
227-
entry(%instance : @owned $C):
235+
sil [ossa] @fold_two_parallel_applies___canonical_destroys : $@convention(thin) () -> () {
236+
entry:
237+
%get_owned = function_ref @get_owned : $@convention(thin) () -> (@owned C)
238+
%instance = apply %get_owned() : $@convention(thin) () -> (@owned C)
228239
%callee_owned = function_ref @callee_owned : $@convention(thin) (@owned C) -> ()
229240
%lifetime = begin_borrow [lexical] %instance : $C
230241
cond_br undef, left, right
@@ -253,7 +264,8 @@ exit:
253264
// borrowee that is not within the scope.
254265
//
255266
// CHECK-LABEL: sil [ossa] @fold_multiblock_borrow_single_apply_with_parallel_use : {{.*}} {
256-
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
267+
// CHECK: [[GET_OWNED:%[^,]+]] = function_ref @get_owned
268+
// CHECK: [[INSTANCE:%[^,]+]] = apply [[GET_OWNED]]
257269
// CHECK: [[CALLEE_OWNED:%[^,]+]] = function_ref @callee_owned
258270
// CHECK: cond_br undef, [[LEFT1:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
259271
// CHECK: [[LEFT1]]:
@@ -270,8 +282,10 @@ exit:
270282
// CHECK: br [[EXIT]]
271283
// CHECK: [[EXIT]]:
272284
// CHECK-LABEL: } // end sil function 'fold_multiblock_borrow_single_apply_with_parallel_use'
273-
sil [ossa] @fold_multiblock_borrow_single_apply_with_parallel_use : $@convention(thin) (@owned C) -> () {
274-
entry(%instance : @owned $C):
285+
sil [ossa] @fold_multiblock_borrow_single_apply_with_parallel_use : $@convention(thin) () -> () {
286+
entry:
287+
%get_owned = function_ref @get_owned : $@convention(thin) () -> (@owned C)
288+
%instance = apply %get_owned() : $@convention(thin) () -> (@owned C)
275289
%callee_owned = function_ref @callee_owned : $@convention(thin) (@owned C) -> ()
276290
cond_br undef, left1, right
277291

@@ -306,7 +320,8 @@ exit:
306320
// borrowee that is not within the scope.
307321
//
308322
// CHECK-LABEL: sil [ossa] @fold_multiblock_borrow_single_apply_and_parallel_singleblock_borrow : {{.*}} {
309-
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
323+
// CHECK: [[GET_OWNED:%[^,]+]] = function_ref @get_owned
324+
// CHECK: [[INSTANCE:%[^,]+]] = apply [[GET_OWNED]]
310325
// CHECK: [[CALLEE_OWNED:%[^,]+]] = function_ref @callee_owned
311326
// CHECK: cond_br undef, [[LEFT1:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
312327
// CHECK: [[LEFT1]]:
@@ -324,8 +339,10 @@ exit:
324339
// CHECK: br [[EXIT]]
325340
// CHECK: [[EXIT]]:
326341
// CHECK-LABEL: } // end sil function 'fold_multiblock_borrow_single_apply_and_parallel_singleblock_borrow'
327-
sil [ossa] @fold_multiblock_borrow_single_apply_and_parallel_singleblock_borrow : $@convention(thin) (@owned C) -> () {
328-
entry(%instance : @owned $C):
342+
sil [ossa] @fold_multiblock_borrow_single_apply_and_parallel_singleblock_borrow : $@convention(thin) () -> () {
343+
entry:
344+
%get_owned = function_ref @get_owned : $@convention(thin) () -> (@owned C)
345+
%instance = apply %get_owned() : $@convention(thin) () -> (@owned C)
329346
%callee_owned = function_ref @callee_owned : $@convention(thin) (@owned C) -> ()
330347
cond_br undef, left1, right
331348

@@ -364,7 +381,8 @@ exit:
364381
// guaranteed lifetime remains.
365382
//
366383
// CHECK-LABEL: sil [ossa] @fold_single_block_one_apply_double_use_all_owned : {{.*}} {
367-
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
384+
// CHECK: [[GET_OWNED:%[^,]+]] = function_ref @get_owned
385+
// CHECK: [[INSTANCE:%[^,]+]] = apply [[GET_OWNED]]
368386
// CHECK: [[LIFETIME:%[^,]+]] = move_value [lexical] [[INSTANCE]]
369387
// CHECK: [[LIFETIME_GUARANTEED:%[^,]+]] = begin_borrow [lexical] [[LIFETIME]]
370388
// CHECK: [[CALLEE_GUARANTEED:%[^,]+]] = function_ref @callee_guaranteed
@@ -374,8 +392,10 @@ exit:
374392
// CHECK: [[CALLEE_OWNED_OWNED:%[^,]+]] = function_ref @callee_owned_owned
375393
// CHECK: apply [[CALLEE_OWNED_OWNED]]([[LIFETIME]], [[COPY]])
376394
// CHECK-LABEL: } // end sil function 'fold_single_block_one_apply_double_use_all_owned'
377-
sil [ossa] @fold_single_block_one_apply_double_use_all_owned : $@convention(thin) (@owned C) -> () {
378-
entry(%instance : @owned $C):
395+
sil [ossa] @fold_single_block_one_apply_double_use_all_owned : $@convention(thin) () -> () {
396+
entry:
397+
%get_owned = function_ref @get_owned : $@convention(thin) () -> (@owned C)
398+
%instance = apply %get_owned() : $@convention(thin) () -> (@owned C)
379399
%lifetime = begin_borrow [lexical] %instance : $C
380400
%callee_guaranteed = function_ref @callee_guaranteed : $@convention(thin) (@guaranteed C) -> ()
381401
apply %callee_guaranteed(%lifetime) : $@convention(thin) (@guaranteed C) -> ()
@@ -393,14 +413,17 @@ entry(%instance : @owned $C):
393413
// guaranteed lifetime remains.
394414
//
395415
// CHECK-LABEL: sil [ossa] @fold_single_block_one_apply_double_use_all_owned__no_remaining_uses : {{.*}} {
396-
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
416+
// CHECK: [[GET_OWNED:%[^,]+]] = function_ref @get_owned
417+
// CHECK: [[INSTANCE:%[^,]+]] = apply [[GET_OWNED]]
397418
// CHECK: [[MOVE:%[^,]+]] = move_value [lexical] [[INSTANCE]]
398419
// CHECK: [[COPY:%[^,]+]] = copy_value [[MOVE]]
399420
// CHECK: [[CALLEE_OWNED_OWNED:%[^,]+]] = function_ref @callee_owned_owned
400421
// CHECK: apply [[CALLEE_OWNED_OWNED]]([[MOVE]], [[COPY]])
401422
// CHECK-LABEL: } // end sil function 'fold_single_block_one_apply_double_use_all_owned__no_remaining_uses'
402-
sil [ossa] @fold_single_block_one_apply_double_use_all_owned__no_remaining_uses : $@convention(thin) (@owned C) -> () {
403-
entry(%instance : @owned $C):
423+
sil [ossa] @fold_single_block_one_apply_double_use_all_owned__no_remaining_uses : $@convention(thin) () -> () {
424+
entry:
425+
%get_owned = function_ref @get_owned : $@convention(thin) () -> (@owned C)
426+
%instance = apply %get_owned() : $@convention(thin) () -> (@owned C)
404427
%lifetime = begin_borrow [lexical] %instance : $C
405428
%copy_1 = copy_value %lifetime : $C
406429
%copy_2 = copy_value %lifetime : $C
@@ -464,7 +487,8 @@ entry(%instance : @owned $C):
464487
// Fold with the last consuming use but not with a previous consuming use.
465488
//
466489
// CHECK-LABEL: sil [ossa] @fold_single_block_two_applies_first_only : {{.*}} {
467-
// CHECK: bb0([[INSTANCE:%[^,]+]] :
490+
// CHECK: [[GET_OWNED:%[^,]+]] = function_ref @get_owned
491+
// CHECK: [[INSTANCE:%[^,]+]] = apply [[GET_OWNED]]
468492
// CHECK: [[MOVE:%[^,]+]] = move_value [lexical] [[INSTANCE]]
469493
// CHECK: [[LIFETIME:%[^,]+]] = begin_borrow [lexical] [[MOVE]]
470494
// CHECK: [[CALLEE_OWNED:%[^,]+]] = function_ref @callee_owned
@@ -474,8 +498,9 @@ entry(%instance : @owned $C):
474498
// CHECK: tuple ()
475499
// CHECK: apply [[CALLEE_OWNED]]([[MOVE]])
476500
// CHECK-LABEL: } // end sil function 'fold_single_block_two_applies_first_only'
477-
sil [ossa] @fold_single_block_two_applies_first_only : $@convention(thin) (@owned C) -> () {
478-
entry(%instance : @owned $C):
501+
sil [ossa] @fold_single_block_two_applies_first_only : $@convention(thin) () -> () {
502+
%get_owned = function_ref @get_owned : $@convention(thin) () -> (@owned C)
503+
%instance = apply %get_owned() : $@convention(thin) () -> (@owned C)
479504
%lifetime = begin_borrow [lexical] %instance : $C
480505
%callee_owned = function_ref @callee_owned : $@convention(thin) (@owned C) -> ()
481506
%copy_1 = copy_value %lifetime : $C
@@ -523,23 +548,27 @@ exit:
523548
// and the lexical scope ends before the use on the non-lexical branch.
524549
//
525550
// CHECK-LABEL: sil [ossa] @nofold_two_parallel_owned_uses_one_lexical___scope_ends_before_use : {{.*}} {
526-
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
527-
// CHECK: [[COPY:%[^,]+]] = copy_value [[INSTANCE]]
528-
// CHECK: [[MOVE:%[^,]+]] = move_value [lexical] [[INSTANCE]]
551+
// CHECK: [[GET_OWNED:%[^,]+]] = function_ref @get_owned
552+
// CHECK: [[INSTANCE:%[^,]+]] = apply [[GET_OWNED]]
553+
// CHECK: [[LIFETIME:%[^,]+]] = begin_borrow [lexical] [[INSTANCE]]
529554
// CHECK: [[CALLEE_OWNED:%[^,]+]] = function_ref @callee_owned
530555
// CHECK: cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
531556
// CHECK: [[LEFT]]:
532-
// CHECK: apply [[CALLEE_OWNED]]([[MOVE]])
533-
// CHECK: destroy_value [[COPY]]
557+
// CHECK: [[COPY:%[^,]+]] = copy_value [[LIFETIME]]
558+
// CHECK: apply [[CALLEE_OWNED]]([[COPY]])
559+
// CHECK: end_borrow [[LIFETIME]]
560+
// CHECK: destroy_value [[INSTANCE]]
534561
// CHECK: br [[EXIT:bb[0-9]+]]
535562
// CHECK: [[RIGHT]]:
536-
// CHECK: destroy_value [[MOVE]]
537-
// CHECK: apply [[CALLEE_OWNED]]([[COPY]])
563+
// CHECK: end_borrow [[LIFETIME]]
564+
// CHECK: apply [[CALLEE_OWNED]]([[INSTANCE]])
538565
// CHECK: br [[EXIT]]
539566
// CHECK: [[EXIT]]:
540567
// CHECK-LABEL: } // end sil function 'nofold_two_parallel_owned_uses_one_lexical___scope_ends_before_use'
541-
sil [ossa] @nofold_two_parallel_owned_uses_one_lexical___scope_ends_before_use : $@convention(thin) (@owned C) -> () {
542-
entry(%instance : @owned $C):
568+
sil [ossa] @nofold_two_parallel_owned_uses_one_lexical___scope_ends_before_use : $@convention(thin) () -> () {
569+
entry:
570+
%get_owned = function_ref @get_owned : $@convention(thin) () -> (@owned C)
571+
%instance = apply %get_owned() : $@convention(thin) () -> (@owned C)
543572
%copy_2 = copy_value %instance : $C
544573
%lifetime = begin_borrow [lexical] %instance : $C
545574
%callee_owned = function_ref @callee_owned : $@convention(thin) (@owned C) -> ()
@@ -618,7 +647,8 @@ exit:
618647
// use of %original_borrowee in that unreachable-terminated branch.
619648
//
620649
// CHECK-LABEL: sil [ossa] @fold_unreachable : {{.*}} {
621-
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
650+
// CHECK: [[GET_OWNED:%[^,]+]] = function_ref @get_owned
651+
// CHECK: [[INSTANCE:%[^,]+]] = apply [[GET_OWNED]]
622652
// CHECK: [[MOVE:%[^,]+]] = move_value [lexical] [[INSTANCE]]
623653
// CHECK: cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
624654
// CHECK: [[LEFT]]:
@@ -629,8 +659,10 @@ exit:
629659
// CHECK: br [[EXIT:bb[0-9]+]]
630660
// CHECK: [[EXIT]]:
631661
// CHECK-LABEL: } // end sil function 'fold_unreachable'
632-
sil [ossa] @fold_unreachable : $@convention(thin) (@owned C) -> () {
633-
entry(%instance : @owned $C):
662+
sil [ossa] @fold_unreachable : $@convention(thin) () -> () {
663+
entry:
664+
%get_owned = function_ref @get_owned : $@convention(thin) () -> (@owned C)
665+
%instance = apply %get_owned() : $@convention(thin) () -> (@owned C)
634666
%lifetime = begin_borrow [lexical] %instance : $C
635667
cond_br undef, left, right
636668

test/SILOptimizer/shrink_borrow_scope.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,9 @@ exit:
556556
// CHECK: [[COPY_C:%[^,]+]] = copy_value [[LIFETIME_C]]
557557
// CHECK: [[LIFETIME_D:%[^,]+]] = begin_borrow [[INSTANCE_D]]
558558
// CHECK: struct $CDCase ([[LIFETIME_C]] : $C, [[LIFETIME_D]] : $D)
559-
// CHECK: end_borrow [[LIFETIME_C]]
560559
// CHECK: end_borrow [[LIFETIME_D]]
561560
// CHECK: destroy_value [[INSTANCE_D]]
561+
// CHECK: end_borrow [[LIFETIME_C]]
562562
// CHECK: return [[COPY_C]]
563563
// CHECK-LABEL: } // end sil function 'hoist_over_struct'
564564
sil [ossa] @hoist_over_struct : $@convention(thin) (@owned C, @owned D) -> @owned C {

0 commit comments

Comments
 (0)