[llvm-commits] [llvm] r94873 - in /llvm/trunk: lib/Target/X86/X86ISelLowering.cpp test/CodeGen/X86/2009-11-04-SubregCoalescingBug.ll test/CodeGen/X86/tailcall2.ll

Evan Cheng evan.cheng at apple.com
Fri Jan 29 17:22:00 PST 2010


Author: evancheng
Date: Fri Jan 29 19:22:00 2010
New Revision: 94873

URL: http://llvm.org/viewvc/llvm-project?rev=94873&view=rev
Log:
Allow more tailcall optimization: calls with inputs that are all passed in registers.

Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
    llvm/trunk/test/CodeGen/X86/2009-11-04-SubregCoalescingBug.ll
    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=94873&r1=94872&r2=94873&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Fri Jan 29 19:22:00 2010
@@ -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

Modified: llvm/trunk/test/CodeGen/X86/2009-11-04-SubregCoalescingBug.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/2009-11-04-SubregCoalescingBug.ll?rev=94873&r1=94872&r2=94873&view=diff

==============================================================================
--- llvm/trunk/test/CodeGen/X86/2009-11-04-SubregCoalescingBug.ll (original)
+++ llvm/trunk/test/CodeGen/X86/2009-11-04-SubregCoalescingBug.ll Fri Jan 29 19:22:00 2010
@@ -5,7 +5,7 @@
 entry:
 ; CHECK:     leal 15(%rsi), %edi
 ; CHECK-NOT: movl
-; CHECK:     callq _foo
+; CHECK:     jmp _foo
   %0 = add i32 %a, 15                             ; <i32> [#uses=1]
   %1 = zext i32 %0 to i64                         ; <i64> [#uses=1]
   tail call void @foo(i64 %1) nounwind

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

==============================================================================
--- llvm/trunk/test/CodeGen/X86/tailcall2.ll (original)
+++ llvm/trunk/test/CodeGen/X86/tailcall2.ll Fri Jan 29 19:22:00 2010
@@ -1,10 +1,13 @@
-; RUN: llc < %s -march=x86    -asm-verbose=false | FileCheck %s
-; RUN: llc < %s -march=x86-64 -asm-verbose=false | FileCheck %s
+; RUN: llc < %s -march=x86    -asm-verbose=false | FileCheck %s -check-prefix=32
+; RUN: llc < %s -march=x86-64 -asm-verbose=false | FileCheck %s -check-prefix=64
 
 define void @t1(i32 %x) nounwind ssp {
 entry:
-; CHECK: t1:
-; CHECK: jmp {{_?}}foo
+; 32: t1:
+; 32: jmp {{_?}}foo
+
+; 64: t1:
+; 64: jmp {{_?}}foo
   tail call void @foo() nounwind
   ret void
 }
@@ -13,8 +16,11 @@
 
 define void @t2() nounwind ssp {
 entry:
-; CHECK: t2:
-; CHECK: jmp {{_?}}foo2
+; 32: t2:
+; 32: jmp {{_?}}foo2
+
+; 64: t2:
+; 64: jmp {{_?}}foo2
   %0 = tail call i32 @foo2() nounwind
   ret void
 }
@@ -23,10 +29,39 @@
 
 define void @t3() nounwind ssp {
 entry:
-; CHECK: t3:
-; CHECK: jmp {{_?}}foo3
+; 32: t3:
+; 32: jmp {{_?}}foo3
+
+; 64: t3:
+; 64: jmp {{_?}}foo3
   %0 = tail call i32 @foo3() nounwind
   ret void
 }
 
 declare i32 @foo3()
+
+define void @t4(void (i32)* nocapture %x) nounwind ssp {
+entry:
+; 32: t4:
+; 32: call *
+; FIXME: gcc can generate a tailcall for this. But it's tricky.
+
+; 64: t4:
+; 64-NOT: call
+; 64: jmpq *
+  tail call void %x(i32 0) nounwind
+  ret void
+}
+
+define void @t5(void ()* nocapture %x) nounwind ssp {
+entry:
+; 32: t5:
+; 32-NOT: call
+; 32: jmpl *
+
+; 64: t5:
+; 64-NOT: call
+; 64: jmpq *
+  tail call void %x() nounwind
+  ret void
+}





More information about the llvm-commits mailing list