Skip to content

Speculative fix for a regression on the iOS simulator bot. #13656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/SILOptimizer/SILCombiner/SILCombiner.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ class SILCombiner :
SILInstruction *visitEnumInst(EnumInst *EI);

SILInstruction *visitMarkDependenceInst(MarkDependenceInst *MDI);
SILInstruction *visitInitExistentialRefInst(InitExistentialRefInst *IER);
SILInstruction *visitConvertFunctionInst(ConvertFunctionInst *CFI);

/// Instruction visitor helpers.
Expand Down
40 changes: 8 additions & 32 deletions lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1437,40 +1437,16 @@ SILInstruction *SILCombiner::visitMarkDependenceInst(MarkDependenceInst *MDI) {
eraseInstFromFunction(*ier);
return MDI;
}

return nullptr;
}


SILInstruction *SILCombiner::
visitInitExistentialRefInst(InitExistentialRefInst *IER) {
// Arrays in particular end up with chains of init/open existential refs,
// which convert back and forth between a class reference and an existential
// reference e.g. like this:
//
// %a = init_existential_ref %x : $_ContiguousArrayStorageBase :
// $_ContiguousArrayStorageBase, $_NSArrayCore
// %b = open_existential_ref %a : $_NSArrayCore to
// $@opened("EA85...") _NSArrayCore
//
// %c = init_existential_ref %b : $@opened("EA85...") _NSArrayCore :
// $@opened("EA85...") _NSArrayCore, $AnyObject
// we can simplify this by having %c initialize itself from the %x reference
// directly.
if (auto *ORE = dyn_cast<OpenExistentialRefInst>(IER->getOperand())) {
if (auto *IER2 = dyn_cast<InitExistentialRefInst>(ORE->getOperand())) {

// We create a new instruction, instead of modifying the existing one
// in place, because we need the result type of "%c" but the operand list
// of "%a", and the number of dependent types could disagree.
return Builder.createInitExistentialRef(IER->getLoc(), IER->getType(),
IER2->getFormalConcreteType(),
IER2->getOperand(),
IER->getConformances());

}
// Conversions from a class to AnyObject also happen a lot, we can just depend
// on the class reference.
if (auto oeri = dyn_cast<OpenExistentialRefInst>(MDI->getBase())) {
MDI->setBase(oeri->getOperand());
if (oeri->use_empty())
eraseInstFromFunction(*oeri);
return MDI;
}

return nullptr;
}

Expand Down
30 changes: 17 additions & 13 deletions test/SILOptimizer/sil_combine.sil
Original file line number Diff line number Diff line change
Expand Up @@ -2083,19 +2083,6 @@ bb0(%0 : $B, %1 : $@sil_unowned B, %2 : $AnyObject, %3: $@sil_unmanaged AnyObjec
return %9999 : $(B, @sil_unowned B, AnyObject, @sil_unmanaged AnyObject)
}

// CHECK-LABEL: sil @collapse_init_open_init_ref_cast
// CHECK: bb0([[Ref:%.*]]: $MyClass):
// CHECK-NEXT: init_existential_ref
// CHECK-NEXT: return
sil @collapse_init_open_init_ref_cast : $@convention(thin) (MyClass) -> (AnyObject) {
bb0(%0: $MyClass):
%1 = init_existential_ref %0 : $MyClass : $MyClass, $AnyObject
%2 = open_existential_ref %1 : $AnyObject to $@opened("2CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject
%3 = init_existential_ref %2 : $@opened("2CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject : $@opened("2CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject, $AnyObject
return %3 : $AnyObject
}


// CHECK-LABEL: sil @collapse_existential_pack_unpack_unchecked_ref_cast
// CHECK: bb0([[Ref:%.*]]: $MyClass):
// CHECK-NOT: init_existential_ref
Expand Down Expand Up @@ -3459,5 +3446,22 @@ bb0(%0 : $*Builtin.Int64, %1 : $B):
return %4 : $Builtin.Int64
}

// CHECK-LABEL: sil @mark_dependence_base2
// CHECK: bb0(
// CHECK-NOT: open_existential_ref
// CHECK-NOT: enum
// CHECK-NEXT: mark_dependence
// CHECK-NEXT: load
// CHECK: return
sil @mark_dependence_base2 : $@convention(thin) (@inout Builtin.Int64, @owned B) -> Builtin.Int64 {
bb0(%0 : $*Builtin.Int64, %1 : $B):
%2 = init_existential_ref %1 : $B : $B, $AnyObject
%3 = open_existential_ref %2 : $AnyObject to $@opened("B674783A-EF08-11E7-97D6-8C85900CB088") _NSArrayCore
%5 = mark_dependence %0 : $*Builtin.Int64 on %3 : $@opened("B674783A-EF08-11E7-97D6-8C85900CB088") _NSArrayCore

%4 = load %5 : $*Builtin.Int64
return %4 : $Builtin.Int64
}