Fix a bug in GVN that Duncan noticed, where we potentially need to insert a 
pointer bitcast when performing return slot optimization.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48343 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp
index 545f709..1d764af 100644
--- a/lib/Transforms/Scalar/GVN.cpp
+++ b/lib/Transforms/Scalar/GVN.cpp
@@ -1171,8 +1171,12 @@
 
   // All the checks have passed, so do the transformation.
   for (unsigned i = 0; i < CS.arg_size(); ++i)
-    if (CS.getArgument(i) == cpySrc)
+    if (CS.getArgument(i) == cpySrc) {
+      if (cpySrc->getType() != cpyDest->getType())
+        cpyDest = CastInst::createPointerCast(cpyDest, cpySrc->getType(),
+                                              cpyDest->getName(), C);
       CS.setArgument(i, cpyDest);
+    }
 
   // Drop any cached information about the call, because we may have changed
   // its dependence information by changing its parameter.