[llvm-commits] [llvm] r95565 - in /llvm/trunk: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp test/CodeGen/X86/tailcall1.ll

Dan Gohman gohman at apple.com
Mon Feb 8 12:34:14 PST 2010


Author: djg
Date: Mon Feb  8 14:34:14 2010
New Revision: 95565

URL: http://llvm.org/viewvc/llvm-project?rev=95565&view=rev
Log:
In guaranteed tailcall mode, don't decline the tailcall optimization
for blocks ending in "unreachable".

Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
    llvm/trunk/test/CodeGen/X86/tailcall1.ll

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

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Mon Feb  8 14:34:14 2010
@@ -4205,13 +4205,16 @@
   const ReturnInst *Ret = dyn_cast<ReturnInst>(Term);
   const Function *F = ExitBB->getParent();
 
-  // 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;
+  // The block must end in a return statement or unreachable.
+  //
+  // FIXME: Decline tailcall if it's not guaranteed and 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 &&
+      (!GuaranteedTailCallOpt || !isa<UnreachableInst>(Term))) return false;
 
   // If I will have a chain, make sure no other instruction that will have a
   // chain interposes between I and the return.

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

==============================================================================
--- llvm/trunk/test/CodeGen/X86/tailcall1.ll (original)
+++ llvm/trunk/test/CodeGen/X86/tailcall1.ll Mon Feb  8 14:34:14 2010
@@ -1,4 +1,7 @@
-; RUN: llc < %s -march=x86 -tailcallopt | grep TAILCALL | count 4
+; RUN: llc < %s -march=x86 -tailcallopt | grep TAILCALL | count 5
+
+; With -tailcallopt, CodeGen guarantees a tail call optimization
+; for all of these.
 
 declare fastcc i32 @tailcallee(i32 %a1, i32 %a2, i32 %a3, i32 %a4)
 





More information about the llvm-commits mailing list