Skip to content

Commit df72b54

Browse files
committed
Fix SILCombine of existential applies
1 parent 0b6ab9a commit df72b54

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,11 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
11991199
concreteArgCopies.push_back(*argSub);
12001200
NewArgs.push_back(argSub->tempArg);
12011201
} else {
1202-
NewArgs.push_back(CEI.ConcreteValue);
1202+
SILValue argValue = CEI.ConcreteValue;
1203+
if (argValue->getOwnershipKind() == OwnershipKind::Owned) {
1204+
argValue = makeCopiedValueAvailable(argValue, Apply->getParent());
1205+
}
1206+
NewArgs.push_back(argValue);
12031207
}
12041208

12051209
// Form a new set of substitutions where the argument is

test/SILOptimizer/sil_combine_ossa.sil

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,7 +2855,21 @@ bb0(%0 : @owned $Klass):
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 :
2863+
// CHECK: apply {{.*}}<Klass>
2864+
// CHECK: } // end sil function 'collapse_existential_pack_unpack_unchecked_ref_cast_owned4'
2865+
sil [ossa] @collapse_existential_pack_unpack_unchecked_ref_cast_owned4 : $@convention(thin) (@owned Klass) -> @owned Builtin.NativeObject {
2866+
bb0(%0 : @owned $Klass):
2867+
%1 = init_existential_ref %0 : $Klass : $Klass, $AnyObject
2868+
%f1 = function_ref @use_anyobject_guaranteed : $@convention(thin) (@guaranteed AnyObject) -> ()
2869+
apply %f1(%1) : $@convention(thin) (@guaranteed AnyObject) -> ()
2870+
%2 = open_existential_ref %1 : $AnyObject to $@opened("7CAE06CE-5F10-11E4-AF13-C82A1428F987", AnyObject) Self
2871+
%f2 = function_ref @use_generic_obj_guaranteed : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
2872+
apply %f2<@opened("7CAE06CE-5F10-11E4-AF13-C82A1428F987", AnyObject) Self>(%2) : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
28592873
%3 = unchecked_ref_cast %2 : $@opened("7CAE06CE-5F10-11E4-AF13-C82A1428F987", AnyObject) Self to $Builtin.NativeObject
28602874
return %3 : $Builtin.NativeObject
28612875
}

0 commit comments

Comments
 (0)