[PATCH] D33850: Inlining: Don't re-map simplified cloned instructions.

Kyle Butt via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 2 13:53:10 PDT 2017


iteratee created this revision.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D33850

Files:
  lib/Transforms/Utils/CloneFunction.cpp


Index: lib/Transforms/Utils/CloneFunction.cpp
===================================================================
--- lib/Transforms/Utils/CloneFunction.cpp
+++ lib/Transforms/Utils/CloneFunction.cpp
@@ -310,10 +310,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((dyn_cast<Instruction>(V) == nullptr ||
+                dyn_cast<Instruction>(V)->getParent() == nullptr ||
+                dyn_cast<Instruction>(V)->getFunction() != OldFunc ||
+                OldFunc == NewFunc) &&
+               "Simplified Instruction should not be in the old function.");
 
         if (!NewInst->mayHaveSideEffects()) {
           VMap[&*II] = V;
@@ -453,7 +454,7 @@
   //
   // Defer PHI resolution until rest of function is resolved.
   SmallVector<const PHINode*, 16> PHIToResolve;
-  for (const BasicBlock &BI : *OldFunc) {
+  for (const BasicBlock &BI : make_range(OldFunc->begin(), OldFunc->end())) {
     Value *V = VMap.lookup(&BI);
     BasicBlock *NewBB = cast_or_null<BasicBlock>(V);
     if (!NewBB) continue;  // Dead block.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33850.101273.patch
Type: text/x-patch
Size: 1340 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170602/0748834f/attachment.bin>


More information about the llvm-commits mailing list