Skip to content

Commit e4c263c

Browse files
committed
Don't use previously found owned concrete values in OSSA.
1 parent c3bd7f6 commit e4c263c

File tree

3 files changed

+26
-146
lines changed

3 files changed

+26
-146
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,12 @@ SILCombiner::buildConcreteOpenedExistentialInfoFromSoleConformingType(
789789
ConcreteExistentialInfo &SoleCEI = *COAI.CEI;
790790
assert(SoleCEI.isValid());
791791

792-
if (SoleCEI.ConcreteValue)
792+
// In ossa, don not use the concrete value previously found as it maybe
793+
// forward consumed and not available at the apply using the opened
794+
// existential.
795+
if (SoleCEI.ConcreteValue &&
796+
(!F->hasOwnership() ||
797+
SoleCEI.ConcreteValue->getOwnershipKind() != OwnershipKind::Owned))
793798
return COAI;
794799

795800
// Create SIL type for the concrete type.

test/SILOptimizer/sil_combine_concrete_existential_ossa.swift

Lines changed: 0 additions & 140 deletions
This file was deleted.

test/SILOptimizer/sil_combine_ossa.sil

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2845,17 +2845,32 @@ bb0(%0 : @owned $Klass):
28452845
return %3 : $Builtin.NativeObject
28462846
}
28472847

2848-
// CHECK-LABEL: sil [ossa] @collapse_existential_pack_unpack_unchecked_ref_cast_owned3 :
2849-
// CHECK-NOT: init_existential_ref
2850-
// CHECK-NOT: open_existential_ref
2851-
// CHECK: } // end sil function 'collapse_existential_pack_unpack_unchecked_ref_cast_owned3'
2852-
sil [ossa] @collapse_existential_pack_unpack_unchecked_ref_cast_owned3 : $@convention(thin) (@owned Klass) -> @owned Builtin.NativeObject {
2848+
// CHECK-LABEL: sil [ossa] @collapse_existential_pack_unpack_unchecked_ref_cast_owned3_fail :
2849+
// CHECK: init_existential_ref
2850+
// CHECK: open_existential_ref
2851+
// CHECK: } // end sil function 'collapse_existential_pack_unpack_unchecked_ref_cast_owned3_fail'
2852+
sil [ossa] @collapse_existential_pack_unpack_unchecked_ref_cast_owned3_fail : $@convention(thin) (@owned Klass) -> @owned Builtin.NativeObject {
28532853
bb0(%0 : @owned $Klass):
28542854
%1 = init_existential_ref %0 : $Klass : $Klass, $AnyObject
28552855
%2 = open_existential_ref %1 : $AnyObject to $@opened("7CAE06CE-5F10-11E4-AF13-C82A1428F987", AnyObject) Self
28562856
%f = function_ref @use_generic_obj_guaranteed : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
28572857
apply %f<@opened("7CAE06CE-5F10-11E4-AF13-C82A1428F987", AnyObject) Self>(%2) : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
2858+
%3 = unchecked_ref_cast %2 : $@opened("7CAE06CE-5F10-11E4-AF13-C82A1428F987", AnyObject) Self to $Builtin.NativeObject
2859+
return %3 : $Builtin.NativeObject
2860+
}
28582861

2862+
// CHECK-LABEL: sil [ossa] @collapse_existential_pack_unpack_unchecked_ref_cast_owned4_fail :
2863+
// CHECK: init_existential_ref
2864+
// CHECK: open_existential_ref
2865+
// CHECK: } // end sil function 'collapse_existential_pack_unpack_unchecked_ref_cast_owned4_fail'
2866+
sil [ossa] @collapse_existential_pack_unpack_unchecked_ref_cast_owned4_fail : $@convention(thin) (@owned Klass) -> @owned Builtin.NativeObject {
2867+
bb0(%0 : @owned $Klass):
2868+
%1 = init_existential_ref %0 : $Klass : $Klass, $AnyObject
2869+
%f1 = function_ref @use_anyobject_guaranteed : $@convention(thin) (@guaranteed AnyObject) -> ()
2870+
apply %f1(%1) : $@convention(thin) (@guaranteed AnyObject) -> ()
2871+
%2 = open_existential_ref %1 : $AnyObject to $@opened("7CAE06CE-5F10-11E4-AF13-C82A1428F987", AnyObject) Self
2872+
%f2 = function_ref @use_generic_obj_guaranteed : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
2873+
apply %f2<@opened("7CAE06CE-5F10-11E4-AF13-C82A1428F987", AnyObject) Self>(%2) : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
28592874
%3 = unchecked_ref_cast %2 : $@opened("7CAE06CE-5F10-11E4-AF13-C82A1428F987", AnyObject) Self to $Builtin.NativeObject
28602875
return %3 : $Builtin.NativeObject
28612876
}

0 commit comments

Comments
 (0)