diff options
| author | Evan Cheng <evan.cheng@apple.com> | 2010-01-29 06:45:59 +0000 |
|---|---|---|
| committer | Evan Cheng <evan.cheng@apple.com> | 2010-01-29 06:45:59 +0000 |
| commit | 297a494f557ba268535a18dfc47dbc18613e13c1 (patch) | |
| tree | 26a3bedd082c11ac9ca1b9a0a13632b72be3c1fd /llvm/lib/Target/X86/X86ISelLowering.cpp | |
| parent | 385ab187e6d9e6d6a24c1d61055e37fbdd42675e (diff) | |
| download | bcm5719-llvm-297a494f557ba268535a18dfc47dbc18613e13c1.tar.gz bcm5719-llvm-297a494f557ba268535a18dfc47dbc18613e13c1.zip | |
Catch more trivial tail call opportunities: no inputs and output types match.
llvm-svn: 94804
Diffstat (limited to 'llvm/lib/Target/X86/X86ISelLowering.cpp')
| -rw-r--r-- | llvm/lib/Target/X86/X86ISelLowering.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index f868b75bd8b..5dbe0bb8f0a 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -2246,27 +2246,35 @@ X86TargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, const SmallVectorImpl<ISD::OutputArg> &Outs, const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG& DAG) const { - // If -tailcallopt is specified, make fastcc functions tail-callable. - const Function *F = DAG.getMachineFunction().getFunction(); - if (PerformTailCallOpt && - CalleeCC == CallingConv::Fast && F->getCallingConv() == CalleeCC) - return true; - if (CalleeCC != CallingConv::Fast && CalleeCC != CallingConv::C) return false; + // If -tailcallopt is specified, make fastcc functions tail-callable. + const Function *CallerF = DAG.getMachineFunction().getFunction(); + if (PerformTailCallOpt && + CalleeCC == CallingConv::Fast && + CallerF->getCallingConv() == CalleeCC) + return true; + // Look for obvious safe cases to perform tail call optimization. - // For now, only consider callees which take no arguments and no return - // values. + // For now, only consider callees which take no arguments. if (!Outs.empty()) return false; - if (Ins.empty()) - // If the caller does not return a value, then this is obviously safe. - return F->getReturnType()->isVoidTy(); + // 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 + // if the return types do not match. + const Type *CallerRetTy = CallerF->getReturnType(); + if (CallerRetTy->isVoidTy()) + return true; - return false; + // If the return types match, then it's safe. + GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee); + if (!G) return false; // FIXME: common external symbols? + Function *CalleeF = cast<Function>(G->getGlobal()); + const Type *CalleeRetTy = CalleeF->getReturnType(); + return CallerRetTy == CalleeRetTy; } FastISel * |

