Skip to content

Commit 39b9616

Browse files
committed
[SILCombine] Keep ued(deiniting).
It's not allowed to replace ued(enum(x)) with x if the enum in question has a deinit.
1 parent 0315fcd commit 39b9616

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/SILOptimizer/Analysis/SimplifyInstruction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ SILValue InstSimplifier::visitStructExtractInst(StructExtractInst *sei) {
172172

173173
SILValue
174174
InstSimplifier::visitUncheckedEnumDataInst(UncheckedEnumDataInst *uedi) {
175+
if (uedi->getOperand()->getType().isValueTypeWithDeinit())
176+
return SILValue();
175177
// (unchecked_enum_data (enum payload)) -> payload
176178
auto opt = lookThroughOwnershipInsts(uedi->getOperand());
177179
if (auto *ei = dyn_cast<EnumInst>(opt)) {

lib/SILOptimizer/Utils/CanonicalizeInstruction.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ eliminateUnneededForwardingUnarySingleValueInst(SingleValueInstruction *inst,
549549
auto next = std::next(inst->getIterator());
550550
if (isa<DropDeinitInst>(inst))
551551
return next;
552+
if (auto *uedi = dyn_cast<UncheckedEnumDataInst>(inst)) {
553+
if (uedi->getOperand()->getType().isValueTypeWithDeinit())
554+
return next;
555+
}
552556
for (auto *use : getNonDebugUses(inst)) {
553557
if (auto *destroy = dyn_cast<DestroyValueInst>(use->getUser())) {
554558
if (destroy->isFullDeinitialization())

0 commit comments

Comments
 (0)