From febc81680c80a53f15f85b1812cba07fc179b9fd Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Wed, 3 Feb 2010 03:55:59 +0000 Subject: [PATCH] Revert 94937 and move the noreturn check to codegen. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95198 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 9 +++++++-- lib/Transforms/Scalar/TailRecursionElimination.cpp | 9 ++++----- test/CodeGen/X86/tailcall1.ll | 2 +- test/CodeGen/X86/tailcall2.ll | 13 +++++++++++++ test/Transforms/TailCallElim/no-return-calls.ll | 12 ------------ 5 files changed, 25 insertions(+), 20 deletions(-) delete mode 100644 test/Transforms/TailCallElim/no-return-calls.ll diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 495418d999e..3a25714f07c 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -4205,8 +4205,13 @@ isInTailCallPosition(CallSite CS, Attributes CalleeRetAttr, const ReturnInst *Ret = dyn_cast(Term); const Function *F = ExitBB->getParent(); - // The block must end in a return statement or an unreachable. - if (!Ret && !isa(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 diff --git a/lib/Transforms/Scalar/TailRecursionElimination.cpp b/lib/Transforms/Scalar/TailRecursionElimination.cpp index 913dd73cc17..162d902cfa4 100644 --- a/lib/Transforms/Scalar/TailRecursionElimination.cpp +++ b/lib/Transforms/Scalar/TailRecursionElimination.cpp @@ -184,11 +184,10 @@ bool TailCallElim::runOnFunction(Function &F) { 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(I)) - if (!CI->doesNotReturn()) { - CI->setTailCall(); - MadeChange = true; - } + if (CallInst *CI = dyn_cast(I)) { + CI->setTailCall(); + MadeChange = true; + } return MadeChange; } diff --git a/test/CodeGen/X86/tailcall1.ll b/test/CodeGen/X86/tailcall1.ll index 96c4cad9799..d08919e668c 100644 --- a/test/CodeGen/X86/tailcall1.ll +++ b/test/CodeGen/X86/tailcall1.ll @@ -1,4 +1,4 @@ -; 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) diff --git a/test/CodeGen/X86/tailcall2.ll b/test/CodeGen/X86/tailcall2.ll index 81419dc387e..3cd8b26f608 100644 --- a/test/CodeGen/X86/tailcall2.ll +++ b/test/CodeGen/X86/tailcall2.ll @@ -127,3 +127,16 @@ entry: %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() diff --git a/test/Transforms/TailCallElim/no-return-calls.ll b/test/Transforms/TailCallElim/no-return-calls.ll deleted file mode 100644 index f5643ae3330..00000000000 --- a/test/Transforms/TailCallElim/no-return-calls.ll +++ /dev/null @@ -1,12 +0,0 @@ -; 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() -- 2.34.1