Skip to content

[ome] Just erase the destructure rather than trying to get rid of dea… #27606

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
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
5 changes: 2 additions & 3 deletions lib/SILOptimizer/Transforms/OwnershipModelEliminator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,8 @@ static void splitDestructure(SILBuilder &B, SILInstruction *I, SILValue Op) {
Result->replaceAllUsesWith(ProjInst);
}

// We may have exposed trivially dead instructions due to
// simplifyInstruction... delete I and any such instructions!
recursivelyDeleteTriviallyDeadInstructions(I, true);
// Now that all of its uses have been eliminated, erase the destructure.
I->eraseFromParent();
}

bool OwnershipModelEliminatorVisitor::visitDestructureStructInst(
Expand Down
15 changes: 14 additions & 1 deletion test/SILOptimizer/ownership_model_eliminator.sil
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,24 @@ bb0(%0 : @owned $(Builtin.NativeObject, Builtin.Int32), %1 : @owned $TestArray2)

// CHECK-LABEL: sil [canonical] @test_simplify_instruction : $@convention(thin) (@owned Builtin.NativeObject, Builtin.Int32) -> @owned Builtin.NativeObject {
// CHECK: bb0([[ARG:%.*]] : $Builtin.NativeObject,
// CHECK-NEXT: return [[ARG]]
// CHECK: return [[ARG]]
// CHECK: } // end sil function 'test_simplify_instruction'
sil [canonical] [ossa] @test_simplify_instruction : $@convention(thin) (@owned Builtin.NativeObject, Builtin.Int32) -> @owned Builtin.NativeObject {
bb0(%0 : @owned $Builtin.NativeObject, %1 : $Builtin.Int32):
%2 = tuple(%0 : $Builtin.NativeObject, %1 : $Builtin.Int32)
(%3, %4) = destructure_tuple %2 : $(Builtin.NativeObject, Builtin.Int32)
return %3 : $Builtin.NativeObject
}

// Just make sure that we do not crash on this function.
//
// CHECK-LABEL: sil @do_not_crash_due_to_debug_value_use : $@convention(thin) (Builtin.Int32, Builtin.Int32) -> () {
// CHECK: } // end sil function 'do_not_crash_due_to_debug_value_use'
sil [ossa] @do_not_crash_due_to_debug_value_use : $@convention(thin) (Builtin.Int32, Builtin.Int32) -> () {
bb0(%0a : $Builtin.Int32, %0b : $Builtin.Int32):
%0 = tuple(%0a : $Builtin.Int32, %0b : $Builtin.Int32)
(%1, %2) = destructure_tuple %0 : $(Builtin.Int32, Builtin.Int32)
debug_value %0 : $(Builtin.Int32, Builtin.Int32), let, name "myName2"
%9999 = tuple()
return %9999 : $()
}