Regenerate.
[oota-llvm.git] / lib / Transforms / Scalar / LoopStrengthReduce.cpp
index 9689c120d692b9fc161769bba9af4f0c845da6b2..fea3c420d9e26d7295c5e7ddfbb2c72540f78069 100644 (file)
@@ -145,7 +145,7 @@ namespace {
 
   public:
     static char ID; // Pass ID, replacement for typeid
-    LoopStrengthReduce(const TargetLowering *tli = NULL) : 
+    explicit LoopStrengthReduce(const TargetLowering *tli = NULL) : 
       LoopPass((intptr_t)&ID), TLI(tli) {
     }
 
@@ -596,10 +596,13 @@ void BasedUser::RewriteInstructionToUseNewBase(const SCEVHandle &NewBase,
       }
     }
     Value *NewVal = InsertCodeForBaseAtPosition(NewBase, Rewriter, InsertPt, L);
-    // Adjust the type back to match the Inst.
+    // Adjust the type back to match the Inst. Note that we can't use InsertPt
+    // here because the SCEVExpander may have inserted the instructions after
+    // that point, in its efforts to avoid inserting redundant expressions.
     if (isa<PointerType>(OperandValToReplace->getType())) {
-      NewVal = new IntToPtrInst(NewVal, OperandValToReplace->getType(), "cast",
-                                InsertPt);
+      NewVal = SCEVExpander::InsertCastOfTo(Instruction::IntToPtr,
+                                            NewVal,
+                                            OperandValToReplace->getType());
     }
     // Replace the use of the operand Value with the new Phi we just created.
     Inst->replaceUsesOfWith(OperandValToReplace, NewVal);
@@ -648,9 +651,14 @@ void BasedUser::RewriteInstructionToUseNewBase(const SCEVHandle &NewBase,
         Instruction *InsertPt = PN->getIncomingBlock(i)->getTerminator();
         Code = InsertCodeForBaseAtPosition(NewBase, Rewriter, InsertPt, L);
 
-        // Adjust the type back to match the PHI.
+        // Adjust the type back to match the PHI. Note that we can't use
+        // InsertPt here because the SCEVExpander may have inserted its
+        // instructions after that point, in its efforts to avoid inserting
+        // redundant expressions.
         if (isa<PointerType>(PN->getType())) {
-          Code = new IntToPtrInst(Code, PN->getType(), "cast", InsertPt);
+          Code = SCEVExpander::InsertCastOfTo(Instruction::IntToPtr,
+                                              Code,
+                                              PN->getType());
         }
       }