]> granicus.if.org Git - llvm/commitdiff
Inlining: Don't re-map simplified cloned instructions.
authorKyle Butt <kyle+llvm@iteratee.net>
Wed, 28 Jun 2017 01:41:25 +0000 (01:41 +0000)
committerKyle Butt <kyle+llvm@iteratee.net>
Wed, 28 Jun 2017 01:41:25 +0000 (01:41 +0000)
When simplifying an instruction that has been re-mapped, it should never
simplify to an instruction in the original function. In the edge case
where we are inlining a function into itself, the existing code led to
incorrect behavior. Replace the incorrect code with an assert verifying
that we never expect simplification to produce an instruction in the old
function, unless the functions are the same.

Differential Revision: https://reviews.llvm.org/D33850

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306495 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/CloneFunction.cpp

index 314c990293cc5701a6824e6b5ebf5a64c9d17dda..b61017f37ca984791ab6ed4ef1607580199d7c38 100644 (file)
@@ -325,10 +325,11 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
       // 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<Instruction>(V) ||
+                cast<Instruction>(V)->getParent() == nullptr ||
+                cast<Instruction>(V)->getFunction() != OldFunc ||
+                OldFunc == NewFunc) &&
+               "Simplified Instruction should not be in the old function.");
 
         if (!NewInst->mayHaveSideEffects()) {
           VMap[&*II] = V;