reapply Sanjiv's patch to genericize memcpy/memset/memmove to take an
arbitrary integer width for the count.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@59823 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index ee6b51c..717a46e 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -9200,12 +9200,11 @@
       if (GlobalVariable *GVSrc = dyn_cast<GlobalVariable>(MMI->getSource()))
         if (GVSrc->isConstant()) {
           Module *M = CI.getParent()->getParent()->getParent();
-          Intrinsic::ID MemCpyID;
-          if (CI.getOperand(3)->getType() == Type::Int32Ty)
-            MemCpyID = Intrinsic::memcpy_i32;
-          else
-            MemCpyID = Intrinsic::memcpy_i64;
-          CI.setOperand(0, Intrinsic::getDeclaration(M, MemCpyID));
+          Intrinsic::ID MemCpyID = Intrinsic::memcpy;
+          const Type *Tys[1];
+          Tys[0] = CI.getOperand(3)->getType();
+          CI.setOperand(0, 
+                        Intrinsic::getDeclaration(M, MemCpyID, Tys, 1));
           Changed = true;
         }
 
diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index 7ccca00..6d27327 100644
--- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -427,9 +427,12 @@
     // instruction needed by the start of the block.
     BasicBlock::iterator InsertPt = BI;
   
-    if (MemSetF == 0)
+    if (MemSetF == 0) {
+      const Type *Tys[] = {Type::Int64Ty};
       MemSetF = Intrinsic::getDeclaration(SI->getParent()->getParent()
-                                          ->getParent(), Intrinsic::memset_i64);
+                                          ->getParent(), Intrinsic::memset,
+                                          Tys, 1);
+   }
     
     // Get the starting pointer of the block.
     StartPtr = Range.StartPtr;
@@ -671,9 +674,11 @@
     return false;
   
   // If all checks passed, then we can transform these memcpy's
+  const Type *Tys[1];
+  Tys[0] = M->getLength()->getType();
   Function* MemCpyFun = Intrinsic::getDeclaration(
                                  M->getParent()->getParent()->getParent(),
-                                 M->getIntrinsicID());
+                                 M->getIntrinsicID(), Tys, 1);
     
   std::vector<Value*> args;
   args.push_back(M->getRawDest());
diff --git a/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/lib/Transforms/Scalar/SimplifyLibCalls.cpp
index 2fbc25e..8952747 100644
--- a/lib/Transforms/Scalar/SimplifyLibCalls.cpp
+++ b/lib/Transforms/Scalar/SimplifyLibCalls.cpp
@@ -130,9 +130,10 @@
 Value *LibCallOptimization::EmitMemCpy(Value *Dst, Value *Src, Value *Len,
                                        unsigned Align, IRBuilder<> &B) {
   Module *M = Caller->getParent();
-  Intrinsic::ID IID = Len->getType() == Type::Int32Ty ?
-                           Intrinsic::memcpy_i32 : Intrinsic::memcpy_i64;
-  Value *MemCpy = Intrinsic::getDeclaration(M, IID);
+  Intrinsic::ID IID = Intrinsic::memcpy;
+  const Type *Tys[1];
+  Tys[0] = Len->getType();
+  Value *MemCpy = Intrinsic::getDeclaration(M, IID, Tys, 1);
   return B.CreateCall4(MemCpy, CastToCStr(Dst, B), CastToCStr(Src, B), Len,
                        ConstantInt::get(Type::Int32Ty, Align));
 }
diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp
index 26b4de5..49131e8 100644
--- a/lib/Transforms/Utils/InlineFunction.cpp
+++ b/lib/Transforms/Utils/InlineFunction.cpp
@@ -257,8 +257,10 @@
         Value *NewAlloca = new AllocaInst(AggTy, 0, Align, I->getName(),
                                           Caller->begin()->begin());
         // Emit a memcpy.
+        const Type *Tys[] = { Type::Int64Ty };
         Function *MemCpyFn = Intrinsic::getDeclaration(Caller->getParent(),
-                                                       Intrinsic::memcpy_i64);
+                                                       Intrinsic::memcpy, 
+                                                       Tys, 1);
         Value *DestCast = new BitCastInst(NewAlloca, VoidPtrTy, "tmp", TheCall);
         Value *SrcCast = new BitCastInst(*AI, VoidPtrTy, "tmp", TheCall);