Skip to content

Commit 8d9455e

Browse files
committed
[pmo] Rather than bailing from addMissingDestroysForCopiedValues if we are in non-ossa, just always assume we are in ossa in the code and do not call it if we are in non-ossa.
1 parent 5ecacb9 commit 8d9455e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -753,11 +753,8 @@ SILValue AvailableValueAggregator::handlePrimitiveValue(SILType loadTy,
753753
SingleValueInstruction *
754754
AvailableValueAggregator::addMissingDestroysForCopiedValues(
755755
SingleValueInstruction *svi, SILValue newVal) {
756-
// If ownership is not enabled... bail. We do not need to do this since we do
757-
// not need to insert an extra copy unless we have ownership since without
758-
// ownership stores do not consume.
759-
if (!B.hasOwnership())
760-
return svi;
756+
assert(B.hasOwnership() &&
757+
"We assume this is only called if we have ownership");
761758

762759
assert((isa<LoadBorrowInst>(svi) || isa<LoadInst>(svi)) &&
763760
"Expected to have a /real/ load here since we assume that we have a "
@@ -1601,6 +1598,18 @@ bool AllocOptimize::promoteLoadCopy(LoadInst *li) {
16011598

16021599
LLVM_DEBUG(llvm::dbgs() << " *** Promoting load: " << *li << "\n");
16031600
LLVM_DEBUG(llvm::dbgs() << " To value: " << *newVal << "\n");
1601+
++NumLoadPromoted;
1602+
1603+
// If we did not have ownership, we did not insert extra copies at our stores,
1604+
// so we can just RAUW and return.
1605+
if (!li->getFunction()->hasOwnership()) {
1606+
li->replaceAllUsesWith(newVal);
1607+
SILValue addr = li->getOperand();
1608+
li->eraseFromParent();
1609+
if (auto *addrI = addr->getDefiningInstruction())
1610+
recursivelyDeleteTriviallyDeadInstructions(addrI);
1611+
return true;
1612+
}
16041613

16051614
// If we inserted any copies, we created the copies at our stores. We know
16061615
// that in our load block, we will reform the aggregate as appropriate at the
@@ -1611,8 +1620,6 @@ bool AllocOptimize::promoteLoadCopy(LoadInst *li) {
16111620
// for the purposes of identifying the consuming block).
16121621
auto *oldLoad = agg.addMissingDestroysForCopiedValues(li, newVal);
16131622

1614-
++NumLoadPromoted;
1615-
16161623
// If we are returned the load, eliminate it. Otherwise, it was already
16171624
// handled for us... so return true.
16181625
if (!oldLoad)

0 commit comments

Comments
 (0)