From d1ee7e0ba3b4f942e3bf3b2e9d6a02b186da4ec8 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Fri, 26 Mar 2010 16:26:03 +0000 Subject: [PATCH] Do not sibcall if stack needs to be dynamically aligned. llvm-svn: 99620 --- lib/Target/X86/X86ISelLowering.cpp | 6 ++++++ test/CodeGen/X86/sibcall.ll | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index d08dfc4eab5..707b9fe2c59 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -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()) diff --git a/test/CodeGen/X86/sibcall.ll b/test/CodeGen/X86/sibcall.ll index 541e7506b8b..8e52a7cbfe7 100644 --- a/test/CodeGen/X86/sibcall.ll +++ b/test/CodeGen/X86/sibcall.ll @@ -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()