@@ -732,21 +732,22 @@ StoreInst *StackAllocationPromoter::promoteAllocationInBlock(
732
732
733
733
// Replace destroys with a release of the value.
734
734
if (auto *dai = dyn_cast<DestroyAddrInst>(inst)) {
735
- if (dai->getOperand () == asi) {
736
- if (runningVals) {
737
- replaceDestroy (dai, runningVals->value .replacement (asi, dai), ctx,
738
- deleter, instructionsToDelete);
739
- if (shouldAddLexicalLifetime (asi)) {
740
- endLexicalLifetimeBeforeInst (asi, /* beforeInstruction=*/ dai, ctx,
741
- runningVals->value );
742
- }
743
- runningVals->isStorageValid = false ;
744
- if (lastStoreInst)
745
- lastStoreInst->isStorageValid = false ;
746
- } else {
747
- assert (!deinitializationPoints[blockPromotingWithin]);
748
- deinitializationPoints[blockPromotingWithin] = dai;
735
+ if (dai->getOperand () != asi) {
736
+ continue ;
737
+ }
738
+ if (runningVals) {
739
+ replaceDestroy (dai, runningVals->value .replacement (asi, dai), ctx,
740
+ deleter, instructionsToDelete);
741
+ if (shouldAddLexicalLifetime (asi)) {
742
+ endLexicalLifetimeBeforeInst (asi, /* beforeInstruction=*/ dai, ctx,
743
+ runningVals->value );
749
744
}
745
+ runningVals->isStorageValid = false ;
746
+ if (lastStoreInst)
747
+ lastStoreInst->isStorageValid = false ;
748
+ } else {
749
+ assert (!deinitializationPoints[blockPromotingWithin]);
750
+ deinitializationPoints[blockPromotingWithin] = dai;
750
751
}
751
752
continue ;
752
753
}
@@ -1636,26 +1637,27 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
1636
1637
// Remove stores and record the value that we are saving as the running
1637
1638
// value.
1638
1639
if (auto *si = dyn_cast<StoreInst>(inst)) {
1639
- if (si->getDest () == asi) {
1640
- if (si->getOwnershipQualifier () == StoreOwnershipQualifier::Assign) {
1641
- assert (runningVals && runningVals->isStorageValid );
1642
- SILBuilderWithScope (si, ctx).createDestroyValue (
1643
- si->getLoc (), runningVals->value .replacement (asi, si));
1644
- }
1645
- auto oldRunningVals = runningVals;
1646
- runningVals = {LiveValues::toReplace (asi, /* replacement=*/ si->getSrc ()),
1647
- /* isStorageValid=*/ true };
1648
- if (shouldAddLexicalLifetime (asi)) {
1649
- if (oldRunningVals && oldRunningVals->isStorageValid ) {
1650
- endLexicalLifetimeBeforeInst (asi, /* beforeInstruction=*/ si, ctx,
1651
- oldRunningVals->value );
1652
- }
1653
- runningVals = beginLexicalLifetimeAfterStore (asi, si);
1654
- }
1655
- deleter.forceDelete (inst);
1656
- ++NumInstRemoved;
1640
+ if (si->getDest () != asi) {
1657
1641
continue ;
1658
1642
}
1643
+ if (si->getOwnershipQualifier () == StoreOwnershipQualifier::Assign) {
1644
+ assert (runningVals && runningVals->isStorageValid );
1645
+ SILBuilderWithScope (si, ctx).createDestroyValue (
1646
+ si->getLoc (), runningVals->value .replacement (asi, si));
1647
+ }
1648
+ auto oldRunningVals = runningVals;
1649
+ runningVals = {LiveValues::toReplace (asi, /* replacement=*/ si->getSrc ()),
1650
+ /* isStorageValid=*/ true };
1651
+ if (shouldAddLexicalLifetime (asi)) {
1652
+ if (oldRunningVals && oldRunningVals->isStorageValid ) {
1653
+ endLexicalLifetimeBeforeInst (asi, /* beforeInstruction=*/ si, ctx,
1654
+ oldRunningVals->value );
1655
+ }
1656
+ runningVals = beginLexicalLifetimeAfterStore (asi, si);
1657
+ }
1658
+ deleter.forceDelete (inst);
1659
+ ++NumInstRemoved;
1660
+ continue ;
1659
1661
}
1660
1662
1661
1663
// Replace debug_value w/ address value with debug_value of
0 commit comments