Skip to content

Commit f70f60b

Browse files
authored
Merge pull request #29526 from atrick/fix-guaranteed-phi
Fix propagation of guaranteed phi args during DiagnoseUnreachable.
2 parents 44a6475 + b0786e7 commit f70f60b

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

lib/SILOptimizer/Mandatory/DiagnoseUnreachable.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,9 @@ static void propagateBasicBlockArgs(SILBasicBlock &BB) {
185185
// this to CCP and trigger another round of copy propagation.
186186
SILArgument *Arg = *AI;
187187

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)
192190
deleteEndBorrows(Arg);
193-
}
194191

195192
// We were able to fold, so all users should use the new folded value.
196193
Arg->replaceAllUsesWith(Args[Idx]);

test/SILOptimizer/diagnose_unreachable.sil

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,3 +782,33 @@ bb1(%2 : @owned $Builtin.NativeObject):
782782
bb2:
783783
unreachable
784784
}
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+
}

0 commit comments

Comments
 (0)