File tree 3 files changed +32
-17
lines changed 3 files changed +32
-17
lines changed Original file line number Diff line number Diff line change @@ -1347,6 +1347,14 @@ void visitTransitiveEndBorrows(
1347
1347
// / - the value is itself a begin_borrow [lexical]
1348
1348
bool isNestedLexicalBeginBorrow (BeginBorrowInst *bbi);
1349
1349
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
+
1350
1358
} // namespace swift
1351
1359
1352
1360
#endif
Original file line number Diff line number Diff line change @@ -2381,3 +2381,25 @@ bool swift::isNestedLexicalBeginBorrow(BeginBorrowInst *bbi) {
2381
2381
return false ;
2382
2382
});
2383
2383
}
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) {
39
39
if (!ctx.shouldPerform (ARCTransformKind::RedundantMoveValueElim))
40
40
return false ;
41
41
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))
57
43
return false ;
58
- }
59
44
60
45
// Both characteristics match.
61
- eraseAndRAUWSingleValueInstruction (mvi, original );
46
+ eraseAndRAUWSingleValueInstruction (mvi, mvi-> getOperand () );
62
47
return true ;
63
48
}
You can’t perform that action at this time.
0 commit comments