Index: lib/Transforms/Scalar/RewriteStatepointsForGC.cpp =================================================================== --- lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -1865,12 +1865,18 @@ assert(!Inst->isTerminator() && "The only TerminatorInst that can produce a value is " "InvokeInst which is handled above."); - Store->insertAfter(Inst); + if (isa(Inst)) { + Store->insertBefore(Inst->getParent()->getFirstNonPHI()); + } else { + Store->insertAfter(Inst); + } } } else { assert(isa(Def)); Store->insertAfter(cast(Alloca)); } + assert(!isa(Store->getNextNode()) && + "must not insert in front of phi"); } assert(PromotableAllocas.size() == Live.size() + NumRematerializedValues &&