Skip to content

Commit 5e13af4

Browse files
committed
[NFC] Extracted isRedundantMoveValue.
Extracted the predicate from inline in RedundantMoveValueElimination into the new function which can now be called from elsewhere (CopyPropagation).
1 parent aae9483 commit 5e13af4

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,14 @@ void visitTransitiveEndBorrows(
13471347
/// - the value is itself a begin_borrow [lexical]
13481348
bool isNestedLexicalBeginBorrow(BeginBorrowInst *bbi);
13491349

1350+
/// Whether specified move_value is redundant.
1351+
///
1352+
/// A move_value is redundant if the lifetimes that it separates both have the
1353+
/// same characteristics with respect to
1354+
/// - lexicality
1355+
/// - escaping
1356+
bool isRedundantMoveValue(MoveValueInst *mvi);
1357+
13501358
} // namespace swift
13511359

13521360
#endif

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,3 +2381,25 @@ bool swift::isNestedLexicalBeginBorrow(BeginBorrowInst *bbi) {
23812381
return false;
23822382
});
23832383
}
2384+
2385+
bool swift::isRedundantMoveValue(MoveValueInst *mvi) {
2386+
auto original = mvi->getOperand();
2387+
2388+
// If the moved-from value has none ownership, hasPointerEscape can't handle
2389+
// it, so it can't be used to determine whether escaping matches.
2390+
if (original->getOwnershipKind() != OwnershipKind::Owned) {
2391+
return false;
2392+
}
2393+
2394+
// First, check whether lexicality matches, the cheaper check.
2395+
if (mvi->isLexical() != original->isLexical()) {
2396+
return false;
2397+
}
2398+
2399+
// Then, check whether escaping matches, the more expensive check.
2400+
if (hasPointerEscape(mvi) != hasPointerEscape(original)) {
2401+
return false;
2402+
}
2403+
2404+
return true;
2405+
}

lib/SILOptimizer/SemanticARC/RedundantMoveValueElimination.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,10 @@ bool SemanticARCOptVisitor::visitMoveValueInst(MoveValueInst *mvi) {
3939
if (!ctx.shouldPerform(ARCTransformKind::RedundantMoveValueElim))
4040
return false;
4141

42-
auto original = mvi->getOperand();
43-
44-
// If the moved-from value has none ownership, hasPointerEscape can't handle
45-
// it, so it can't be used to determine whether escaping matches.
46-
if (original->getOwnershipKind() != OwnershipKind::Owned) {
47-
return false;
48-
}
49-
50-
// First, check whether lexicality matches, the cheaper check.
51-
if (mvi->isLexical() != original->isLexical()) {
52-
return false;
53-
}
54-
55-
// Then, check whether escaping matches, the more expensive check.
56-
if (hasPointerEscape(mvi) != hasPointerEscape(original)) {
42+
if (!isRedundantMoveValue(mvi))
5743
return false;
58-
}
5944

6045
// Both characteristics match.
61-
eraseAndRAUWSingleValueInstruction(mvi, original);
46+
eraseAndRAUWSingleValueInstruction(mvi, mvi->getOperand());
6247
return true;
6348
}

0 commit comments

Comments
 (0)