Skip to content

Commit d27d83a

Browse files
committed
CSE/OSSA avoid endless cloning and reoptimization.
Prevent CSE from introducing useless copies, borrows, and clones. Otherwise it will endlessly clone and re-cse the same projections endlessly. TODO: Most of these cases can be handled GuarateedOwnershipExtension or extendOwnedLifetime without requiring any copies!
1 parent 7d6118f commit d27d83a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/SILOptimizer/Transforms/CSE.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,10 @@ bool CSE::processNode(DominanceInfoNode *Node) {
10331033
OwnershipRAUWHelper helper(RAUWFixupContext,
10341034
cast<SingleValueInstruction>(Inst),
10351035
cast<SingleValueInstruction>(AvailInst));
1036-
if (!helper.isValid())
1036+
// If RAUW requires cloning the original, then there's no point. If it
1037+
// also requires introducing a copy and new borrow scope, then it's a
1038+
// very bad idea.
1039+
if (!helper.isValid() || helper.requiresCopyBorrowAndClone())
10371040
continue;
10381041
// Replace SingleValueInstruction using OSSA RAUW here
10391042
nextI = helper.perform();

lib/SILOptimizer/Utils/OwnershipOptUtils.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,10 +1041,9 @@ OwnershipRAUWHelper::replaceAddressUses(SingleValueInstruction *oldValue,
10411041
SILValue newValue) {
10421042
assert(oldValue->getType().isAddress() && newValue->getType().isAddress());
10431043

1044-
// If we are replacing addresses, see if we need to handle interior pointer
1045-
// fixups. If we don't have any extra info, then we know that we can just RAUW
1046-
// without any further work.
1047-
if (!ctx->extraAddressFixupInfo.base)
1044+
// If newValue was not generated by an interior pointer, then it cannot
1045+
// be within a borrow scope, so direct replacement works.
1046+
if (!requiresCopyBorrowAndClone())
10481047
return replaceAllUsesAndErase(oldValue, newValue, ctx->callbacks);
10491048

10501049
// We are RAUWing two addresses and we found that:

0 commit comments

Comments
 (0)