Index: lib/Transforms/Utils/CloneFunction.cpp =================================================================== --- lib/Transforms/Utils/CloneFunction.cpp +++ lib/Transforms/Utils/CloneFunction.cpp @@ -325,10 +325,11 @@ // the basic block. if (Value *V = SimplifyInstruction(NewInst, BB->getModule()->getDataLayout())) { - // On the off-chance that this simplifies to an instruction in the old - // function, map it back into the new function. - if (Value *MappedV = VMap.lookup(V)) - V = MappedV; + assert((!isa(V) || + dyn_cast(V)->getParent() == nullptr || + dyn_cast(V)->getFunction() != OldFunc || + OldFunc == NewFunc) && + "Simplified Instruction should not be in the old function."); if (!NewInst->mayHaveSideEffects()) { VMap[&*II] = V;