|
| 1 | +// RUN: %target-sil-opt -enable-sil-verify-all %s -simplification -simplify-instruction=br | %FileCheck %s |
| 2 | +// RUN: %target-sil-opt -enable-sil-verify-all %s -onone-simplification -simplify-instruction=br -sil-print-debuginfo | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ONONE |
| 3 | + |
| 4 | +// REQUIRES: swift_in_compiler |
| 5 | + |
| 6 | +import Swift |
| 7 | +import Builtin |
| 8 | + |
| 9 | +// CHECK-LABEL: sil @merge_blocks_same_location1 |
| 10 | +// CHECK: %0 = integer_literal $Builtin.Int64, 0 |
| 11 | +// CHECK: fix_lifetime %0 : $Builtin.Int64 |
| 12 | +// CHECK: return %0 : $Builtin.Int64 |
| 13 | +// CHECK: } // end sil function 'merge_blocks_same_location1' |
| 14 | +sil @merge_blocks_same_location1 : $@convention(thin) () -> Builtin.Int64 { |
| 15 | +bb0: |
| 16 | + %0 = integer_literal $Builtin.Int64, 0 |
| 17 | + br bb1(%0 : $Builtin.Int64), loc "a.swift":1:1 |
| 18 | + |
| 19 | +bb1(%2 : $Builtin.Int64): |
| 20 | + fix_lifetime %2 : $Builtin.Int64, loc "a.swift":1:1 |
| 21 | + return %2 : $Builtin.Int64 |
| 22 | +} |
| 23 | + |
| 24 | +// CHECK-LABEL: sil @merge_blocks_same_location2 |
| 25 | +// CHECK: %0 = integer_literal $Builtin.Int64, 0 |
| 26 | +// CHECK: fix_lifetime %0 : $Builtin.Int64 |
| 27 | +// CHECK: return %0 : $Builtin.Int64 |
| 28 | +// CHECK: } // end sil function 'merge_blocks_same_location2' |
| 29 | +sil @merge_blocks_same_location2 : $@convention(thin) () -> Builtin.Int64 { |
| 30 | +bb0: |
| 31 | + %0 = integer_literal $Builtin.Int64, 0, loc "a.swift":1:1 |
| 32 | + br bb1(%0 : $Builtin.Int64), loc "a.swift":1:1 |
| 33 | + |
| 34 | +bb1(%2 : $Builtin.Int64): |
| 35 | + fix_lifetime %2 : $Builtin.Int64 |
| 36 | + return %2 : $Builtin.Int64 |
| 37 | +} |
| 38 | + |
| 39 | +// CHECK-LABEL: sil @merge_blocks_different_locations |
| 40 | +// CHECK: %0 = integer_literal $Builtin.Int64, 0 |
| 41 | +// CHECK-ONONE: debug_step , loc "a.swift":2:1 |
| 42 | +// CHECK: fix_lifetime %0 : $Builtin.Int64 |
| 43 | +// CHECK: return %0 : $Builtin.Int64 |
| 44 | +// CHECK: } // end sil function 'merge_blocks_different_locations' |
| 45 | +sil @merge_blocks_different_locations : $@convention(thin) () -> Builtin.Int64 { |
| 46 | +bb0: |
| 47 | + %0 = integer_literal $Builtin.Int64, 0, loc "a.swift":1:1 |
| 48 | + br bb1(%0 : $Builtin.Int64), loc "a.swift":2:1 |
| 49 | + |
| 50 | +bb1(%2 : $Builtin.Int64): |
| 51 | + fix_lifetime %2 : $Builtin.Int64, loc "a.swift":3:1 |
| 52 | + return %2 : $Builtin.Int64 |
| 53 | +} |
| 54 | + |
| 55 | +// CHECK-LABEL: sil @dont_merge_blocks |
| 56 | +// CHECK: bb1: |
| 57 | +// CHECK-NEXT: br bb3 |
| 58 | +// CHECK: bb2: |
| 59 | +// CHECK-NEXT: br bb3 |
| 60 | +// CHECK: } // end sil function 'dont_merge_blocks' |
| 61 | +sil @dont_merge_blocks : $@convention(thin) () -> () { |
| 62 | +bb0: |
| 63 | + cond_br undef, bb1, bb2 |
| 64 | + |
| 65 | +bb1: |
| 66 | + br bb3 |
| 67 | + |
| 68 | +bb2: |
| 69 | + br bb3 |
| 70 | + |
| 71 | +bb3: |
| 72 | + %r = tuple () |
| 73 | + return %r : $() |
| 74 | +} |
| 75 | + |
| 76 | +// CHECK-LABEL: sil @dont_merge_block_in_single_cycle |
| 77 | +// CHECK: bb1: |
| 78 | +// CHECK-NEXT: br bb1 |
| 79 | +// CHECK: } // end sil function 'dont_merge_block_in_single_cycle' |
| 80 | +sil @dont_merge_block_in_single_cycle : $@convention(thin) () -> () { |
| 81 | +bb0: |
| 82 | + br bb1 |
| 83 | + |
| 84 | +bb1: |
| 85 | + br bb1 |
| 86 | +} |
| 87 | + |
| 88 | +// CHECK-LABEL: sil @dont_crash_with_unreachable_invalid_dominance |
| 89 | +// CHECK-NOT: bb1 |
| 90 | +// CHECK: } // end sil function 'dont_crash_with_unreachable_invalid_dominance' |
| 91 | +sil @dont_crash_with_unreachable_invalid_dominance : $@convention(thin) (Builtin.Int64) -> Builtin.Int64 { |
| 92 | +bb0(%0 : $Builtin.Int64): |
| 93 | + return %0 : $Builtin.Int64 |
| 94 | + |
| 95 | +bb1(%2 : $Builtin.Int64): |
| 96 | + br bb2 |
| 97 | + |
| 98 | +bb2: |
| 99 | + br bb1(%2 : $Builtin.Int64) |
| 100 | +} |
| 101 | + |
0 commit comments