Do not sibcall if stack needs to be dynamically aligned.
authorEvan Cheng <evan.cheng@apple.com>
Fri, 26 Mar 2010 16:26:03 +0000 (16:26 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Fri, 26 Mar 2010 16:26:03 +0000 (16:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99620 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/sibcall.ll

index d08dfc4eab58f845e517285f6ebc0fceef4d2147..707b9fe2c59031c98d02a0f29f47eccbf5190872 100644 (file)
@@ -2290,6 +2290,7 @@ X86TargetLowering::IsEligibleForTailCallOptimization(SDValue Callee,
     return false;
 
   // If -tailcallopt is specified, make fastcc functions tail-callable.
+  const MachineFunction &MF = DAG.getMachineFunction();
   const Function *CallerF = DAG.getMachineFunction().getFunction();
   if (GuaranteedTailCallOpt) {
     if (IsTailCallConvention(CalleeCC) &&
@@ -2301,6 +2302,11 @@ X86TargetLowering::IsEligibleForTailCallOptimization(SDValue Callee,
   // Look for obvious safe cases to perform tail call optimization that does not
   // requite ABI changes. This is what gcc calls sibcall.
 
+  // Can't do sibcall if stack needs to be dynamically re-aligned. PEI needs to
+  // emit a special epilogue.
+  if (RegInfo->needsStackRealignment(MF))
+    return false;
+
   // Do not sibcall optimize vararg calls unless the call site is not passing any
   // arguments.
   if (isVarArg && !Outs.empty())
index 541e7506b8bc1c28dc151679f8aff72dddff66f5..8e52a7cbfe783098b31982bd064abb5b5f6789cd 100644 (file)
@@ -302,3 +302,14 @@ entry:
 }
 
 declare double @bar6(...)
+
+define void @t19() alignstack(32) nounwind {
+entry:
+; CHECK: t19:
+; CHECK: andl $-32
+; CHECK: call {{_?}}foo
+  tail call void @foo() nounwind
+  ret void
+}
+
+declare void @foo()