const ReturnInst *Ret = dyn_cast<ReturnInst>(Term);
const Function *F = ExitBB->getParent();
- // The block must end in a return statement or an unreachable.
- if (!Ret && !isa<UnreachableInst>(Term)) return false;
+ // The block must end in a return statement.
+ // FIXME: Disallow tailcall if the block ends in an unreachable for now.
+ // The way tailcall optimization is currently implemented means it will
+ // add an epilogue followed by a jump. That is not profitable. Also, if
+ // the callee is a special function (e.g. longjmp on x86), it can end up
+ // causing miscompilation that has not been fully understood.
+ if (!Ret) 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
if (!FunctionContainsEscapingAllocas)
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
- if (CallInst *CI = dyn_cast<CallInst>(I))
- if (!CI->doesNotReturn()) {
- CI->setTailCall();
- MadeChange = true;
- }
+ if (CallInst *CI = dyn_cast<CallInst>(I)) {
+ CI->setTailCall();
+ MadeChange = true;
+ }
return MadeChange;
}
-; RUN: llc < %s -march=x86 -tailcallopt | grep TAILCALL | count 5
+; RUN: llc < %s -march=x86 -tailcallopt | grep TAILCALL | count 4
declare fastcc i32 @tailcallee(i32 %a1, i32 %a2, i32 %a3, i32 %a4)
%1 = tail call signext i16 %0(i32 0) nounwind
ret i16 %1
}
+
+define void @t10() nounwind ssp {
+entry:
+; 32: t10:
+; 32: call
+
+; 64: t10:
+; 64: callq
+ %0 = tail call i32 @foo4() noreturn nounwind
+ unreachable
+}
+
+declare i32 @foo4()
+++ /dev/null
-; RUN: opt < %s -tailcallelim -S | FileCheck %s
-
-define void @t() nounwind ssp {
-entry:
-; CHECK: entry:
-; CHECK: %0 = call i32 @foo()
-; CHECK: ret void
- %0 = call i32 @foo() nounwind noreturn
- ret void
-}
-
-declare i32 @foo()