Skip to content

Commit 3761ee3

Browse files
committed
Remove a transformation introduced in PR13652 which fails on the iOS
simulator in a way I can't repro. Reimplement the important part of it in a new way to achieve the same effect.
1 parent 1e63108 commit 3761ee3

File tree

3 files changed

+25
-46
lines changed

3 files changed

+25
-46
lines changed

lib/SILOptimizer/SILCombiner/SILCombiner.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ class SILCombiner :
242242
SILInstruction *visitEnumInst(EnumInst *EI);
243243

244244
SILInstruction *visitMarkDependenceInst(MarkDependenceInst *MDI);
245-
SILInstruction *visitInitExistentialRefInst(InitExistentialRefInst *IER);
246245
SILInstruction *visitConvertFunctionInst(ConvertFunctionInst *CFI);
247246

248247
/// Instruction visitor helpers.

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,40 +1437,16 @@ SILInstruction *SILCombiner::visitMarkDependenceInst(MarkDependenceInst *MDI) {
14371437
eraseInstFromFunction(*ier);
14381438
return MDI;
14391439
}
1440-
1441-
return nullptr;
1442-
}
14431440

1444-
1445-
SILInstruction *SILCombiner::
1446-
visitInitExistentialRefInst(InitExistentialRefInst *IER) {
1447-
// Arrays in particular end up with chains of init/open existential refs,
1448-
// which convert back and forth between a class reference and an existential
1449-
// reference e.g. like this:
1450-
//
1451-
// %a = init_existential_ref %x : $_ContiguousArrayStorageBase :
1452-
// $_ContiguousArrayStorageBase, $_NSArrayCore
1453-
// %b = open_existential_ref %a : $_NSArrayCore to
1454-
// $@opened("EA85...") _NSArrayCore
1455-
//
1456-
// %c = init_existential_ref %b : $@opened("EA85...") _NSArrayCore :
1457-
// $@opened("EA85...") _NSArrayCore, $AnyObject
1458-
// we can simplify this by having %c initialize itself from the %x reference
1459-
// directly.
1460-
if (auto *ORE = dyn_cast<OpenExistentialRefInst>(IER->getOperand())) {
1461-
if (auto *IER2 = dyn_cast<InitExistentialRefInst>(ORE->getOperand())) {
1462-
1463-
// We create a new instruction, instead of modifying the existing one
1464-
// in place, because we need the result type of "%c" but the operand list
1465-
// of "%a", and the number of dependent types could disagree.
1466-
return Builder.createInitExistentialRef(IER->getLoc(), IER->getType(),
1467-
IER->getFormalConcreteType(),
1468-
IER2->getOperand(),
1469-
IER->getConformances());
1470-
1471-
}
1441+
// Conversions from a class to AnyObject also happen a lot, we can just depend
1442+
// on the class reference.
1443+
if (auto oeri = dyn_cast<OpenExistentialRefInst>(MDI->getBase())) {
1444+
MDI->setBase(oeri->getOperand());
1445+
if (oeri->use_empty())
1446+
eraseInstFromFunction(*oeri);
1447+
return MDI;
14721448
}
1473-
1449+
14741450
return nullptr;
14751451
}
14761452

test/SILOptimizer/sil_combine.sil

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,19 +2083,6 @@ bb0(%0 : $B, %1 : $@sil_unowned B, %2 : $AnyObject, %3: $@sil_unmanaged AnyObjec
20832083
return %9999 : $(B, @sil_unowned B, AnyObject, @sil_unmanaged AnyObject)
20842084
}
20852085

2086-
// CHECK-LABEL: sil @collapse_init_open_init_ref_cast
2087-
// CHECK: bb0([[Ref:%.*]]: $MyClass):
2088-
// CHECK-NEXT: init_existential_ref
2089-
// CHECK-NEXT: return
2090-
sil @collapse_init_open_init_ref_cast : $@convention(thin) (MyClass) -> (AnyObject) {
2091-
bb0(%0: $MyClass):
2092-
%1 = init_existential_ref %0 : $MyClass : $MyClass, $AnyObject
2093-
%2 = open_existential_ref %1 : $AnyObject to $@opened("2CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject
2094-
%3 = init_existential_ref %2 : $@opened("2CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject : $@opened("2CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject, $AnyObject
2095-
return %3 : $AnyObject
2096-
}
2097-
2098-
20992086
// CHECK-LABEL: sil @collapse_existential_pack_unpack_unchecked_ref_cast
21002087
// CHECK: bb0([[Ref:%.*]]: $MyClass):
21012088
// CHECK-NOT: init_existential_ref
@@ -3459,5 +3446,22 @@ bb0(%0 : $*Builtin.Int64, %1 : $B):
34593446
return %4 : $Builtin.Int64
34603447
}
34613448

3449+
// CHECK-LABEL: sil @mark_dependence_base2
3450+
// CHECK: bb0(
3451+
// CHECK-NOT: open_existential_ref
3452+
// CHECK-NOT: enum
3453+
// CHECK-NEXT: mark_dependence
3454+
// CHECK-NEXT: load
3455+
// CHECK: return
3456+
sil @mark_dependence_base2 : $@convention(thin) (@inout Builtin.Int64, @owned B) -> Builtin.Int64 {
3457+
bb0(%0 : $*Builtin.Int64, %1 : $B):
3458+
%2 = init_existential_ref %1 : $B : $B, $AnyObject
3459+
%3 = open_existential_ref %2 : $AnyObject to $@opened("B674783A-EF08-11E7-97D6-8C85900CB088") _NSArrayCore
3460+
%5 = mark_dependence %0 : $*Builtin.Int64 on %3 : $@opened("B674783A-EF08-11E7-97D6-8C85900CB088") _NSArrayCore
3461+
3462+
%4 = load %5 : $*Builtin.Int64
3463+
return %4 : $Builtin.Int64
3464+
}
3465+
34623466

34633467

0 commit comments

Comments
 (0)