For PR1138:
authorReid Spencer <rspencer@reidspencer.com>
Sun, 28 Jan 2007 22:28:00 +0000 (22:28 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Sun, 28 Jan 2007 22:28:00 +0000 (22:28 +0000)
Force memcpy to be the 32-bit variant. Since this is only used with
CBE and lli which both target 32-bit machines, this should be okay.

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

lib/CodeGen/IntrinsicLowering.cpp

index 72a1d1485b49118e5a2d7039705f915617e881a3..65835da4f0aab4dad3cfc8cebda5042c2c5c2537 100644 (file)
@@ -77,13 +77,17 @@ void IntrinsicLowering::AddPrototypes(Module &M) {
         break;
       case Intrinsic::memcpy_i32:
       case Intrinsic::memcpy_i64:
-        EnsureFunctionExists(M, "memcpy", I->arg_begin(), --I->arg_end(),
-                             I->arg_begin()->getType());
+        M.getOrInsertFunction("memcpy", PointerType::get(Type::Int8Ty),
+                              PointerType::get(Type::Int8Ty), 
+                              PointerType::get(Type::Int8Ty), Type::Int32Ty,
+                              (Type *)0);
         break;
       case Intrinsic::memmove_i32:
       case Intrinsic::memmove_i64:
-        EnsureFunctionExists(M, "memmove", I->arg_begin(), --I->arg_end(),
-                             I->arg_begin()->getType());
+        M.getOrInsertFunction("memmove", PointerType::get(Type::Int8Ty),
+                              PointerType::get(Type::Int8Ty), 
+                              PointerType::get(Type::Int8Ty), Type::Int32Ty,
+                              (Type *)0);
         break;
       case Intrinsic::memset_i32:
       case Intrinsic::memset_i64:
@@ -360,6 +364,9 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
   }
   case Intrinsic::memcpy_i64: {
     static Constant *MemcpyFCache = 0;
+    Value * Size = cast<Value>(CI->op_end()-1);
+    if (Size->getType() != Type::Int32Ty)
+      Size->replaceAllUsesWith(new TruncInst(Size, Type::Int32Ty));
     ReplaceCallWith("memcpy", CI, CI->op_begin()+1, CI->op_end()-1,
                      (*(CI->op_begin()+1))->getType(), MemcpyFCache);
     break;