File tree Expand file tree Collapse file tree 2 files changed +32
-5
lines changed
lib/SILOptimizer/Mandatory Expand file tree Collapse file tree 2 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -185,12 +185,9 @@ static void propagateBasicBlockArgs(SILBasicBlock &BB) {
185
185
// this to CCP and trigger another round of copy propagation.
186
186
SILArgument *Arg = *AI;
187
187
188
- // If this argument is guaranteed and Args[Idx] is a SILFunctionArgument,
189
- // delete the end_borrow.
190
- if (Arg->getOwnershipKind () == ValueOwnershipKind::Guaranteed &&
191
- isa<SILFunctionArgument>(Args[Idx])) {
188
+ // If this argument is guaranteed and Args[Idx], delete the end_borrow.
189
+ if (Arg->getOwnershipKind () == ValueOwnershipKind::Guaranteed)
192
190
deleteEndBorrows (Arg);
193
- }
194
191
195
192
// We were able to fold, so all users should use the new folded value.
196
193
Arg->replaceAllUsesWith (Args[Idx]);
Original file line number Diff line number Diff line change @@ -782,3 +782,33 @@ bb1(%2 : @owned $Builtin.NativeObject):
782
782
bb2:
783
783
unreachable
784
784
}
785
+
786
+ // Test propagation of guaranteed phi arguments. The nested end_borrow
787
+ // must be removed, even with the outer borrow is *not* a function
788
+ // argument.
789
+
790
+ enum EnumWithB {
791
+ case A(B)
792
+ func testit() -> Int
793
+ }
794
+
795
+ // CHECK-LABEL: sil hidden [ossa] @testPropagateGuaranteedPhi : $@convention(method) (@guaranteed EnumWithB) -> () {
796
+ // CHECK: bb1([[PHI:%.*]] : @guaranteed $B):
797
+ // CHECK: br bb2
798
+ // CHECK: bb2:
799
+ // CHECK: end_borrow [[PHI]] : $B
800
+ // CHECK-NOT: end_borrow
801
+ // CHECK-LABEL: } // end sil function 'testPropagateGuaranteedPhi'
802
+ sil hidden [ossa] @testPropagateGuaranteedPhi : $@convention(method) (@guaranteed EnumWithB) -> () {
803
+ bb0(%0 : @guaranteed $EnumWithB):
804
+ switch_enum %0 : $EnumWithB, case #EnumWithB.A!enumelt.1: bb1
805
+
806
+ bb1(%2 : @guaranteed $B):
807
+ br bb3(%2 : $B)
808
+
809
+ bb3(%4 : @guaranteed $B):
810
+ end_borrow %4 : $B
811
+ end_borrow %2 : $B
812
+ %99 = tuple ()
813
+ return %99 : $()
814
+ }
You can’t perform that action at this time.
0 commit comments