Skip to content

Commit 08c1974

Browse files
committed
Remove complex bailouts and fix replacing open_existential_ref
This code was previously turned off for non-ossa and was creating illegal unchecked_ref_cast with same source and destination.
1 parent 0b6ab9a commit 08c1974

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -798,30 +798,17 @@ SILCombiner::buildConcreteOpenedExistentialInfoFromSoleConformingType(
798798
// Prepare the code by adding UncheckedCast instructions that cast opened
799799
// existentials to concrete types. Set the ConcreteValue of CEI.
800800
if (auto *OER = dyn_cast<OpenExistentialRefInst>(OAI.OpenedArchetypeValue)) {
801-
// If we have an owned open_existential_ref, we only optimize for now if our
802-
// open_existential_ref has a single non-debug consuming use that is a
803-
// destroy_value.
804-
if (OER->getForwardingOwnershipKind() != OwnershipKind::Owned) {
805-
// We use OER as the insertion point so that
806-
SILBuilderWithScope b(std::next(OER->getIterator()), Builder);
807-
auto loc = RegularLocation::getAutoGeneratedLocation();
808-
SoleCEI.ConcreteValue =
809-
b.createUncheckedRefCast(loc, OER, concreteSILType);
810-
return COAI;
811-
}
812-
813-
auto *consumingUse = OER->getSingleConsumingUse();
814-
if (!consumingUse || !isa<DestroyValueInst>(consumingUse->getUser())) {
815-
return std::nullopt;
816-
}
817-
818-
// We use std::next(OER) as the insertion point so that we can reuse the
819-
// destroy_value of consumingUse.
820801
SILBuilderWithScope b(std::next(OER->getIterator()), Builder);
821802
auto loc = RegularLocation::getAutoGeneratedLocation();
822803
auto *uri = b.createUncheckedRefCast(loc, OER, concreteSILType);
823804
SoleCEI.ConcreteValue = uri;
824-
replaceInstUsesWith(*OER, uri);
805+
for (auto *use : OER->getUses()) {
806+
auto *user = use->getUser();
807+
if (user == uri) {
808+
continue;
809+
}
810+
setUseValue(use, uri);
811+
}
825812
return COAI;
826813
}
827814

0 commit comments

Comments
 (0)