@@ -255,6 +255,21 @@ entry(%instance : @none $TrivialStruct):
255
255
return %retval : $()
256
256
}
257
257
258
+ // CHECK-LABEL: sil [ossa] @nohoist_inout_aliasable : {{.*}} {
259
+ // CHECK: apply
260
+ // CHECK: destroy_addr
261
+ // CHECK-LABEL: } // end sil function 'nohoist_inout_aliasable'
262
+ sil [ossa] @nohoist_inout_aliasable : $@convention(thin) (@inout_aliasable X) -> () {
263
+ entry(%addr : $*X):
264
+ %value = load [copy] %addr : $*X
265
+ %unknown = function_ref @unknown : $@convention(thin) () -> ()
266
+ apply %unknown() : $@convention(thin) () -> ()
267
+ destroy_addr %addr : $*X
268
+ store %value to [init] %addr : $*X
269
+ %tuple = tuple ()
270
+ return %tuple : $()
271
+ }
272
+
258
273
// Fold destroy_addr and a load [copy] into a load [take] even when that
259
274
// load [take] is guarded by an access scope.
260
275
//
@@ -398,3 +413,31 @@ entry(%instance : @owned $X):
398
413
399
414
return %loaded : $X
400
415
}
416
+
417
+ // Don't fold a destroy_addr with a load [copy] that occurs within the scope of
418
+ // an access to unrelated storage.
419
+ //
420
+ // CHECK-LABEL: sil [ossa] @nofold_into_unrelated_barrier_scope : {{.*}} {
421
+ // CHECK: load [copy]
422
+ // CHECK-LABEL: } // end sil function 'nofold_into_unrelated_barrier_scope'
423
+ sil [ossa] @nofold_into_unrelated_barrier_scope : $@convention(thin) (@owned X) -> (@owned X) {
424
+ entry(%instance : @owned $X):
425
+ %copy = copy_value %instance : $X
426
+ %addr_outer = alloc_stack $X
427
+ %addr_inner = alloc_stack $X
428
+ store %copy to [init] %addr_outer : $*X
429
+ store %instance to [init] %addr_inner : $*X
430
+
431
+ %access = begin_access [modify] [static] %addr_outer : $*X
432
+ apply undef(%access) : $@convention(thin) (@inout X) -> ()
433
+ %unknown = function_ref @unknown : $@convention(thin) () -> ()
434
+ destroy_addr %access : $*X
435
+ apply %unknown() : $@convention(thin) () -> ()
436
+ %value = load [copy] %addr_inner : $*X
437
+ end_access %access : $*X
438
+ destroy_addr %addr_inner : $*X
439
+
440
+ dealloc_stack %addr_inner : $*X
441
+ dealloc_stack %addr_outer : $*X
442
+ return %value : $X
443
+ }
0 commit comments