[llvm-commits] [llvm] r95198 - in /llvm/trunk: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp lib/Transforms/Scalar/TailRecursionElimination.cpp test/CodeGen/X86/tailcall1.ll test/CodeGen/X86/tailcall2.ll test/Transforms/TailCallElim/no-return-calls.ll

Evan Cheng evan.cheng at apple.com
Tue Feb 2 19:55:59 PST 2010


Author: evancheng
Date: Tue Feb  2 21:55:59 2010
New Revision: 95198

URL: http://llvm.org/viewvc/llvm-project?rev=95198&view=rev
Log:
Revert 94937 and move the noreturn check to codegen.

Removed:
    llvm/trunk/test/Transforms/TailCallElim/no-return-calls.ll
Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
    llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
    llvm/trunk/test/CodeGen/X86/tailcall1.ll
    llvm/trunk/test/CodeGen/X86/tailcall2.ll

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=95198&r1=95197&r2=95198&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Tue Feb  2 21:55:59 2010
@@ -4205,8 +4205,13 @@
   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

Modified: llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp?rev=95198&r1=95197&r2=95198&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp Tue Feb  2 21:55:59 2010
@@ -184,11 +184,10 @@
   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;
 }

Modified: llvm/trunk/test/CodeGen/X86/tailcall1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tailcall1.ll?rev=95198&r1=95197&r2=95198&view=diff

==============================================================================
--- llvm/trunk/test/CodeGen/X86/tailcall1.ll (original)
+++ llvm/trunk/test/CodeGen/X86/tailcall1.ll Tue Feb  2 21:55:59 2010
@@ -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)
 

Modified: llvm/trunk/test/CodeGen/X86/tailcall2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tailcall2.ll?rev=95198&r1=95197&r2=95198&view=diff

==============================================================================
--- llvm/trunk/test/CodeGen/X86/tailcall2.ll (original)
+++ llvm/trunk/test/CodeGen/X86/tailcall2.ll Tue Feb  2 21:55:59 2010
@@ -127,3 +127,16 @@
   %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()

Removed: llvm/trunk/test/Transforms/TailCallElim/no-return-calls.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/TailCallElim/no-return-calls.ll?rev=95197&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/TailCallElim/no-return-calls.ll (original)
+++ llvm/trunk/test/Transforms/TailCallElim/no-return-calls.ll (removed)
@@ -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()





More information about the llvm-commits mailing list