Index: lib/Transforms/Coroutines/CoroSplit.cpp =================================================================== --- lib/Transforms/Coroutines/CoroSplit.cpp +++ lib/Transforms/Coroutines/CoroSplit.cpp @@ -654,13 +654,28 @@ // set. do { Instruction *Current = Work.pop_back_val(); + DEBUG(dbgs() << "CoroSplit: Will not relocate:\t" << *Current << "\n"); DoNotRelocate.insert(Current); for (Value *U : Current->operands()) { auto *I = dyn_cast(U); if (!I) continue; - if (isa(U)) + + if (auto *Alloca = 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(Alloca->getParent()) != 0) { + for (auto AI = Alloca->user_begin(), AE = Alloca->user_end(); AI != AE; + ++AI) { + if (auto *Store = dyn_cast(*AI)) { + DoNotRelocate.insert(Store); + } + } + } continue; + } + if (DoNotRelocate.count(I) == 0) { Work.push_back(I); DoNotRelocate.insert(I);