Allow more tailcall optimization: calls with inputs that are all passed in registers.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94873 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp
index 5dbe0bb..c0ebade 100644
--- a/lib/Target/X86/X86ISelLowering.cpp
+++ b/lib/Target/X86/X86ISelLowering.cpp
@@ -2258,9 +2258,18 @@
     return true;
 
   // Look for obvious safe cases to perform tail call optimization.
-  // For now, only consider callees which take no arguments.
-  if (!Outs.empty())
-    return false;
+  // If the callee takes no arguments then go on to check the results of the
+  // call.
+  if (!Outs.empty()) {
+    // Check if stack adjustment is needed. For now, do not do this if any
+    // argument is passed on the stack.
+    SmallVector<CCValAssign, 16> ArgLocs;
+    CCState CCInfo(CalleeCC, isVarArg, getTargetMachine(),
+                   ArgLocs, *DAG.getContext());
+    CCInfo.AnalyzeCallOperands(Outs, CCAssignFnForNode(CalleeCC));
+    if (CCInfo.getNextStackOffset())
+      return false;
+  }
 
   // If the caller does not return a value, then this is obviously safe.
   // This is one case where it's safe to perform this optimization even