Skip to content

Commit a0b67c6

Browse files
committed
SimplifyCFG: It is okay to ignore dealloc_stack to simplify an unreachable block
1 parent b8a0893 commit a0b67c6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,7 @@ bool SimplifyCFG::simplifyUnreachableBlock(UnreachableInst *UI) {
18651865
case SILInstructionKind::StrongReleaseInst:
18661866
case SILInstructionKind::RetainValueInst:
18671867
case SILInstructionKind::ReleaseValueInst:
1868+
case SILInstructionKind::DeallocStackInst:
18681869
break;
18691870

18701871
default:

test/SILOptimizer/simplify_cfg.sil

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2483,20 +2483,24 @@ sil @rethrow_function : $@convention(thin) (@owned @callee_owned (Int) -> (Int,
24832483
sil @non_throwing_closure : $@convention(thin) (Int) -> Int
24842484

24852485
// CHECK-LABEL: sil @replace_try_apply_with_apply
2486-
// CHECK: [[R:%[0-9]+]] = apply [nothrow] %0(%{{[0-9]+}}) : $@convention(thin) (@owned @callee_owned (Int) -> (Int, @error Error)) -> (Int, @error Error)
2486+
// CHECK: [[R:%[0-9]+]] = apply [nothrow] %1(%{{[0-9]+}}) : $@convention(thin) (@owned @callee_owned (Int) -> (Int, @error Error)) -> (Int, @error Error)
2487+
// CHECK-NEXT: dealloc_stack
24872488
// CHECK-NEXT: return [[R]] : $Int
24882489
sil @replace_try_apply_with_apply : $@convention(thin) () -> Int {
24892490
bb0:
2491+
%as = alloc_stack $Builtin.Int32
24902492
%0 = function_ref @rethrow_function : $@convention(thin) (@owned @callee_owned (Int) -> (Int, @error Error)) -> (Int, @error Error)
24912493
%1 = function_ref @non_throwing_closure : $@convention(thin) (Int) -> Int
24922494
%2 = thin_to_thick_function %1 : $@convention(thin) (Int) -> Int to $@callee_owned (Int) -> Int
24932495
%3 = convert_function %2 : $@callee_owned (Int) -> Int to $@callee_owned (Int) -> (Int, @error Error)
24942496
try_apply %0(%3) : $@convention(thin) (@owned @callee_owned (Int) -> (Int, @error Error)) -> (Int, @error Error), normal bb1, error bb2
24952497

24962498
bb1(%5 : $Int):
2499+
dealloc_stack %as: $*Builtin.Int32
24972500
return %5 : $Int
24982501

24992502
bb2(%8 : $Error):
2503+
dealloc_stack %as: $*Builtin.Int32
25002504
unreachable
25012505
}
25022506

0 commit comments

Comments
 (0)