From f0d299c17281b1237e60fc772dae6511a76f8f4b Mon Sep 17 00:00:00 2001
From: Prakalp Srivastava <prakalps@gmail.com>
Date: Thu, 2 Jul 2015 11:06:00 -0500
Subject: [PATCH] Do not allow argument type mungling for __visc__ calls.
 Changes to lib/Transforms/InstCombine/InstCombineCalls.cpp

---
 .../InstCombine/InstCombineCalls.cpp          | 22 ++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 78b4a2c6c9..6ead515114 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -758,6 +758,20 @@ Instruction *InstCombiner::visitInvokeInst(InvokeInst &II) {
   return visitCallSite(&II);
 }
 
+// Check if it is a visc call
+static bool isVISCCall(const ImmutableCallSite &CS) {
+  if (!CS.getInstruction()) {
+    // This is not a call site
+    return false;
+  }
+  if (const CallInst *call = dyn_cast<CallInst>(CS.getInstruction())) {
+    if(const Function *F = call->getCalledFunction()) {
+      return F->getName().startswith("__visc__");
+    }
+  }
+  return false;
+}
+
 /// isSafeToEliminateVarargsCast - If this cast does not affect the value
 /// passed through the varargs area, we can eliminate the use of the cast.
 static bool isSafeToEliminateVarargsCast(const CallSite CS,
@@ -767,6 +781,11 @@ static bool isSafeToEliminateVarargsCast(const CallSite CS,
   if (!CI->isLosslessCast())
     return false;
 
+  // If this is a visc dummy call, avoid mungling types. We need types for
+  // generating correct visc code.
+  if(isVISCCall(CS))
+    return false;
+
   // The size of ByVal arguments is derived from the type, so we
   // can't change to a type with a different size.  If the size were
   // passed explicitly we could avoid this check.
@@ -780,6 +799,7 @@ static bool isSafeToEliminateVarargsCast(const CallSite CS,
     return false;
   if (!TD || TD->getTypeAllocSize(SrcTy) != TD->getTypeAllocSize(DstTy))
     return false;
+
   return true;
 }
 
@@ -976,7 +996,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
 }
 
 // transformConstExprCastCall - If the callee is a constexpr cast of a function,
-// attempt to move the cast to the arguments of the call/invoke.
+// attempt to move the cast to the arg\numents of the call/invoke.
 //
 bool InstCombiner::transformConstExprCastCall(CallSite CS) {
   Function *Callee =
-- 
GitLab