File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed
SwiftCompilerSources/Sources/Optimizer
InstructionSimplification Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -70,8 +70,10 @@ private extension BranchInst {
7070 }
7171 parentBB. moveAllInstructions ( toBeginOf: targetBB, context)
7272 parentBB. moveAllArguments ( to: targetBB, context)
73+ context. erase ( block: parentBB)
7374 } else {
7475 targetBB. moveAllInstructions ( toEndOf: parentBB, context)
76+ context. erase ( block: targetBB)
7577 }
7678 }
7779}
Original file line number Diff line number Diff line change @@ -71,6 +71,10 @@ extension MutatingContext {
7171 erase ( instruction: inst)
7272 }
7373
74+ func erase( block: BasicBlock ) {
75+ _bridged. eraseBlock ( block. bridged)
76+ }
77+
7478 func tryOptimizeApplyOfPartialApply( closure: PartialApplyInst ) -> Bool {
7579 if _bridged. tryOptimizeApplyOfPartialApply ( closure. bridged) {
7680 notifyInstructionsChanged ( )
@@ -227,10 +231,6 @@ struct FunctionPassContext : MutatingContext {
227231 }
228232 }
229233
230- func erase( block: BasicBlock ) {
231- _bridged. eraseBlock ( block. bridged)
232- }
233-
234234 func modifyEffects( in function: Function , _ body: ( inout FunctionEffects ) -> ( ) ) {
235235 notifyEffectsChanged ( )
236236 function. _modifyEffects ( body)
Original file line number Diff line number Diff line change 1+ // RUN: %target-sil-opt -enable-sil-verify-all %s -sil-opt-pass-count=1.1 -simplification -simplify-instruction=br | %FileCheck %s
2+
3+ // REQUIRES: swift_in_compiler
4+
5+ import Swift
6+ import Builtin
7+
8+ // Check that branch simplification doesn't leave empty blocks.
9+ // -sil-opt-pass-count=1.1 prevents dead block elimination which would hide the problem.
10+
11+
12+
13+ // CHECK-LABEL: sil @dont_leave_empty_blocks
14+ // CHECK: bb0(%0 : $Builtin.Int64):
15+ // CHECK-NEXT: br bb1
16+ // CHECK: bb1:
17+ // CHECK-NEXT: return %0
18+ // CHECK: } // end sil function 'dont_leave_empty_blocks'
19+ sil @dont_leave_empty_blocks : $@convention(thin) (Builtin.Int64) -> Builtin.Int64 {
20+ bb0(%0 : $Builtin.Int64):
21+ br bb1
22+
23+ bb1:
24+ br bb2
25+
26+ bb2:
27+ return %0 : $Builtin.Int64
28+ }
You can’t perform that action at this time.
0 commit comments