@@ -716,6 +716,74 @@ bad(%15 : @owned $Error):
716716 throw %15 : $Error
717717}
718718
719+ // CHECK-LABEL: sil [ossa] @dont_hoist_over_try_apply_barrier : {{.*}} {
720+ // CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] : @owned $C):
721+ // CHECK: [[LIFETIME:%[^,]+]] = begin_borrow [[INSTANCE]]
722+ // CHECK: try_apply undef() : {{.*}}, normal [[GOOD:bb[0-9]+]], error [[BAD:bb[0-9]+]]
723+ // CHECK: [[GOOD]]([[REGISTER_3:%[^,]+]] : $()):
724+ // CHECK: end_borrow [[LIFETIME]]
725+ // CHECK: destroy_value [[INSTANCE]]
726+ // CHECK: [[BAD]]([[ERROR:%[^,]+]] : @owned $Error):
727+ // CHECK: end_borrow [[LIFETIME]]
728+ // CHECK: destroy_value [[INSTANCE]]
729+ // CHECK: throw [[ERROR]]
730+ // CHECK-LABEL: } // end sil function 'dont_hoist_over_try_apply_barrier'
731+ sil [ossa] @dont_hoist_over_try_apply_barrier : $@convention(thin) (@owned C) -> @error Error {
732+ bb0(%instance : @owned $C):
733+ %lifetime = begin_borrow %instance : $C
734+ %_ = apply undef(%lifetime) : $@convention(thin) (@guaranteed C) -> ()
735+ try_apply undef() : $@convention(thin) () -> @error Error, normal good, error bad
736+
737+ good(%8 : $()):
738+ end_borrow %lifetime : $C
739+ destroy_value %instance : $C
740+ %13 = tuple ()
741+ return %13 : $()
742+
743+ bad(%15 : @owned $Error):
744+ end_borrow %lifetime : $C
745+ destroy_value %instance : $C
746+ throw %15 : $Error
747+ }
748+
749+ // Hoist up to two parallel barrier applies from a block with two predecessors.
750+ //
751+ // CHECK-LABEL: sil [ossa] @hoist_up_to_two_barrier_applies : $@convention(thin) (@owned C) -> () {
752+ // CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] : @owned $C):
753+ // CHECK: [[LIFETIME:%[^,]+]] = begin_borrow [lexical] [[INSTANCE]]
754+ // CHECK: cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
755+ // CHECK: [[LEFT]]:
756+ // CHECK: [[REGISTER_3:%[^,]+]] = apply undef()
757+ // CHECK: end_borrow [[LIFETIME]]
758+ // CHECK: br [[EXIT:bb[0-9]+]]
759+ // CHECK: [[RIGHT]]:
760+ // CHECK: [[REGISTER_6:%[^,]+]] = apply undef()
761+ // CHECK: end_borrow [[LIFETIME]]
762+ // CHECK: br [[EXIT]]
763+ // CHECK: [[EXIT]]:
764+ // CHECK: destroy_value [[INSTANCE]]
765+ // CHECK-LABEL: } // end sil function 'hoist_up_to_two_barrier_applies'
766+ sil [ossa] @hoist_up_to_two_barrier_applies : $@convention(thin) (@owned C) -> () {
767+ entry(%instance : @owned $C):
768+ %lifetime = begin_borrow [lexical] %instance : $C
769+ %_ = apply undef(%lifetime) : $@convention(thin) (@guaranteed C) -> ()
770+ cond_br undef, left, right
771+
772+ left:
773+ %result_left = apply undef() : $@convention(thin) () -> ()
774+ br exit
775+
776+ right:
777+ %result_right = apply undef() : $@convention(thin) () -> ()
778+ br exit
779+
780+ exit:
781+ end_borrow %lifetime : $C
782+ destroy_value %instance : $C
783+ %retval = tuple ()
784+ return %retval : $()
785+ }
786+
719787// =============================================================================
720788// instruction tests }}
721789// =============================================================================
0 commit comments