Skip to content

Commit d11680f

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents b6afd21 + 2282160 commit d11680f

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,9 @@ BorrowedValue swift::getSingleBorrowIntroducingValue(SILValue inputValue) {
948948
return scopeIntroducer;
949949
}
950950

951+
if (currentValue.getOwnershipKind() == OwnershipKind::None)
952+
return {};
953+
951954
// Otherwise if v is an ownership forwarding value, add its defining
952955
// instruction
953956
if (isForwardingBorrow(currentValue)) {

test/SILOptimizer/cse_ossa_nontrivial.sil

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public enum FakeOptional2 {
2525
case some2(Klass)
2626
}
2727

28+
public enum FakeOptional3 {
29+
case none
30+
case some(WrapperStruct)
31+
}
32+
2833
struct StructWithEnum {
2934
var val:FakeOptional
3035
}
@@ -35,6 +40,7 @@ struct StructWithEnum2 {
3540

3641
sil @use_nontrivialstruct1 : $@convention(thin) (@guaranteed NonTrivialStruct) -> ()
3742
sil @use_nontrivialstruct2 : $@convention(thin) (@owned NonTrivialStruct) -> ()
43+
sil @use_nontrivialstruct3 : $@convention(thin) (@in_guaranteed NonTrivialStruct) -> ()
3844
sil @use_superklass1 : $@convention(thin) (@owned SuperKlass) -> ()
3945

4046
// CHECK-LABEL: sil [ossa] @structliteral1 :
@@ -893,3 +899,36 @@ bb0(%0 : @guaranteed $TestKlass):
893899
%18 = tuple ()
894900
return %18 : $()
895901
}
902+
903+
904+
struct WrapperStruct {
905+
var val: TestKlass
906+
}
907+
908+
// CHECK-LABEL: sil [ossa] @cse_ossa_utilstest :
909+
// CHECK: ref_element_addr
910+
// CHECK: ref_element_addr
911+
// CHECK-LABEL: } // end sil function 'cse_ossa_utilstest'
912+
sil [ossa] @cse_ossa_utilstest : $@convention(thin) (@guaranteed WrapperStruct) -> () {
913+
bb0(%0 : @guaranteed $WrapperStruct):
914+
%f = function_ref @use_nontrivialstruct3 : $@convention(thin) (@in_guaranteed NonTrivialStruct) -> ()
915+
%none = enum $FakeOptional3, #FakeOptional3.none
916+
switch_enum %none : $FakeOptional3, case #FakeOptional3.some!enumelt:bb1, case #FakeOptional3.none!enumelt:bb2
917+
918+
bb1(%arg : @guaranteed $WrapperStruct):
919+
%ex = struct_extract %arg : $WrapperStruct, #WrapperStruct.val
920+
%1 = ref_element_addr %ex : $TestKlass, #TestKlass.testStruct
921+
apply %f (%1) : $@convention(thin) (@in_guaranteed NonTrivialStruct) -> ()
922+
%2 = ref_element_addr %ex : $TestKlass, #TestKlass.testStruct
923+
apply %f (%2) : $@convention(thin) (@in_guaranteed NonTrivialStruct) -> ()
924+
br bb3
925+
926+
bb2:
927+
br bb3
928+
929+
bb3:
930+
%res = tuple ()
931+
return %res : $()
932+
}
933+
934+

0 commit comments

Comments
 (0)