[llvm] r195467 - Don't produce tail calls when the caller is x86_thiscallcc.

Rafael Espindola rafael.espindola at gmail.com
Fri Nov 22 07:18:29 PST 2013


Author: rafael
Date: Fri Nov 22 09:18:28 2013
New Revision: 195467

URL: http://llvm.org/viewvc/llvm-project?rev=195467&view=rev
Log:
Don't produce tail calls when the caller is x86_thiscallcc.

The callee will not pop the stack for us.

Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
    llvm/trunk/test/CodeGen/X86/stdcall-notailcall.ll

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=195467&r1=195466&r2=195467&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Fri Nov 22 09:18:28 2013
@@ -3092,9 +3092,13 @@ X86TargetLowering::IsEligibleForTailCall
   if (isCalleeStructRet || isCallerStructRet)
     return false;
 
-  // An stdcall caller is expected to clean up its arguments; the callee
-  // isn't going to do that.
-  if (!CCMatch && CallerCC == CallingConv::X86_StdCall)
+  // An stdcall/thiscall caller is expected to clean up its arguments; the
+  // callee isn't going to do that.
+  // FIXME: this is more restrictive than needed. We could produce a tailcall
+  // when the stack adjustment matches. For example, with a thiscall that takes
+  // only one argument.
+  if (!CCMatch && (CallerCC == CallingConv::X86_StdCall ||
+                   CallerCC == CallingConv::X86_ThisCall))
     return false;
 
   // Do not sibcall optimize vararg calls unless all arguments are passed via

Modified: llvm/trunk/test/CodeGen/X86/stdcall-notailcall.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/stdcall-notailcall.ll?rev=195467&r1=195466&r2=195467&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/stdcall-notailcall.ll (original)
+++ llvm/trunk/test/CodeGen/X86/stdcall-notailcall.ll Fri Nov 22 09:18:28 2013
@@ -10,4 +10,12 @@ entry:
   ret void
 }
 
+define x86_thiscallcc void @test2(%struct.I*  %this, i32 %a) {
+; CHECK-LABEL: test2:
+; CHECK: calll _foo
+; CHECK: ret $4
+  tail call void @foo()
+  ret void
+}
+
 declare void @foo()





More information about the llvm-commits mailing list