Skip to content

Commit 68cf6a7

Browse files
committed
Add unit tests containing guaranteed forwarding phis for LexicalDestroyHoisting
1 parent dd266f1 commit 68cf6a7

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

test/SILOptimizer/lexical_destroy_hoisting.sil

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ sil [ossa] @callee_optional_d_guaranteed: $@convention(thin) (@guaranteed Option
3636
sil [ossa] @synchronization_point : $@convention(thin) () -> ()
3737
sil [ossa] @modify_s : $@yield_once @convention(thin) () -> @yields @inout S
3838
sil [ossa] @barrier : $@convention(thin) () -> ()
39+
sil @use_C : $@convention(thin) (@guaranteed C) -> ()
40+
sil @use_CDCase : $@convention(thin) (@guaranteed CDCase) -> ()
41+
sil @empty : $@convention(thin) () -> ()
3942

4043

4144
// =============================================================================
@@ -536,6 +539,65 @@ exit:
536539
return %retval : $()
537540
}
538541

542+
// CHECK-LABEL: sil [ossa] @hoist_guaranteedforwardingphi1 :
543+
// bb1:
544+
// end_borrow
545+
// destroy_value
546+
// br bb2
547+
// CHECK-LABEL: } // end sil function 'hoist_guaranteedforwardingphi1'
548+
sil [ossa] @hoist_guaranteedforwardingphi1 : $@convention(thin) (@owned CDCase) -> () {
549+
bb0(%instance_c : @owned $CDCase):
550+
%lifetime_c_0 = begin_borrow %instance_c : $CDCase
551+
%ex = struct_extract %lifetime_c_0 : $CDCase, #CDCase.c
552+
br bb1(%ex : $C)
553+
554+
bb1(%phi1 : @guaranteed $C):
555+
%f1 = function_ref @use_C : $@convention(thin) (@guaranteed C) -> ()
556+
apply %f1(%phi1) : $@convention(thin) (@guaranteed C) -> ()
557+
br bb2
558+
559+
bb2:
560+
end_borrow %lifetime_c_0 : $CDCase
561+
destroy_value %instance_c : $CDCase
562+
%retval = tuple ()
563+
return %retval : $()
564+
}
565+
566+
// CHECK-LABEL: sil [ossa] @nohoist_guaranteedforwardingphi2 :
567+
// CHECK: bb3({{.*}}):
568+
// CHECK: end_borrow
569+
// CHECK: destroy_value
570+
// CHECK-LABEL: } // end sil function 'nohoist_guaranteedforwardingphi2'
571+
sil [ossa] @nohoist_guaranteedforwardingphi2 : $@convention(thin) (@owned CDCase, @owned CDCase) -> () {
572+
bb0(%instance_c1 : @owned $CDCase, %instance_c2 : @owned $CDCase):
573+
cond_br undef, bb1, bb2
574+
575+
bb1:
576+
destroy_value %instance_c2 : $CDCase
577+
%lifetime_c_1 = begin_borrow %instance_c1 : $CDCase
578+
%ex1 = struct_extract %lifetime_c_1 : $CDCase, #CDCase.c
579+
br bb3(%ex1 : $C, %lifetime_c_1 : $CDCase, %instance_c1 : $CDCase)
580+
581+
bb2:
582+
destroy_value %instance_c1 : $CDCase
583+
%lifetime_c_2 = begin_borrow %instance_c2 : $CDCase
584+
%ex2 = struct_extract %lifetime_c_2 : $CDCase, #CDCase.c
585+
br bb3(%ex2 : $C, %lifetime_c_2 : $CDCase, %instance_c2 : $CDCase)
586+
587+
bb3(%phi1 : @guaranteed $C, %phi2 : @guaranteed $CDCase, %phi3 : @owned $CDCase):
588+
%f1 = function_ref @use_C : $@convention(thin) (@guaranteed C) -> ()
589+
apply %f1(%phi1) : $@convention(thin) (@guaranteed C) -> ()
590+
%f2 = function_ref @empty : $@convention(thin) () -> ()
591+
apply %f2() : $@convention(thin) () -> ()
592+
br bb4
593+
594+
bb4:
595+
end_borrow %phi2 : $CDCase
596+
destroy_value %phi3 : $CDCase
597+
%retval = tuple ()
598+
return %retval : $()
599+
}
600+
539601
// =============================================================================
540602
// access scope tests }}
541603
// =============================================================================

0 commit comments

Comments
 (0)