Don't produce tail calls when the caller is x86_thiscallcc.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 22 Nov 2013 15:18:28 +0000 (15:18 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 22 Nov 2013 15:18:28 +0000 (15:18 +0000)
The callee will not pop the stack for us.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195467 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/stdcall-notailcall.ll

index 8320fc1b8822c21a4fc054d7480eb336e94e4b09..1a15bea0d922fb6bad22839adbd4f0d920a3b14a 100644 (file)
@@ -3092,9 +3092,13 @@ X86TargetLowering::IsEligibleForTailCallOptimization(SDValue Callee,
   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
index 8f522cda284a518162ceb1d79b2fd5a31e523279..c847ec7b6c0864710a6e30093ef7824b66481851 100644 (file)
@@ -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()