Index: lib/Transforms/Coroutines/CoroSplit.cpp =================================================================== --- lib/Transforms/Coroutines/CoroSplit.cpp +++ lib/Transforms/Coroutines/CoroSplit.cpp @@ -654,13 +654,25 @@ // set. do { Instruction *Current = Work.pop_back_val(); + DEBUG(dbgs() << "CoroSplit: Will not relocate: " << *Current << "\n"); DoNotRelocate.insert(Current); for (Value *U : Current->operands()) { auto *I = dyn_cast(U); if (!I) continue; - if (isa(U)) + + if (auto *A = dyn_cast(I)) { + // Stores to alloca instructions that occur before coroutine frame + // is allocated should not be moved; the stored values may be used + // by the coroutine frame allocator. + if (RelocBlocks.count(A->getParent()) != 0) { + for (const auto &User : A->users()) + if (auto *SI = dyn_cast(User)) + DoNotRelocate.insert(SI); + } continue; + } + if (DoNotRelocate.count(I) == 0) { Work.push_back(I); DoNotRelocate.insert(I);