File: ownership_model_eliminator.sil

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (413 lines) | stat: -rw-r--r-- 20,656 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
// RUN: %target-sil-opt -ownership-model-eliminator %s | %FileCheck %s

sil_stage raw

import Builtin

sil @use_native_object : $@convention(thin) (@owned Builtin.NativeObject) -> ()
sil @use_native_object_inguaranteed : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> ()
sil @use_int32 : $@convention(thin) (Builtin.Int32) -> ()

enum Either<T, R> {
case left(T)
case some(R)
}

class C {}

struct PairOfInt {
  var lhs : Builtin.Int32
  var rhs : Builtin.Int32
}

// CHECK-LABEL: sil @load : $@convention(thin) (@in Builtin.NativeObject, @in Builtin.Int32) -> () {
// CHECK: bb0([[ARG1:%[0-9]+]] : $*Builtin.NativeObject, [[ARG2:%[0-9]+]] : $*Builtin.Int32):
// CHECK: [[LOAD2:%[0-9]+]] = load [[ARG1]] : $*Builtin.NativeObject
// CHECK: strong_retain [[LOAD2]]
// CHECK: apply {{%[0-9]+}}([[LOAD2]])
// CHECK: [[LOAD3:%[0-9]+]] = load [[ARG1]] : $*Builtin.NativeObject
// CHECK: apply {{%[0-9]+}}([[LOAD3]])
// CHECK: [[LOAD4:%[0-9]+]] = load [[ARG2]] : $*Builtin.Int32
// CHECK: apply {{%[0-9]+}}([[LOAD4]])
sil [ossa] @load : $@convention(thin) (@in Builtin.NativeObject, @in Builtin.Int32) -> () {
bb0(%0 : $*Builtin.NativeObject, %1 : $*Builtin.Int32):
  %use_native_object_func = function_ref @use_native_object : $@convention(thin) (@owned Builtin.NativeObject) -> ()
  %use_int32_func = function_ref @use_int32 : $@convention(thin) (Builtin.Int32) -> ()

  %3 = load [copy] %0 : $*Builtin.NativeObject
  apply %use_native_object_func(%3) : $@convention(thin) (@owned Builtin.NativeObject) -> ()

  %4 = load [take] %0 : $*Builtin.NativeObject
  apply %use_native_object_func(%4) : $@convention(thin) (@owned Builtin.NativeObject) -> ()

  %5 = load [trivial] %1 : $*Builtin.Int32
  apply %use_int32_func(%5) : $@convention(thin) (Builtin.Int32) -> ()

  %9999 = tuple()
  return %9999 : $()
}

// CHECK-LABEL: sil @store : $@convention(thin) (Builtin.NativeObject, @in Builtin.Int32, Builtin.Int32) -> @out Builtin.NativeObject {
// CHECK: bb0([[ARG1:%[0-9]+]] : $*Builtin.NativeObject, [[ARG2:%[0-9]+]] : $Builtin.NativeObject, [[ARG3:%[0-9]+]] : $*Builtin.Int32, [[ARG4:%[0-9]+]] : $Builtin.Int32):
// CHECK: strong_retain [[ARG2]]
// CHECK: strong_retain [[ARG2]]
// CHECK: store [[ARG2]] to [[ARG1]] : $*Builtin.NativeObject
// CHECK: [[OLDVAL:%[0-9]+]] = load [[ARG1]] : $*Builtin.NativeObject
// CHECK: store [[ARG2]] to [[ARG1]] : $*Builtin.NativeObject
// CHECK: strong_release [[OLDVAL]]
// CHECK: store [[ARG4]] to [[ARG3]] : $*Builtin.Int32
sil [ossa] @store : $@convention(thin) (Builtin.NativeObject, @in Builtin.Int32, Builtin.Int32) -> @out Builtin.NativeObject {
bb0(%0 : $*Builtin.NativeObject, %1 : @unowned $Builtin.NativeObject, %2 : $*Builtin.Int32, %3 : $Builtin.Int32):
  %4 = copy_value %1 : $Builtin.NativeObject
  %5 = copy_value %1 : $Builtin.NativeObject
  store %4 to [init] %0 : $*Builtin.NativeObject
  store %5 to [assign] %0 : $*Builtin.NativeObject
  store %3 to [trivial] %2 : $*Builtin.Int32
  %9999 = tuple()
  return %9999 : $()
}

// CHECK-LABEL: sil @borrow : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> () {
// CHECK: bb0([[ARG:%[0-9]+]] : $*Builtin.NativeObject):
// CHECK: [[BORROWED_VALUE:%[0-9]+]] = load [[ARG]] : $*Builtin.NativeObject
// CHECK: unchecked_ref_cast [[BORROWED_VALUE]]
// CHECK-NOT: end_borrow
sil [ossa] @borrow : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> () {
bb0(%0 : $*Builtin.NativeObject):
  %1 = load_borrow %0 : $*Builtin.NativeObject
  %2 = unchecked_ref_cast %1 : $Builtin.NativeObject to $Builtin.NativeObject
  end_borrow %1 : $Builtin.NativeObject
  %3 = tuple()
  return %3 : $()
}

sil @opaque_function : $@convention(thin) () -> ()

// CHECK-LABEL: sil @copy_value_destroy_value : $@convention(thin) (@owned Builtin.NativeObject) -> @owned Builtin.NativeObject {
// CHECK: bb0([[ARG1:%.*]] : $Builtin.NativeObject):
// CHECK: strong_retain [[ARG1]]
// CHECK: strong_release [[ARG1]]
// CHECK: return [[ARG1]]
sil [ossa] @copy_value_destroy_value : $@convention(thin) (@owned Builtin.NativeObject) -> @owned Builtin.NativeObject {
bb0(%0 : @owned $Builtin.NativeObject):
  %1 = function_ref @opaque_function : $@convention(thin) () -> ()
  %2 = copy_value %0 : $Builtin.NativeObject
  apply %1() : $@convention(thin) () -> ()
  destroy_value %0 : $Builtin.NativeObject
  return %2 : $Builtin.NativeObject
}

// CHECK-LABEL: sil @begin_borrow_store_borrow : $@convention(thin) (@owned Builtin.NativeObject) -> () {
// CHECK: bb0([[ARG:%.*]] : $Builtin.NativeObject):
// CHECK-NEXT: [[MEM:%.*]] = alloc_stack $Builtin.NativeObject
// CHECK-NEXT: store [[ARG]] to [[MEM]] : $*Builtin.NativeObject
// CHECK-NEXT: dealloc_stack [[MEM]] : $*Builtin.NativeObject
// CHECK-NEXT: strong_release [[ARG]]
// CHECK-NEXT: tuple ()
// CHECK-NEXT: return
// CHECK: } // end sil function 'begin_borrow_store_borrow'
sil [ossa] @begin_borrow_store_borrow : $@convention(thin) (@owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject):
  %1 = begin_borrow %0 : $Builtin.NativeObject
  end_borrow %1 : $Builtin.NativeObject
  %2 = alloc_stack $Builtin.NativeObject
  %3 = begin_borrow %0 : $Builtin.NativeObject
  %4 = store_borrow %3 to %2 : $*Builtin.NativeObject
  end_borrow %4 : $*Builtin.NativeObject
  end_borrow %3 : $Builtin.NativeObject
  dealloc_stack %2 : $*Builtin.NativeObject
  destroy_value %0 : $Builtin.NativeObject
  %9999 = tuple()
  return %9999 : $()
}

// We no longer lower strong_copy_unowned_value. So make sure that we actually don't.
//
// CHECK-LABEL: sil @strong_copy_unowned_value_test : $@convention(thin) (@owned @sil_unowned Builtin.NativeObject) -> () {
// CHECK: bb0([[ARG:%.*]] : $@sil_unowned Builtin.NativeObject):
// CHECK-NEXT: [[STRONG:%.*]] = strong_copy_unowned_value [[ARG]] : $@sil_unowned Builtin.NativeObject
// CHECK-NEXT: strong_release [[STRONG]] : $Builtin.NativeObject
// CHECK-NEXT: unowned_release [[ARG]] : $@sil_unowned Builtin.NativeObject
// CHECK-NEXT: tuple ()
// CHECK-NEXT: return
sil [ossa] @strong_copy_unowned_value_test : $@convention(thin) (@owned @sil_unowned Builtin.NativeObject) -> () {
bb0(%0 : @owned $@sil_unowned Builtin.NativeObject):
  %1 = strong_copy_unowned_value %0 : $@sil_unowned Builtin.NativeObject
  destroy_value %1 : $Builtin.NativeObject
  destroy_value %0 : $@sil_unowned Builtin.NativeObject
  %9999 = tuple()
  return %9999 : $()
}

// CHECK-LABEL: sil @unmanaged_retain_release_test : $@convention(thin) (@owned Builtin.NativeObject, @owned C) -> () {
// CHECK: bb0([[ARG1:%.*]] : $Builtin.NativeObject, [[ARG2:%.*]] : $C):
// CHECK: strong_retain [[ARG1]] : $Builtin.NativeObject
// CHECK: autorelease_value [[ARG2]] : $C
// CHECK: strong_release [[ARG1]] : $Builtin.NativeObject
// CHECK: strong_release [[ARG1]] : $Builtin.NativeObject
// CHECK: } // end sil function 'unmanaged_retain_release_test'
sil [ossa] @unmanaged_retain_release_test : $@convention(thin) (@owned Builtin.NativeObject, @owned C) -> () {
bb0(%0 : @owned $Builtin.NativeObject, %1 : @owned $C):
  unmanaged_retain_value %0 : $Builtin.NativeObject
  unmanaged_autorelease_value %1 : $C
  br bb1

bb1:
  unmanaged_release_value %0 : $Builtin.NativeObject
  destroy_value %0 : $Builtin.NativeObject
  destroy_value %1 : $C
  %9999 = tuple()
  return %9999 : $()
}

// CHECK-LABEL: sil @checked_cast_br_lowered : $@convention(thin) (@owned Builtin.NativeObject) -> () {
// CHECK: bb0([[ARG:%.*]] : $Builtin.NativeObject):
// CHECK:   checked_cast_br Builtin.NativeObject in [[ARG]] : $Builtin.NativeObject to C, [[SUCCBB:bb[0-9]+]], [[FAILBB:bb[0-9]+]]
//
// CHECK: [[SUCCBB]]([[CASTED_VALUE:%.*]] : $C):
// CHECK-NEXT:   strong_release [[CASTED_VALUE]]
// CHECK-NEXT:   br bb3
//
// CHECK: [[FAILBB]]:
// CHECK-NEXT:   strong_release [[ARG]]
// CHECK-NEXT:   br bb3
sil [ossa] @checked_cast_br_lowered : $@convention(thin) (@owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject):
  checked_cast_br Builtin.NativeObject in %0 : $Builtin.NativeObject to C, bb1, bb2

bb1(%1 : @owned $C):
  destroy_value %1 : $C
  br bb3

bb2(%2 : @owned $Builtin.NativeObject):
  destroy_value %2 : $Builtin.NativeObject
  br bb3

bb3:
  %9999 = tuple()
  return %9999 : $()
}

// CHECK-LABEL: sil @end_lifetime_test : $@convention(thin) (@owned Builtin.NativeObject) -> () {
// CHECK-NOT: end_lifetime {{%.*}} : $Builtin.NativeObject
sil [ossa] @end_lifetime_test : $@convention(thin) (@owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject):
  end_lifetime %0 : $Builtin.NativeObject
  %9999 = tuple()
  return %9999 : $()
}

// CHECK-LABEL: sil @unchecked_ownership_conversion_test : $@convention(thin) (@guaranteed Builtin.NativeObject) -> @owned Builtin.NativeObject {
// CHECK: bb0([[ARG:%.*]] : $Builtin.NativeObject):
// CHECK: return [[ARG]] : $Builtin.NativeObject
sil [ossa] @unchecked_ownership_conversion_test : $@convention(thin) (@guaranteed Builtin.NativeObject) -> @owned Builtin.NativeObject {
bb0(%0 : @guaranteed $Builtin.NativeObject):
  %1 = unchecked_ownership_conversion %0 : $Builtin.NativeObject, @guaranteed to @owned
  return %1 : $Builtin.NativeObject
}

// CHECK-LABEL: sil @switch_enum_default_case : $@convention(thin) (@owned Either<Builtin.NativeObject, AnyObject>) -> () {
// CHECK: bb0([[ARG:%.*]] : $Either<Builtin.NativeObject, AnyObject>):
// CHECK:   switch_enum [[ARG]] : $Either<Builtin.NativeObject, AnyObject>, case #Either.left!enumelt: [[SUCC_BB:bb[0-9]+]], default [[DEFAULT_BB:bb[0-9]+]]
//
// CHECK: [[SUCC_BB]]([[LHS:%.*]] : $Builtin.NativeObject
// CHECK:   strong_release [[LHS]]
// CHECK:   br [[EPILOG_BB:bb[0-9]+]]
//
// CHECK: [[DEFAULT_BB]]:
// CHECK:   release_value [[ARG]]
// CHECK:   br [[EPILOG_BB]]
//
// CHECK: [[EPILOG_BB]]:
// CHECK:   return
// CHECK: } // end sil function 'switch_enum_default_case'
sil [ossa] @switch_enum_default_case : $@convention(thin) (@owned Either<Builtin.NativeObject, Builtin.AnyObject>) -> () {
bb0(%0 : @owned $Either<Builtin.NativeObject, Builtin.AnyObject>):
  switch_enum %0 : $Either<Builtin.NativeObject, Builtin.AnyObject>, case #Either.left!enumelt: bb1, default bb2

bb1(%1 : @owned $Builtin.NativeObject):
  destroy_value %1 : $Builtin.NativeObject
  br bb3

bb2(%2 : @owned $Builtin.AnyObject):
  destroy_value %2 : $Builtin.AnyObject
  br bb3

bb3:
  %9999 = tuple()
  return %9999 : $()
}

class TestArrayStorage {
  @_hasStorage var count: Builtin.Int32
  init()
}

struct TestArray {
  var storage : TestArrayStorage
}

struct TestArray2 {
  var storage : TestArrayStorage
  var someValue : Builtin.Int32
  var storage2 : TestArrayStorage
}

// CHECK-LABEL: sil @test_destructure_struct_tuple : $@convention(thin) (@owned (Builtin.NativeObject, Builtin.Int32), @owned TestArray2) -> @owned (Builtin.NativeObject, Builtin.Int32, TestArrayStorage, Builtin.Int32, TestArrayStorage) {
// CHECK: bb0([[TUPLE:%.*]] : $(Builtin.NativeObject, Builtin.Int32), [[STRUCT:%.*]] : $TestArray2):
// CHECK:   [[TUP_ELT_0:%.*]] = tuple_extract [[TUPLE]] : $(Builtin.NativeObject, Builtin.Int32), 0
// CHECK:   [[TUP_ELT_1:%.*]] = tuple_extract [[TUPLE]] : $(Builtin.NativeObject, Builtin.Int32), 1
// CHECK:   [[STRUCT_FIELD_0:%.*]] = struct_extract [[STRUCT]] : $TestArray2, #TestArray2.storage
// CHECK:   [[STRUCT_FIELD_1:%.*]] = struct_extract [[STRUCT]] : $TestArray2, #TestArray2.someValue
// CHECK:   [[STRUCT_FIELD_2:%.*]] = struct_extract [[STRUCT]] : $TestArray2, #TestArray2.storage2
// CHECK:   [[RESULT:%.*]] = tuple ([[TUP_ELT_0]] : {{.*}}, [[TUP_ELT_1]] : {{.*}}, [[STRUCT_FIELD_0]] : {{.*}}, [[STRUCT_FIELD_1]] : {{.*}}, [[STRUCT_FIELD_2]] : {{.*}})
// CHECK:   return [[RESULT]]
// CHECK: } // end sil function 'test_destructure_struct_tuple'
sil [ossa] @test_destructure_struct_tuple : $@convention(thin) (@owned (Builtin.NativeObject, Builtin.Int32), @owned TestArray2) -> @owned (Builtin.NativeObject, Builtin.Int32, TestArrayStorage, Builtin.Int32, TestArrayStorage) {
bb0(%0 : @owned $(Builtin.NativeObject, Builtin.Int32), %1 : @owned $TestArray2):
  (%2, %3) = destructure_tuple %0 : $(Builtin.NativeObject, Builtin.Int32)
  (%4, %5, %6) = destructure_struct %1 : $TestArray2
  %7 = tuple(%2 : $Builtin.NativeObject, %3 : $Builtin.Int32, %4 : $TestArrayStorage, %5 : $Builtin.Int32, %6 : $TestArrayStorage)
  return %7 : $(Builtin.NativeObject, Builtin.Int32, TestArrayStorage, Builtin.Int32, TestArrayStorage)
}

struct EmptyStruct {}

// We should completely eliminate the destructures here since the relevant
// aggregates are empty.
//
// CHECK-LABEL: sil @test_empty_destructure : $@convention(thin) () -> () {
// CHECK-NOT: destructure_struct
// CHECK-NOT: destructure_tuple
// CHECK: } // end sil function 'test_empty_destructure'
sil [ossa] @test_empty_destructure : $@convention(thin) () -> () {
bb0:
  %0 = struct $EmptyStruct()
  () = destructure_struct %0 : $EmptyStruct
  %1 = tuple()
  () = destructure_tuple %1 : $()
  return %1 : $()
}

// CHECK-LABEL: sil [canonical] @test_destructure_struct_tuple_canonical : $@convention(thin) (@owned (Builtin.NativeObject, Builtin.Int32), @owned TestArray2) -> @owned (Builtin.NativeObject, Builtin.Int32, TestArrayStorage, Builtin.Int32, TestArrayStorage) {
// CHECK: bb0([[TUPLE:%.*]] : $(Builtin.NativeObject, Builtin.Int32), [[STRUCT:%.*]] : $TestArray2):
// CHECK:   [[TUP_ELT_0:%.*]] = tuple_extract [[TUPLE]] : $(Builtin.NativeObject, Builtin.Int32), 0
// CHECK:   [[TUP_ELT_1:%.*]] = tuple_extract [[TUPLE]] : $(Builtin.NativeObject, Builtin.Int32), 1
// CHECK:   [[STRUCT_FIELD_0:%.*]] = struct_extract [[STRUCT]] : $TestArray2, #TestArray2.storage
// CHECK:   [[STRUCT_FIELD_1:%.*]] = struct_extract [[STRUCT]] : $TestArray2, #TestArray2.someValue
// CHECK:   [[STRUCT_FIELD_2:%.*]] = struct_extract [[STRUCT]] : $TestArray2, #TestArray2.storage2
// CHECK:   [[RESULT:%.*]] = tuple ([[TUP_ELT_0]] : {{.*}}, [[TUP_ELT_1]] : {{.*}}, [[STRUCT_FIELD_0]] : {{.*}}, [[STRUCT_FIELD_1]] : {{.*}}, [[STRUCT_FIELD_2]] : {{.*}})
// CHECK:   return [[RESULT]]
// CHECK: } // end sil function 'test_destructure_struct_tuple_canonical'
sil [canonical] [ossa] @test_destructure_struct_tuple_canonical : $@convention(thin) (@owned (Builtin.NativeObject, Builtin.Int32), @owned TestArray2) -> @owned (Builtin.NativeObject, Builtin.Int32, TestArrayStorage, Builtin.Int32, TestArrayStorage) {
bb0(%0 : @owned $(Builtin.NativeObject, Builtin.Int32), %1 : @owned $TestArray2):
  (%2, %3) = destructure_tuple %0 : $(Builtin.NativeObject, Builtin.Int32)
  (%4, %5, %6) = destructure_struct %1 : $TestArray2
  %7 = tuple(%2 : $Builtin.NativeObject, %3 : $Builtin.Int32, %4 : $TestArrayStorage, %5 : $Builtin.Int32, %6 : $TestArrayStorage)
  return %7 : $(Builtin.NativeObject, Builtin.Int32, TestArrayStorage, Builtin.Int32, TestArrayStorage)
}

// In the following test, the trivial parts do not have any actual uses... do
// not emit any value projections for them!
//
// CHECK-LABEL: sil [canonical] @test_destructure_with_only_some_uses : $@convention(thin) (@owned (Builtin.NativeObject, Builtin.Int32), @owned TestArray2) -> @owned (Builtin.NativeObject, TestArrayStorage, TestArrayStorage) {
// CHECK:    bb0([[ARG0:%.*]] : $(Builtin.NativeObject, Builtin.Int32), [[ARG1:%.*]] : $TestArray2):
// CHECK-NEXT:   [[ARG0_0:%.*]] = tuple_extract [[ARG0]]
// CHECK-NEXT:   [[STORAGE:%.*]] = struct_extract [[ARG1]] : $TestArray2, #TestArray2.storage
// CHECK-NEXT:   [[STORAGE2:%.*]] = struct_extract [[ARG1]] : $TestArray2, #TestArray2.storage2
// CHECK-NEXT:   [[RESULT:%.*]] = tuple ([[ARG0_0]] : ${{.*}}, [[STORAGE]] : ${{.*}}, [[STORAGE2]] : ${{.*}})
// CHECK-NEXT:   return [[RESULT]]
// CHECK: } // end sil function 'test_destructure_with_only_some_uses'
sil [canonical] [ossa] @test_destructure_with_only_some_uses : $@convention(thin) (@owned (Builtin.NativeObject, Builtin.Int32), @owned TestArray2) -> @owned (Builtin.NativeObject, TestArrayStorage, TestArrayStorage) {
bb0(%0 : @owned $(Builtin.NativeObject, Builtin.Int32), %1 : @owned $TestArray2):
  (%2, %3) = destructure_tuple %0 : $(Builtin.NativeObject, Builtin.Int32)
  (%4, %5, %6) = destructure_struct %1 : $TestArray2
  %7 = tuple (%2 : $Builtin.NativeObject, %4 : $TestArrayStorage, %6 : $TestArrayStorage)
  return %7 : $(Builtin.NativeObject, TestArrayStorage, TestArrayStorage)
}

// CHECK-LABEL: sil [canonical] @test_simplify_instruction : $@convention(thin) (@owned Builtin.NativeObject, Builtin.Int32) -> @owned Builtin.NativeObject {
// CHECK: bb0([[ARG:%.*]] : $Builtin.NativeObject,
// CHECK:   return [[ARG]]
// CHECK: } // end sil function 'test_simplify_instruction'
sil [canonical] [ossa] @test_simplify_instruction : $@convention(thin) (@owned Builtin.NativeObject, Builtin.Int32) -> @owned Builtin.NativeObject {
bb0(%0 : @owned $Builtin.NativeObject, %1 : $Builtin.Int32):
  %2 = tuple(%0 : $Builtin.NativeObject, %1 : $Builtin.Int32)
  (%3, %4) = destructure_tuple %2 : $(Builtin.NativeObject, Builtin.Int32)
  return %3 : $Builtin.NativeObject
}

// Just make sure that we do not crash on this function.
//
// CHECK-LABEL: sil @do_not_crash_due_to_debug_value_use : $@convention(thin) (Builtin.Int32, Builtin.Int32) -> () {
// CHECK: } // end sil function 'do_not_crash_due_to_debug_value_use'
sil [ossa] @do_not_crash_due_to_debug_value_use : $@convention(thin) (Builtin.Int32, Builtin.Int32) -> () {
bb0(%0a : $Builtin.Int32, %0b : $Builtin.Int32):
  %0 = tuple(%0a : $Builtin.Int32, %0b : $Builtin.Int32)
  (%1, %2) = destructure_tuple %0 : $(Builtin.Int32, Builtin.Int32)
  debug_value %0 : $(Builtin.Int32, Builtin.Int32), let, name "myName2"
  %9999 = tuple()
  return %9999 : $()
}

// Just make sure that we do not crash on this function.
//
// CHECK-LABEL: sil @lower_unchecked_value_cast_to_unchecked_bitwise_cast : $@convention(thin) (PairOfInt) -> Builtin.Int64 {
// CHECK: unchecked_bitwise_cast
// CHECK: } // end sil function 'lower_unchecked_value_cast_to_unchecked_bitwise_cast'
sil [ossa] @lower_unchecked_value_cast_to_unchecked_bitwise_cast : $@convention(thin) (PairOfInt) -> Builtin.Int64 {
bb0(%0a : $PairOfInt):
  %0b = unchecked_value_cast %0a : $PairOfInt to $Builtin.Int64
  return %0b : $Builtin.Int64
}

// Make sure we RAUW the store_borrow's result with its dest while lowering.
//
// CHECK-LABEL: sil @lower_store_borrow_result_correctly : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
// CHECK: bb0([[ARG:%.*]] :
// CHECK:   [[STACK:%.*]] = alloc_stack
// CHECK:   store [[ARG]] to [[STACK]]
// CHECK:   apply {{%.*}}([[STACK]])
// CHECK: } // end sil function 'lower_store_borrow_result_correctly'
sil [ossa] @lower_store_borrow_result_correctly : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
bb0(%0 : @guaranteed $Builtin.NativeObject):
  // This is materializing %0 into memory to be passed as an in_guaranteed arg.
  %1 = alloc_stack $Builtin.NativeObject
  %result = store_borrow %0 to %1 : $*Builtin.NativeObject
  %f = function_ref @use_native_object_inguaranteed : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> ()
  apply %f(%result) : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> ()
  end_borrow %result : $*Builtin.NativeObject
  dealloc_stack %1 : $*Builtin.NativeObject
  %9999 = tuple()
  return %9999 : $()
}

// CHECK-LABEL: sil @lower_explicit_copy_addr : $@convention(thin) (@in_guaranteed C) -> () {
// CHECK: {{[^_]copy_addr}}
// CHECK: } // end sil function 'lower_explicit_copy_addr'
sil [ossa] @lower_explicit_copy_addr : $@convention(thin) (@in_guaranteed C) -> () {
bb0(%0 : $*C):
  %1 = alloc_stack $C
  explicit_copy_addr %0 to [init] %1 : $*C
  destroy_addr %1 : $*C
  dealloc_stack %1 : $*C
  %9999 = tuple()
  return %9999 : $()
}

sil @closure1: $@convention(thin) (@guaranteed C, @inout_aliasable C) -> ()
sil @closure2 : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> ()) -> ()

// Ensure no assertion about missing dealloc_stack for partial_apply [on_stack] after OME
sil [ossa] @test_partial_apply_on_stack: $@convention(thin) (@guaranteed C, @inout C) -> () {
bb0(%0 : @guaranteed $C, %1 : $*C):
  %f1 = function_ref @closure1: $@convention(thin) (@guaranteed C, @inout_aliasable C) -> ()
  %pa1 = partial_apply [callee_guaranteed] [on_stack] %f1(%0, %1) : $@convention(thin) (@guaranteed C, @inout_aliasable C) -> ()
  %md = mark_dependence %pa1 : $@noescape @callee_guaranteed () -> () on %1 : $*C
  %f2 = function_ref @closure2 : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> ()) -> ()
  %pa2 = partial_apply [callee_guaranteed] %f2(%md) : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> ()) -> ()
  destroy_value %pa2 : $@callee_guaranteed () -> ()
  %t = tuple ()
  return %t : $()
}