diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp index b61017f37ca..314c990293c 100644 --- a/lib/Transforms/Utils/CloneFunction.cpp +++ b/lib/Transforms/Utils/CloneFunction.cpp @@ -325,11 +325,10 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB, // the basic block. if (Value *V = SimplifyInstruction(NewInst, BB->getModule()->getDataLayout())) { - assert((!isa(V) || - cast(V)->getParent() == nullptr || - cast(V)->getFunction() != OldFunc || - OldFunc == NewFunc) && - "Simplified Instruction should not be in the old function."); + // 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; if (!NewInst->mayHaveSideEffects()) { VMap[&*II] = V; diff --git a/test/Transforms/Inline/pr33637.ll b/test/Transforms/Inline/pr33637.ll new file mode 100644 index 00000000000..315feca27bd --- /dev/null +++ b/test/Transforms/Inline/pr33637.ll @@ -0,0 +1,25 @@ +; RUN: opt -inline < %s + +define void @patatino() { +for.cond: + br label %for.body + +for.body: + %tobool = icmp eq i32 5, 0 + %sel = select i1 %tobool, i32 0, i32 2 + br i1 undef, label %cleanup1.thread, label %cleanup1 + +cleanup1.thread: + ret void + +cleanup1: + %cleanup.dest2 = phi i32 [ %sel, %for.body ] + %switch = icmp ult i32 %cleanup.dest2, 1 + ret void +} + +define void @main() { +entry: + call void @patatino() + ret void +}