diff options
author | Evan Cheng <evan.cheng@apple.com> | 2010-02-03 03:28:02 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2010-02-03 03:28:02 +0000 |
commit | 40905b43024caf6781fdc20a458a5a862cc9897b (patch) | |
tree | 4bab76dc759fd55c6bffd82c848d5143d7a47acf /llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | |
parent | c434394d183a00235f8773de831b447d35e1963c (diff) | |
download | bcm5719-llvm-40905b43024caf6781fdc20a458a5a862cc9897b.tar.gz bcm5719-llvm-40905b43024caf6781fdc20a458a5a862cc9897b.zip |
Allow all types of callee's to be tail called. But avoid automatic tailcall if the callee is a result of bitcast to avoid losing necessary zext / sext etc.
llvm-svn: 95195
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 284b984f0a1..495418d999e 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -4197,8 +4197,9 @@ SelectionDAGBuilder::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { /// /// This function only tests target-independent requirements. static bool -isInTailCallPosition(const Instruction *I, Attributes CalleeRetAttr, +isInTailCallPosition(CallSite CS, Attributes CalleeRetAttr, const TargetLowering &TLI) { + const Instruction *I = CS.getInstruction(); const BasicBlock *ExitBB = I->getParent(); const TerminatorInst *Term = ExitBB->getTerminator(); const ReturnInst *Ret = dyn_cast<ReturnInst>(Term); @@ -4207,6 +4208,12 @@ isInTailCallPosition(const Instruction *I, Attributes CalleeRetAttr, // The block must end in a return statement or an unreachable. if (!Ret && !isa<UnreachableInst>(Term)) return false; + // Unless we are explicitly forcing tailcall optimization do not tailcall if + // the called function is bitcast'ed. The analysis may not be entirely + // accurate. + if (!PerformTailCallOpt && isa<BitCastInst>(CS.getCalledValue())) + return false; + // If I will have a chain, make sure no other instruction that will have a // chain interposes between I and the return. if (I->mayHaveSideEffects() || I->mayReadFromMemory() || @@ -4348,9 +4355,7 @@ void SelectionDAGBuilder::LowerCallTo(CallSite CS, SDValue Callee, // Check if target-independent constraints permit a tail call here. // Target-dependent constraints are checked within TLI.LowerCallTo. if (isTailCall && - !isInTailCallPosition(CS.getInstruction(), - CS.getAttributes().getRetAttributes(), - TLI)) + !isInTailCallPosition(CS, CS.getAttributes().getRetAttributes(), TLI)) isTailCall = false; std::pair<SDValue,SDValue> Result = |