[llvm-commits] [llvm] r94946 - in /llvm/trunk: lib/Target/X86/X86ISelLowering.cpp test/CodeGen/X86/tailcall2.ll

Evan Cheng evan.cheng at apple.com
Sat Jan 30 22:44:50 PST 2010


Author: evancheng
Date: Sun Jan 31 00:44:49 2010
New Revision: 94946

URL: http://llvm.org/viewvc/llvm-project?rev=94946&view=rev
Log:
Avoid recursive sibcall's.

Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
    llvm/trunk/test/CodeGen/X86/tailcall2.ll

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=94946&r1=94945&r2=94946&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Sun Jan 31 00:44:49 2010
@@ -2252,10 +2252,26 @@
 
   // If -tailcallopt is specified, make fastcc functions tail-callable.
   const Function *CallerF = DAG.getMachineFunction().getFunction();
-  if (PerformTailCallOpt &&
-      CalleeCC == CallingConv::Fast &&
-      CallerF->getCallingConv() == CalleeCC)
-    return true;
+  if (PerformTailCallOpt) {
+    if (CalleeCC == CallingConv::Fast &&
+        CallerF->getCallingConv() == CalleeCC)
+      return true;
+    return false;
+  }
+
+  // Do not tail call optimize vararg calls for now.
+  if (isVarArg)
+    return false;
+
+  // Don't tail call optimize recursive call.
+  GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);
+  const Function *CalleeF = G ? cast<Function>(G->getGlobal()) : 0;
+  if (CallerF == CalleeF)
+    return false;
+  // If it's an indirect call, conversatively return false if the caller's
+  // address is taken.
+  if (!isa<ExternalSymbolSDNode>(Callee) && CallerF->hasAddressTaken())
+    return false;
 
   // Look for obvious safe cases to perform tail call optimization.
   // If the callee takes no arguments then go on to check the results of the
@@ -2279,9 +2295,7 @@
     return true;
 
   // If the return types match, then it's safe.
-  GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);
   if (!G) return false;  // FIXME: common external symbols?
-  Function *CalleeF = cast<Function>(G->getGlobal());
   const Type *CalleeRetTy = CalleeF->getReturnType();
   return CallerRetTy == CalleeRetTy;
 }

Modified: llvm/trunk/test/CodeGen/X86/tailcall2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tailcall2.ll?rev=94946&r1=94945&r2=94946&view=diff

==============================================================================
--- llvm/trunk/test/CodeGen/X86/tailcall2.ll (original)
+++ llvm/trunk/test/CodeGen/X86/tailcall2.ll Sun Jan 31 00:44:49 2010
@@ -65,3 +65,27 @@
   tail call void %x() nounwind
   ret void
 }
+
+define i32 @t6(i32 %x) nounwind ssp {
+entry:
+; 32: t6:
+; 32: call {{_?}}t6
+; 32: call {{_?}}bar
+
+; 64: t6:
+; 64: callq {{_?}}t6
+; 64: jmp {{_?}}bar
+  %0 = icmp slt i32 %x, 10
+  br i1 %0, label %bb, label %bb1
+
+bb:
+  %1 = add nsw i32 %x, -1
+  %2 = tail call i32 @t6(i32 %1) nounwind ssp
+  ret i32 %2
+
+bb1:
+  %3 = tail call i32 @bar(i32 %x) nounwind
+  ret i32 %3
+}
+
+declare i32 @bar(i32)





More information about the llvm-commits mailing list