|
| 1 | +// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -licm | %FileCheck %s |
| 2 | +// REQUIRES: CPU=x86_64 |
| 3 | +// REQUIRES: OS=macosx |
| 4 | + |
| 5 | +sil_stage canonical |
| 6 | + |
| 7 | +import Builtin |
| 8 | +import Swift |
| 9 | +import SwiftShims |
| 10 | + |
| 11 | +var x: Int |
| 12 | + |
| 13 | +let reversedArray: ReversedCollection<[Int]> |
| 14 | + |
| 15 | +// x |
| 16 | +sil_global hidden @$S3tmp1xSivp : $Int |
| 17 | + |
| 18 | +// reversedArray |
| 19 | +sil_global hidden [let] @$S3tmp13reversedArrays18ReversedCollectionVySaySiGGvp : $ReversedCollection<Array<Int>> |
| 20 | + |
| 21 | +// _swiftEmptyArrayStorage |
| 22 | +sil_global @_swiftEmptyArrayStorage : $_SwiftEmptyArrayStorage |
| 23 | + |
| 24 | + |
| 25 | +// CHECK-LABEL: sil hidden @multi_end_licm : $@convention(thin) () -> () { |
| 26 | +// CHECK: bb2: |
| 27 | +// CHECK: [[GLOBALVAR:%.*]] = global_addr @$S3tmp1xSivp : $*Int |
| 28 | +// CHECK: [[BEGINA:%.*]] = begin_access [modify] [dynamic] [no_nested_conflict] [[GLOBALVAR]] : $*Int |
| 29 | +// CHECK-NEXT: br [[LOOPH:bb[0-9]+]]({{.*}} : $Builtin.Int64) |
| 30 | +// CHECK: [[LOOPH]]({{.*}} : $Builtin.Int64) |
| 31 | +// CHECK: cond_br {{.*}}, [[LOOPCOND1:bb[0-9]+]], [[LOOPCOND2:bb[0-9]+]] |
| 32 | +// CHECK: [[LOOPCOND1]]: |
| 33 | +// CHECK-NEXT: store |
| 34 | +// CHECK-NEXT: cond_br {{.*}}, [[LOOPEXIT1:bb[0-9]+]], [[LOOPCONT1:bb[0-9]+]] |
| 35 | +// CHECK: [[LOOPEXIT1]]: |
| 36 | +// CHECK-NEXT: end_access [[BEGINA]] : $*Int |
| 37 | +// CHECK-NEXT: br [[LOOPAFTEREXIT:bb[0-9]+]] |
| 38 | +// CHECK: [[LOOPCOND2]]: |
| 39 | +// CHECK-NEXT: struct $Int |
| 40 | +// CHECK-NEXT: store |
| 41 | +// CHECK-NEXT: cond_br {{.*}}, [[LOOPEXIT2:bb[0-9]+]], [[LOOPCONT1]] |
| 42 | +// CHECK: [[LOOPEXIT2]]: |
| 43 | +// CHECK-NEXT: end_access [[BEGINA]] : $*Int |
| 44 | +// CHECK-NEXT: br [[LOOPAFTEREXIT]] |
| 45 | +// CHECK: [[LOOPCONT1]]: |
| 46 | +// CHECK-NEXT: br [[LOOPH]] |
| 47 | +// CHECK: [[LOOPAFTEREXIT]]: |
| 48 | +// CHECK-NEXT: br [[FUNCRET:bb[0-9]+]] |
| 49 | +// CHECK: [[FUNCRET]]: |
| 50 | +// CHECK-NEXT: tuple |
| 51 | +// CHECK-NEXT: return |
| 52 | +sil hidden @multi_end_licm : $@convention(thin) () -> () { |
| 53 | +bb0: |
| 54 | + %0 = global_addr @$S3tmp13reversedArrays18ReversedCollectionVySaySiGGvp : $*ReversedCollection<Array<Int>> |
| 55 | + %1 = struct_element_addr %0 : $*ReversedCollection<Array<Int>>, #ReversedCollection._base |
| 56 | + %2 = struct_element_addr %1 : $*Array<Int>, #Array._buffer |
| 57 | + %3 = struct_element_addr %2 : $*_ArrayBuffer<Int>, #_ArrayBuffer._storage |
| 58 | + %4 = struct_element_addr %3 : $*_BridgeStorage<_ContiguousArrayStorageBase, _NSArrayCore>, #_BridgeStorage.rawValue |
| 59 | + %5 = load %4 : $*Builtin.BridgeObject |
| 60 | + %6 = unchecked_ref_cast %5 : $Builtin.BridgeObject to $_ContiguousArrayStorageBase |
| 61 | + %7 = ref_element_addr %6 : $_ContiguousArrayStorageBase, #_ContiguousArrayStorageBase.countAndCapacity |
| 62 | + %8 = struct_element_addr %7 : $*_ArrayBody, #_ArrayBody._storage |
| 63 | + %9 = struct_element_addr %8 : $*_SwiftArrayBodyStorage, #_SwiftArrayBodyStorage.count |
| 64 | + %10 = struct_element_addr %9 : $*Int, #Int._value |
| 65 | + %11 = load %10 : $*Builtin.Int64 |
| 66 | + %12 = builtin "assumeNonNegative_Int64"(%11 : $Builtin.Int64) : $Builtin.Int64 |
| 67 | + %13 = integer_literal $Builtin.Int64, 0 |
| 68 | + %14 = integer_literal $Builtin.Int1, 0 |
| 69 | + %15 = builtin "cmp_eq_Int64"(%12 : $Builtin.Int64, %13 : $Builtin.Int64) : $Builtin.Int1 |
| 70 | + %16 = builtin "int_expect_Int1"(%15 : $Builtin.Int1, %14 : $Builtin.Int1) : $Builtin.Int1 |
| 71 | + cond_br %16, bb1, bb2 |
| 72 | + |
| 73 | +bb1: |
| 74 | + br bbRet |
| 75 | + |
| 76 | +bb2: |
| 77 | + %19 = global_addr @$S3tmp1xSivp : $*Int |
| 78 | + %20 = integer_literal $Builtin.Int64, 1 |
| 79 | + %21 = integer_literal $Builtin.Int1, -1 |
| 80 | + %23 = ref_tail_addr %6 : $_ContiguousArrayStorageBase, $Int |
| 81 | + br bb4(%12 : $Builtin.Int64) |
| 82 | + |
| 83 | +bb4(%27 : $Builtin.Int64): |
| 84 | + %28 = builtin "ssub_with_overflow_Int64"(%27 : $Builtin.Int64, %20 : $Builtin.Int64, %21 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1) |
| 85 | + %29 = tuple_extract %28 : $(Builtin.Int64, Builtin.Int1), 0 |
| 86 | + %30 = tuple_extract %28 : $(Builtin.Int64, Builtin.Int1), 1 |
| 87 | + cond_fail %30 : $Builtin.Int1 |
| 88 | + %32 = builtin "cmp_slt_Int64"(%29 : $Builtin.Int64, %13 : $Builtin.Int64) : $Builtin.Int1 |
| 89 | + %33 = load %10 : $*Builtin.Int64 |
| 90 | + %34 = builtin "assumeNonNegative_Int64"(%33 : $Builtin.Int64) : $Builtin.Int64 |
| 91 | + %35 = builtin "cmp_slt_Int64"(%29 : $Builtin.Int64, %34 : $Builtin.Int64) : $Builtin.Int1 |
| 92 | + %36 = builtin "xor_Int1"(%35 : $Builtin.Int1, %21 : $Builtin.Int1) : $Builtin.Int1 |
| 93 | + %37 = builtin "or_Int1"(%32 : $Builtin.Int1, %36 : $Builtin.Int1) : $Builtin.Int1 |
| 94 | + cond_fail %37 : $Builtin.Int1 |
| 95 | + %39 = builtin "truncOrBitCast_Int64_Word"(%29 : $Builtin.Int64) : $Builtin.Word |
| 96 | + %40 = index_addr %23 : $*Int, %39 : $Builtin.Word |
| 97 | + %41 = struct_element_addr %40 : $*Int, #Int._value |
| 98 | + %42 = load %41 : $*Builtin.Int64 |
| 99 | + %43 = struct $Int (%42 : $Builtin.Int64) |
| 100 | + debug_value %43 : $Int, let, name "item" |
| 101 | + %global = begin_access [modify] [dynamic] [no_nested_conflict] %19 : $*Int |
| 102 | + %46 = builtin "cmp_eq_Int64"(%29 : $Builtin.Int64, %13 : $Builtin.Int64) : $Builtin.Int1 |
| 103 | + %47 = builtin "int_expect_Int1"(%46 : $Builtin.Int1, %14 : $Builtin.Int1) : $Builtin.Int1 |
| 104 | + cond_br %47, bbend1, bbend2 |
| 105 | + |
| 106 | +bbend1: |
| 107 | + store %43 to %global : $*Int |
| 108 | + end_access %global : $*Int |
| 109 | + cond_br %47, bb6, bb5 |
| 110 | + |
| 111 | +bbend2: |
| 112 | + %otherInt = struct $Int (%27 : $Builtin.Int64) |
| 113 | + store %otherInt to %global : $*Int |
| 114 | + end_access %global : $*Int |
| 115 | + cond_br %47, bb6, bb5 |
| 116 | + |
| 117 | +bb5: |
| 118 | + br bb4(%29 : $Builtin.Int64) |
| 119 | + |
| 120 | +bb6: |
| 121 | + br bbRet |
| 122 | + |
| 123 | +bbRet: |
| 124 | + %25 = tuple () |
| 125 | + return %25 : $() |
| 126 | +} // end sil function 'multi_end_licm' |
| 127 | + |
| 128 | +// CHECK-LABEL: sil hidden @multi_end_licm_loop_exit : $@convention(thin) () -> () { |
| 129 | +// CHECK: br [[LOOPH:bb[0-9]+]]({{.*}} : $Builtin.Int64) |
| 130 | +// CHECK: [[LOOPH]]({{.*}} : $Builtin.Int64) |
| 131 | +// CHECK: begin_access [modify] [dynamic] [no_nested_conflict] |
| 132 | +// CHECK: cond_br {{.*}}, [[LOOPCOND1:bb[0-9]+]], [[LOOPCOND2:bb[0-9]+]] |
| 133 | +// CHECK: [[LOOPCOND1]] |
| 134 | +// CHECK-NEXT: store |
| 135 | +// CHECK-NEXT: end_access |
| 136 | +// CHECK: return |
| 137 | +sil hidden @multi_end_licm_loop_exit : $@convention(thin) () -> () { |
| 138 | +bb0: |
| 139 | + %0 = global_addr @$S3tmp13reversedArrays18ReversedCollectionVySaySiGGvp : $*ReversedCollection<Array<Int>> |
| 140 | + %1 = struct_element_addr %0 : $*ReversedCollection<Array<Int>>, #ReversedCollection._base |
| 141 | + %2 = struct_element_addr %1 : $*Array<Int>, #Array._buffer |
| 142 | + %3 = struct_element_addr %2 : $*_ArrayBuffer<Int>, #_ArrayBuffer._storage |
| 143 | + %4 = struct_element_addr %3 : $*_BridgeStorage<_ContiguousArrayStorageBase, _NSArrayCore>, #_BridgeStorage.rawValue |
| 144 | + %5 = load %4 : $*Builtin.BridgeObject |
| 145 | + %6 = unchecked_ref_cast %5 : $Builtin.BridgeObject to $_ContiguousArrayStorageBase |
| 146 | + %7 = ref_element_addr %6 : $_ContiguousArrayStorageBase, #_ContiguousArrayStorageBase.countAndCapacity |
| 147 | + %8 = struct_element_addr %7 : $*_ArrayBody, #_ArrayBody._storage |
| 148 | + %9 = struct_element_addr %8 : $*_SwiftArrayBodyStorage, #_SwiftArrayBodyStorage.count |
| 149 | + %10 = struct_element_addr %9 : $*Int, #Int._value |
| 150 | + %11 = load %10 : $*Builtin.Int64 |
| 151 | + %12 = builtin "assumeNonNegative_Int64"(%11 : $Builtin.Int64) : $Builtin.Int64 |
| 152 | + %13 = integer_literal $Builtin.Int64, 0 |
| 153 | + %14 = integer_literal $Builtin.Int1, 0 |
| 154 | + %15 = builtin "cmp_eq_Int64"(%12 : $Builtin.Int64, %13 : $Builtin.Int64) : $Builtin.Int1 |
| 155 | + %16 = builtin "int_expect_Int1"(%15 : $Builtin.Int1, %14 : $Builtin.Int1) : $Builtin.Int1 |
| 156 | + cond_br %16, bb1, bb2 |
| 157 | + |
| 158 | +bb1: |
| 159 | + br bbRet |
| 160 | + |
| 161 | +bb2: |
| 162 | + %19 = global_addr @$S3tmp1xSivp : $*Int |
| 163 | + %20 = integer_literal $Builtin.Int64, 1 |
| 164 | + %21 = integer_literal $Builtin.Int1, -1 |
| 165 | + %23 = ref_tail_addr %6 : $_ContiguousArrayStorageBase, $Int |
| 166 | + br bb4(%12 : $Builtin.Int64) |
| 167 | + |
| 168 | +bb4(%27 : $Builtin.Int64): |
| 169 | + %28 = builtin "ssub_with_overflow_Int64"(%27 : $Builtin.Int64, %20 : $Builtin.Int64, %21 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1) |
| 170 | + %29 = tuple_extract %28 : $(Builtin.Int64, Builtin.Int1), 0 |
| 171 | + %30 = tuple_extract %28 : $(Builtin.Int64, Builtin.Int1), 1 |
| 172 | + cond_fail %30 : $Builtin.Int1 |
| 173 | + %32 = builtin "cmp_slt_Int64"(%29 : $Builtin.Int64, %13 : $Builtin.Int64) : $Builtin.Int1 |
| 174 | + %33 = load %10 : $*Builtin.Int64 |
| 175 | + %34 = builtin "assumeNonNegative_Int64"(%33 : $Builtin.Int64) : $Builtin.Int64 |
| 176 | + %35 = builtin "cmp_slt_Int64"(%29 : $Builtin.Int64, %34 : $Builtin.Int64) : $Builtin.Int1 |
| 177 | + %36 = builtin "xor_Int1"(%35 : $Builtin.Int1, %21 : $Builtin.Int1) : $Builtin.Int1 |
| 178 | + %37 = builtin "or_Int1"(%32 : $Builtin.Int1, %36 : $Builtin.Int1) : $Builtin.Int1 |
| 179 | + cond_fail %37 : $Builtin.Int1 |
| 180 | + %39 = builtin "truncOrBitCast_Int64_Word"(%29 : $Builtin.Int64) : $Builtin.Word |
| 181 | + %40 = index_addr %23 : $*Int, %39 : $Builtin.Word |
| 182 | + %41 = struct_element_addr %40 : $*Int, #Int._value |
| 183 | + %42 = load %41 : $*Builtin.Int64 |
| 184 | + %43 = struct $Int (%42 : $Builtin.Int64) |
| 185 | + debug_value %43 : $Int, let, name "item" |
| 186 | + %global = begin_access [modify] [dynamic] [no_nested_conflict] %19 : $*Int |
| 187 | + %46 = builtin "cmp_eq_Int64"(%29 : $Builtin.Int64, %13 : $Builtin.Int64) : $Builtin.Int1 |
| 188 | + %47 = builtin "int_expect_Int1"(%46 : $Builtin.Int1, %14 : $Builtin.Int1) : $Builtin.Int1 |
| 189 | + cond_br %47, bbend1, bbend2 |
| 190 | + |
| 191 | +bbend1: |
| 192 | + store %43 to %global : $*Int |
| 193 | + end_access %global : $*Int |
| 194 | + cond_br %47, bb6, bb5 |
| 195 | + |
| 196 | +bbend2: |
| 197 | + %otherInt = struct $Int (%27 : $Builtin.Int64) |
| 198 | + store %otherInt to %global : $*Int |
| 199 | + cond_br %47, bbOut, bb5 |
| 200 | + |
| 201 | +bbOut: |
| 202 | + end_access %global : $*Int |
| 203 | + br bb6 |
| 204 | + |
| 205 | +bb5: |
| 206 | + br bb4(%29 : $Builtin.Int64) |
| 207 | + |
| 208 | +bb6: |
| 209 | + br bbRet |
| 210 | + |
| 211 | +bbRet: |
| 212 | + %25 = tuple () |
| 213 | + return %25 : $() |
| 214 | +} // end sil function 'multi_end_licm_loop_exit' |
0 commit comments