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 {
70
70
}
71
71
parentBB. moveAllInstructions ( toBeginOf: targetBB, context)
72
72
parentBB. moveAllArguments ( to: targetBB, context)
73
+ context. erase ( block: parentBB)
73
74
} else {
74
75
targetBB. moveAllInstructions ( toEndOf: parentBB, context)
76
+ context. erase ( block: targetBB)
75
77
}
76
78
}
77
79
}
Original file line number Diff line number Diff line change @@ -71,6 +71,10 @@ extension MutatingContext {
71
71
erase ( instruction: inst)
72
72
}
73
73
74
+ func erase( block: BasicBlock ) {
75
+ _bridged. eraseBlock ( block. bridged)
76
+ }
77
+
74
78
func tryOptimizeApplyOfPartialApply( closure: PartialApplyInst ) -> Bool {
75
79
if _bridged. tryOptimizeApplyOfPartialApply ( closure. bridged) {
76
80
notifyInstructionsChanged ( )
@@ -227,10 +231,6 @@ struct FunctionPassContext : MutatingContext {
227
231
}
228
232
}
229
233
230
- func erase( block: BasicBlock ) {
231
- _bridged. eraseBlock ( block. bridged)
232
- }
233
-
234
234
func modifyEffects( in function: Function , _ body: ( inout FunctionEffects ) -> ( ) ) {
235
235
notifyEffectsChanged ( )
236
236
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