Skip to content

Commit 2c4f14b

Browse files
committed
[ShrinkBorrowScope] Replaced check with assertion.
Previously, it was checked whether a barrier terminator was actually a control flow terminator before adding end_borrows at the beginnings of its successors. But it can't actually happen that a terminator is classified as a barrier without the beginnings of all of its predecessors having been reached because the BackwardReachability data flow is pessimistic and only visits the end of a block (i.e. its terminator) if it reached the beginnings of all of that block's successors (see BackwardReachability::meetOverSuccessors and where the data flow calls it).
1 parent 208743c commit 2c4f14b

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

lib/SILOptimizer/Utils/ShrinkBorrowScope.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -336,25 +336,19 @@ bool Rewriter::run() {
336336
// Insert end_borrows after every non-terminator barrier.
337337
//
338338
// For terminator barriers, add end_borrows at the beginning of the successor
339-
// blocks. But only if all of its parent block P's successors S in succ(P)
340-
// had reachable beginnings. If any one of them didn't, then this isn't a
341-
// barrier boundary but actually a control flow boundary, and will be handled
342-
// below. We witness that all of its successors had reachable beginnings by
343-
// way of parent block P having a reachable end.
344-
//
345-
// terminator-boundary(B) := isBarrier(P->getTerminator()) && end-reachable(P)
346-
// where P := pred(B)
339+
// blocks. In order to reach a terminator and classify it as a barrier, all
340+
// of a block P's successors B had reachable beginnings. If any of them
341+
// didn't, then BackwardReachability::meetOverSuccessors would never have
342+
// returned true for P, so none of its instructions would ever have been
343+
// classified (except for via checkReachablePhiBarrier, which doesn't record
344+
// terminator barriers).
347345
for (auto instruction : barriers.barriers) {
348346
if (auto *terminator = dyn_cast<TermInst>(instruction)) {
349347
auto successors = terminator->getParentBlock()->getSuccessorBlocks();
350-
if (!barriers.hoistingReachesEndBlocks.contains(
351-
terminator->getParentBlock())) {
352-
// If reachability didn't make it to the begin of any one of this
353-
// block's successors, then this isn't a terminator boundary, and will
354-
// be handled below.
355-
assert(successors.size() > 1);
356-
continue;
357-
}
348+
// In order for the instruction to have been classified as a barrier,
349+
// reachability would have had to reach the block containing it.
350+
assert(barriers.hoistingReachesEndBlocks.contains(
351+
terminator->getParentBlock()));
358352
for (auto *successor : successors) {
359353
madeChange |= createEndBorrow(&successor->front());
360354
}

0 commit comments

Comments
 (0)