File tree Expand file tree Collapse file tree 3 files changed +32
-17
lines changed Expand file tree Collapse file tree 3 files changed +32
-17
lines changed Original file line number Diff line number Diff line change @@ -1347,6 +1347,14 @@ void visitTransitiveEndBorrows(
13471347// / - the value is itself a begin_borrow [lexical]
13481348bool 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
Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments