|
1 | 1 | // RUN: %target-sil-opt -copy-to-borrow-optimization %s | %FileCheck %s
|
| 2 | +// REQUIRES: macosx |
2 | 3 |
|
3 | 4 | sil_stage canonical
|
4 | 5 |
|
@@ -2220,3 +2221,42 @@ sil [ossa] @keep_yield2ed_copy : $@convention(thin) () -> () {
|
2220 | 2221 | %retval = tuple ()
|
2221 | 2222 | return %retval : $()
|
2222 | 2223 | }
|
| 2224 | + |
| 2225 | +// CHECK-LABEL: sil [ossa] @borrowed_from_forward1 : {{.*}} { |
| 2226 | +// CHECK-NOT: copy_value |
| 2227 | +// CHECK-LABEL: } // end sil function 'borrowed_from_forward1' |
| 2228 | +sil [ossa] @borrowed_from_forward1 : $@convention(thin) (@guaranteed C) -> () { |
| 2229 | +bb0(%0 : @guaranteed $C): |
| 2230 | + br bb1(%0) |
| 2231 | + |
| 2232 | +bb1(%1 : @guaranteed $C): |
| 2233 | + %2 = borrowed %1 from (%0) |
| 2234 | + %copy = copy_value %2 |
| 2235 | + %useC = function_ref @useC : $@convention(thin) (@guaranteed C) -> () |
| 2236 | + apply %useC(%copy) : $@convention(thin) (@guaranteed C) -> () |
| 2237 | + destroy_value %copy |
| 2238 | + %retval = tuple () |
| 2239 | + return %retval : $() |
| 2240 | +} |
| 2241 | + |
| 2242 | +// CHECK-LABEL: sil [ossa] @borrowed_from_forward2 : {{.*}} { |
| 2243 | +// CHECK-NOT: copy_value |
| 2244 | +// CHECK-LABEL: } // end sil function 'borrowed_from_forward2' |
| 2245 | +sil [ossa] @borrowed_from_forward2 : $@convention(thin) (@guaranteed Array<Int>) -> () { |
| 2246 | +bb0(%0 : @guaranteed $Array<Int>): |
| 2247 | + %1 = struct_extract %0, #Array._buffer |
| 2248 | + %2 = struct_extract %1, #_ArrayBuffer._storage |
| 2249 | + %3 = struct_extract %2, #_BridgeStorage.rawValue |
| 2250 | + %4 = unchecked_ref_cast %3 to $__ContiguousArrayStorageBase |
| 2251 | + br bb1(%4) |
| 2252 | + |
| 2253 | +bb1(%6 : @guaranteed $__ContiguousArrayStorageBase): |
| 2254 | + %7 = borrowed %6 from (%0) |
| 2255 | + %8 = copy_value %7 |
| 2256 | + %9 = begin_borrow %8 |
| 2257 | + %10 = ref_element_addr [immutable] %9, #__ContiguousArrayStorageBase.countAndCapacity |
| 2258 | + end_borrow %9 |
| 2259 | + destroy_value %8 |
| 2260 | + %13 = tuple () |
| 2261 | + return %13 |
| 2262 | +} |
0 commit comments