@@ -753,11 +753,8 @@ SILValue AvailableValueAggregator::handlePrimitiveValue(SILType loadTy,
753
753
SingleValueInstruction *
754
754
AvailableValueAggregator::addMissingDestroysForCopiedValues (
755
755
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" );
761
758
762
759
assert ((isa<LoadBorrowInst>(svi) || isa<LoadInst>(svi)) &&
763
760
" Expected to have a /real/ load here since we assume that we have a "
@@ -1601,6 +1598,18 @@ bool AllocOptimize::promoteLoadCopy(LoadInst *li) {
1601
1598
1602
1599
LLVM_DEBUG (llvm::dbgs () << " *** Promoting load: " << *li << " \n " );
1603
1600
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
+ }
1604
1613
1605
1614
// If we inserted any copies, we created the copies at our stores. We know
1606
1615
// that in our load block, we will reform the aggregate as appropriate at the
@@ -1611,8 +1620,6 @@ bool AllocOptimize::promoteLoadCopy(LoadInst *li) {
1611
1620
// for the purposes of identifying the consuming block).
1612
1621
auto *oldLoad = agg.addMissingDestroysForCopiedValues (li, newVal);
1613
1622
1614
- ++NumLoadPromoted;
1615
-
1616
1623
// If we are returned the load, eliminate it. Otherwise, it was already
1617
1624
// handled for us... so return true.
1618
1625
if (!oldLoad)
0 commit comments