File tree Expand file tree Collapse file tree 4 files changed +61
-3
lines changed Expand file tree Collapse file tree 4 files changed +61
-3
lines changed Original file line number Diff line number Diff line change @@ -107,8 +107,16 @@ SILValue stripBorrow(SILValue V);
107
107
// / type may be changed by a cast.
108
108
SingleValueInstruction *getSingleValueCopyOrCast (SILInstruction *I);
109
109
110
+ // Return true if this instruction begins a SIL-level scope. If so, it must have
111
+ // a single result. That result must have an isEndOfScopeMarker direct use on
112
+ // all reachable paths. This instruction along with its scope-ending
113
+ // instructions are considered a single operation. They must be inserted and
114
+ // deleted together.
115
+ bool isBeginScopeMarker (SILInstruction *user);
116
+
110
117
// / Return true if this instruction terminates a SIL-level scope. Scope end
111
- // / instructions do not produce a result.
118
+ // / instructions do not produce a result. Their single operand must be an
119
+ // / isBeginScopeMarker and cannot be 'undef'.
112
120
bool isEndOfScopeMarker (SILInstruction *user);
113
121
114
122
// / Return true if the given instruction has no effect on it's operand values
Original file line number Diff line number Diff line change @@ -295,7 +295,16 @@ SingleValueInstruction *swift::getSingleValueCopyOrCast(SILInstruction *I) {
295
295
}
296
296
}
297
297
298
- // Does this instruction terminate a SIL-level scope?
298
+ bool swift::isBeginScopeMarker (SILInstruction *user) {
299
+ switch (user->getKind ()) {
300
+ default :
301
+ return false ;
302
+ case SILInstructionKind::BeginAccessInst:
303
+ case SILInstructionKind::BeginBorrowInst:
304
+ return true ;
305
+ }
306
+ }
307
+
299
308
bool swift::isEndOfScopeMarker (SILInstruction *user) {
300
309
switch (user->getKind ()) {
301
310
default :
Original file line number Diff line number Diff line change @@ -844,6 +844,15 @@ SILInstruction *SILCombiner::visitCondFailInst(CondFailInst *CFI) {
844
844
ValueSet DefinedValues (CFI->getFunction ());
845
845
for (auto Iter = std::next (CFI->getIterator ());
846
846
Iter != CFI->getParent ()->end (); ++Iter) {
847
+
848
+ if (isBeginScopeMarker (&*Iter)) {
849
+ for (auto *scopeUse : cast<SingleValueInstruction>(&*Iter)->getUses ()) {
850
+ auto *scopeEnd = scopeUse->getUser ();
851
+ if (isEndOfScopeMarker (scopeEnd)) {
852
+ ToRemove.push_back (scopeEnd);
853
+ }
854
+ }
855
+ }
847
856
if (!CFI->getFunction ()->hasOwnership ()) {
848
857
ToRemove.push_back (&*Iter);
849
858
continue ;
@@ -870,6 +879,9 @@ SILInstruction *SILCombiner::visitCondFailInst(CondFailInst *CFI) {
870
879
return nullptr ;
871
880
872
881
for (auto *Inst : ToRemove) {
882
+ if (Inst->isDeleted ())
883
+ continue ;
884
+
873
885
// Replace any still-remaining uses with undef and erase.
874
886
Inst->replaceAllUsesOfAllResultsWithUndef ();
875
887
eraseInstFromFunction (*Inst);
Original file line number Diff line number Diff line change @@ -587,6 +587,35 @@ bb0(%0 : $Builtin.Int1):
587
587
return %2 : $()
588
588
}
589
589
590
+ // rdar://121599876 (SILCombine should delete instructions in blocks dominated by cond_fail -1)
591
+ // CHECK-LABEL: sil @cond_fail_end_scope : $@convention(thin) (@inout Builtin.Int32, Builtin.Int1) -> () {
592
+ // CHECK: cond_fail
593
+ // CHECK-NEXT: unreachable
594
+ // CHECK: bb1:
595
+ // CHECK-NEXT: br bb3
596
+ // CHECK: bb2:
597
+ // CHECK-NEXT: br bb3
598
+ // CHECK-LABEL: } // end sil function 'cond_fail_end_scope'
599
+ sil @cond_fail_end_scope : $@convention(thin) (@inout Builtin.Int32, Builtin.Int1) -> () {
600
+ entry(%0 : $*Builtin.Int32, %1 : $Builtin.Int1):
601
+ %true = integer_literal $Builtin.Int1, -1
602
+ cond_fail %true : $Builtin.Int1
603
+ %access = begin_access [read] [static] %0 : $*Builtin.Int32
604
+ cond_br %1, left, right
605
+
606
+ left:
607
+ end_access %access : $*Builtin.Int32
608
+ br end
609
+
610
+ right:
611
+ end_access %access : $*Builtin.Int32
612
+ br end
613
+
614
+ end:
615
+ %99 = tuple ()
616
+ return %99 : $()
617
+ }
618
+
590
619
// CHECK-LABEL: sil @release_then_retain_peephole
591
620
// CHECK: bb0
592
621
// CHECK-NOT: strong_release
@@ -3688,7 +3717,7 @@ bb3(%16 : $Int32): // Preds: bb1 bb2
3688
3717
return %16 : $Int32 // id: %17
3689
3718
}
3690
3719
3691
- protocol Prot0 : class {
3720
+ protocol Prot0 : AnyObject {
3692
3721
static func newWithConfig() throws -> Builtin.Int32
3693
3722
}
3694
3723
You can’t perform that action at this time.
0 commit comments