Skip to content

Commit 2dbf54d

Browse files
committed
[ome] Just erase the destructure rather than trying to get rid of dead instructions due to simplifyInstruction.
This ensures that we do not run into any iterator invalidation issues. It does worsen the passes output slightly, but avoiding the complexity is worth it and other later passes will clean up the dead code. rdar://55811732 (cherry picked from commit 1b29d86)
1 parent 0640fef commit 2dbf54d

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/SILOptimizer/Transforms/OwnershipModelEliminator.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,8 @@ static void splitDestructure(SILBuilder &B, SILInstruction *I, SILValue Op) {
285285
Result->replaceAllUsesWith(ProjInst);
286286
}
287287

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

293292
bool OwnershipModelEliminatorVisitor::visitDestructureStructInst(

test/SILOptimizer/ownership_model_eliminator.sil

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,24 @@ bb0(%0 : @owned $(Builtin.NativeObject, Builtin.Int32), %1 : @owned $TestArray2)
321321

322322
// CHECK-LABEL: sil [canonical] @test_simplify_instruction : $@convention(thin) (@owned Builtin.NativeObject, Builtin.Int32) -> @owned Builtin.NativeObject {
323323
// CHECK: bb0([[ARG:%.*]] : $Builtin.NativeObject,
324-
// CHECK-NEXT: return [[ARG]]
324+
// CHECK: return [[ARG]]
325325
// CHECK: } // end sil function 'test_simplify_instruction'
326326
sil [canonical] [ossa] @test_simplify_instruction : $@convention(thin) (@owned Builtin.NativeObject, Builtin.Int32) -> @owned Builtin.NativeObject {
327327
bb0(%0 : @owned $Builtin.NativeObject, %1 : $Builtin.Int32):
328328
%2 = tuple(%0 : $Builtin.NativeObject, %1 : $Builtin.Int32)
329329
(%3, %4) = destructure_tuple %2 : $(Builtin.NativeObject, Builtin.Int32)
330330
return %3 : $Builtin.NativeObject
331331
}
332+
333+
// Just make sure that we do not crash on this function.
334+
//
335+
// CHECK-LABEL: sil @do_not_crash_due_to_debug_value_use : $@convention(thin) (Builtin.Int32, Builtin.Int32) -> () {
336+
// CHECK: } // end sil function 'do_not_crash_due_to_debug_value_use'
337+
sil [ossa] @do_not_crash_due_to_debug_value_use : $@convention(thin) (Builtin.Int32, Builtin.Int32) -> () {
338+
bb0(%0a : $Builtin.Int32, %0b : $Builtin.Int32):
339+
%0 = tuple(%0a : $Builtin.Int32, %0b : $Builtin.Int32)
340+
(%1, %2) = destructure_tuple %0 : $(Builtin.Int32, Builtin.Int32)
341+
debug_value %0 : $(Builtin.Int32, Builtin.Int32), let, name "myName2"
342+
%9999 = tuple()
343+
return %9999 : $()
344+
}

0 commit comments

Comments
 (0)