Skip to content

Commit 69abf25

Browse files
committed
[NFC] Mem2Reg: Restructured conditional.
In preparation for adding other cases. Also improved comments.
1 parent 1f7432d commit 69abf25

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,17 +2097,20 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
20972097
}
20982098
}
20992099

2100-
if (lexicalLifetimeEnsured(asi) && runningVals &&
2101-
runningVals->isStorageValid &&
2100+
if (!runningVals || !runningVals->isStorageValid) {
2101+
return;
2102+
}
2103+
// There is still valid storage after visiting all instructions in this
2104+
// block which are the only instructions involving this alloc_stack.
2105+
// That can only happen if:
2106+
// - all paths from this block end in unreachable
2107+
2108+
if (lexicalLifetimeEnsured(asi) &&
21022109
runningVals->value.getStored()->getOwnershipKind().isCompatibleWith(
21032110
OwnershipKind::Owned)) {
2104-
// There is still valid storage after visiting all instructions in this
2105-
// block which are the only instructions involving this alloc_stack.
2106-
// This can only happen if all paths from this block end in unreachable.
2107-
//
2108-
// We need to end the lexical lifetime at the last possible location, at the
2109-
// boundary blocks which are the predecessors of dominance frontier
2110-
// dominated by the alloc_stack.
2111+
// An owned value was stored to the alloc_stack [lexical] but never
2112+
// destroy_addr'd. Destroy it on the dominance boundary of the
2113+
// alloc_stack's parent block.
21112114
SmallVector<SILBasicBlock *, 4> boundary;
21122115
computeDominatedBoundaryBlocks(asi->getParent(), domInfo, boundary);
21132116
for (auto *block : boundary) {

0 commit comments

Comments
 (0)