Skip to content

Fix propagation of guaranteed phi args during DiagnoseUnreachable. #29526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/SILOptimizer/Mandatory/DiagnoseUnreachable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,9 @@ static void propagateBasicBlockArgs(SILBasicBlock &BB) {
// this to CCP and trigger another round of copy propagation.
SILArgument *Arg = *AI;

// If this argument is guaranteed and Args[Idx] is a SILFunctionArgument,
// delete the end_borrow.
if (Arg->getOwnershipKind() == ValueOwnershipKind::Guaranteed &&
isa<SILFunctionArgument>(Args[Idx])) {
// If this argument is guaranteed and Args[Idx], delete the end_borrow.
if (Arg->getOwnershipKind() == ValueOwnershipKind::Guaranteed)
deleteEndBorrows(Arg);
}

// We were able to fold, so all users should use the new folded value.
Arg->replaceAllUsesWith(Args[Idx]);
Expand Down
30 changes: 30 additions & 0 deletions test/SILOptimizer/diagnose_unreachable.sil
Original file line number Diff line number Diff line change
Expand Up @@ -782,3 +782,33 @@ bb1(%2 : @owned $Builtin.NativeObject):
bb2:
unreachable
}

// Test propagation of guaranteed phi arguments. The nested end_borrow
// must be removed, even with the outer borrow is *not* a function
// argument.

enum EnumWithB {
case A(B)
func testit() -> Int
}

// CHECK-LABEL: sil hidden [ossa] @testPropagateGuaranteedPhi : $@convention(method) (@guaranteed EnumWithB) -> () {
// CHECK: bb1([[PHI:%.*]] : @guaranteed $B):
// CHECK: br bb2
// CHECK: bb2:
// CHECK: end_borrow [[PHI]] : $B
// CHECK-NOT: end_borrow
// CHECK-LABEL: } // end sil function 'testPropagateGuaranteedPhi'
sil hidden [ossa] @testPropagateGuaranteedPhi : $@convention(method) (@guaranteed EnumWithB) -> () {
bb0(%0 : @guaranteed $EnumWithB):
switch_enum %0 : $EnumWithB, case #EnumWithB.A!enumelt.1: bb1

bb1(%2 : @guaranteed $B):
br bb3(%2 : $B)

bb3(%4 : @guaranteed $B):
end_borrow %4 : $B
end_borrow %2 : $B
%99 = tuple ()
return %99 : $()
}