When re-using an existing cast for a user, it's still necessary to call
authorDan Gohman <gohman@apple.com>
Thu, 21 Jan 2010 10:08:42 +0000 (10:08 +0000)
committerDan Gohman <gohman@apple.com>
Thu, 21 Jan 2010 10:08:42 +0000 (10:08 +0000)
rememberInstruction so that future users of that user will be inserted
in the correct position. This fixes the Darwin selfhost.

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

lib/Analysis/ScalarEvolutionExpander.cpp

index b049f424fa88f82cf22fd30a033a3d4cb0f9d635..a72f58f64faecd231ffaf33c772a3360889d6225 100644 (file)
@@ -98,14 +98,16 @@ Value *SCEVExpander::InsertNoopCastOfTo(Value *V, const Type *Ty) {
             It = cast<InvokeInst>(I)->getNormalDest()->begin();
           while (isa<PHINode>(It)) ++It;
           if (It != BasicBlock::iterator(CI)) {
-            // Recreate the cast at the beginning of the entry block.
+            // Recreate the cast after the user.
             // The old cast is left in place in case it is being used
             // as an insert point.
             Instruction *NewCI = CastInst::Create(Op, V, Ty, "", It);
             NewCI->takeName(CI);
             CI->replaceAllUsesWith(NewCI);
+            rememberInstruction(NewCI);
             return NewCI;
           }
+          rememberInstruction(CI);
           return CI;
         }
   }