@@ -2153,6 +2153,8 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
21532153void MemoryToRegisters::collectStoredValues (AllocStackInst *asi,
21542154 StackList<SILValue> &owned,
21552155 StackList<SILValue> &guaranteed) {
2156+ if (!f.hasOwnership ())
2157+ return ;
21562158 for (auto *use : asi->getUses ()) {
21572159 auto *user = use->getUser ();
21582160 if (auto *si = dyn_cast<StoreInst>(user)) {
@@ -2166,6 +2168,8 @@ void MemoryToRegisters::collectStoredValues(AllocStackInst *asi,
21662168void MemoryToRegisters::canonicalizeValueLifetimes (
21672169 StackList<SILValue> &owned, StackList<SILValue> &guaranteed,
21682170 BasicBlockSetVector &livePhiBlocks) {
2171+ if (!f.hasOwnership ())
2172+ return ;
21692173 if (Mem2RegDisableLifetimeCanonicalization)
21702174 return ;
21712175
@@ -2191,6 +2195,8 @@ void MemoryToRegisters::canonicalizeValueLifetimes(
21912195 /* pruneDebug=*/ true , /* maximizeLifetime=*/ !f.shouldOptimize (), &f,
21922196 accessBlockAnalysis, domInfo, calleeAnalysis, deleter);
21932197 for (auto value : owned) {
2198+ if (isa<SILUndef>(value))
2199+ continue ;
21942200 auto root = CanonicalizeOSSALifetime::getCanonicalCopiedDef (value);
21952201 if (auto *copy = dyn_cast<CopyValueInst>(root)) {
21962202 if (SILValue borrowDef = CanonicalizeBorrowScope::getCanonicalBorrowedDef (
@@ -2203,6 +2209,8 @@ void MemoryToRegisters::canonicalizeValueLifetimes(
22032209 }
22042210 CanonicalizeBorrowScope borrowCanonicalizer (&f, deleter);
22052211 for (auto value : guaranteed) {
2212+ if (isa<SILUndef>(value))
2213+ continue ;
22062214 auto borrowee = CanonicalizeBorrowScope::getCanonicalBorrowedDef (value);
22072215 if (!borrowee)
22082216 continue ;
0 commit comments