@@ -18,7 +18,13 @@ enum Numerals {
1818 case Four
1919}
2020
21+ enum E2 {
22+ case int(Int)
23+ case str(String)
24+ }
25+
2126sil [ossa] @external_func: $@convention(thin) () -> ()
27+ sil @useit : $@convention(thin) (@owned E2) -> ()
2228
2329// CHECK-LABEL: sil [ossa] @eliminate_sw_enum_addr : $@convention(thin) () -> Int {
2430// CHECK-NOT: switch_enum_addr
@@ -679,3 +685,33 @@ bb0(%0 : $*Optional<NC>):
679685 return %1 : $Optional<NC>
680686}
681687
688+ // CHECK-LABEL: sil [ossa] @trivial_replacement
689+ // CHECK: bb1({{.*}}:
690+ // CHECK-NEXT: end_borrow
691+ // CHECK-NEXT: destroy_value %2
692+ // CHECK: apply {{%[0-9]+}}(%1)
693+ // CHECK: } // end sil function 'trivial_replacement'
694+ sil [ossa] @trivial_replacement : $@convention(thin) (Int) -> () {
695+ bb0(%0 : $Int):
696+ %1 = enum $E2, #E2.int!enumelt, %0 : $Int
697+ %2 = enum $Optional<E2>, #Optional.some!enumelt, %1 : $E2, forwarding: @owned
698+ %3 = begin_borrow %2 : $Optional<E2>
699+ switch_enum %3 : $Optional<E2>, case #Optional.some!enumelt: bb1, case #Optional.none!enumelt: bb2
700+
701+ bb1(%5 : @guaranteed $E2):
702+ end_borrow %3 : $Optional<E2>
703+ %7 = unchecked_enum_data %2 : $Optional<E2>, #Optional.some!enumelt
704+ %8 = function_ref @useit : $@convention(thin) (@owned E2) -> ()
705+ %9 = apply %8(%7) : $@convention(thin) (@owned E2) -> ()
706+ br bb3
707+
708+ bb2:
709+ end_borrow %3 : $Optional<E2>
710+ destroy_value %2 : $Optional<E2>
711+ br bb3
712+
713+ bb3:
714+ %r = tuple ()
715+ return %r : $()
716+ }
717+
0 commit comments