In guaranteed tailcall mode, don't decline the tailcall optimization
authorDan Gohman <gohman@apple.com>
Mon, 8 Feb 2010 20:34:14 +0000 (20:34 +0000)
committerDan Gohman <gohman@apple.com>
Mon, 8 Feb 2010 20:34:14 +0000 (20:34 +0000)
for blocks ending in "unreachable".

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95565 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
test/CodeGen/X86/tailcall1.ll

index cf342c793b9dcef4cfefa77a2f16ae024267f901..93ae043dbc14435c5f3c203b971d7481c2372b78 100644 (file)
@@ -4205,13 +4205,16 @@ isInTailCallPosition(CallSite CS, Attributes CalleeRetAttr,
   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.
index d08919e668cf652b118834d9dc681741e8e8f4e4..f7ff5d5308d66411fbae3efbf394109efabb00c7 100644 (file)
@@ -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)