Skip to content

Commit 15e5364

Browse files
committed
DeadObjectElimination: Handle keypaths with non-trivial operands in OSSA
1 parent 41697b0 commit 15e5364

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lib/SILOptimizer/Transforms/DeadObjectElimination.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -892,11 +892,20 @@ bool DeadObjectElimination::processKeyPath(KeyPathInst *KPI) {
892892
return false;
893893
}
894894

895-
// For simplicity just bail if the keypath has a non-trivial operands.
896-
// TODO: don't bail but insert compensating destroys for such operands.
897-
for (const Operand &Op : KPI->getPatternOperands()) {
898-
if (!Op.get()->getType().isTrivial(*KPI->getFunction()))
899-
return false;
895+
// In non-ossa, bail out if we have non-trivial pattern operands
896+
if (!KPI->getFunction()->hasOwnership()) {
897+
for (const Operand &Op : KPI->getPatternOperands()) {
898+
if (!Op.get()->getType().isTrivial(*KPI->getFunction()))
899+
return false;
900+
}
901+
}
902+
903+
if (KPI->getFunction()->hasOwnership()) {
904+
for (const Operand &Op : KPI->getPatternOperands()) {
905+
if (Op.get()->getType().isTrivial(*KPI->getFunction()))
906+
continue;
907+
SILBuilderWithScope(KPI).createDestroyValue(KPI->getLoc(), Op.get());
908+
}
900909
}
901910

902911
// Remove the keypath and all of its users.

0 commit comments

Comments
 (0)