[llvm-commits] [llvm] r41804 - in /llvm/trunk: lib/Transforms/Scalar/TailRecursionElimination.cpp test/Transforms/TailCallElim/inf-recursion.ll

Chris Lattner sabre at nondot.org
Mon Sep 10 13:58:55 PDT 2007


Author: lattner
Date: Mon Sep 10 15:58:55 2007
New Revision: 41804

URL: http://llvm.org/viewvc/llvm-project?rev=41804&view=rev
Log:
Prevent tailcallelim from breaking "recursive" calls to builtins.

Added:
    llvm/trunk/test/Transforms/TailCallElim/inf-recursion.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp

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

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp Mon Sep 10 15:58:55 2007
@@ -302,6 +302,15 @@
 
   if (&BB->front() == Ret) // Make sure there is something before the ret...
     return false;
+  
+  // If the return is in the entry block, then making this transformation would
+  // turn infinite recursion into an infinite loop.  This transformation is ok
+  // in theory, but breaks some code like:
+  //   double fabs(double f) { return __builtin_fabs(f); } // a 'fabs' call
+  // disable this xform in this case, because the code generator will lower the
+  // call to fabs into inline code.
+  if (BB == &F->getEntryBlock())
+    return false;
 
   // Scan backwards from the return, checking to see if there is a tail call in
   // this block.  If so, set CI to it.

Added: llvm/trunk/test/Transforms/TailCallElim/inf-recursion.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/TailCallElim/inf-recursion.ll?rev=41804&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/TailCallElim/inf-recursion.ll (added)
+++ llvm/trunk/test/Transforms/TailCallElim/inf-recursion.ll Mon Sep 10 15:58:55 2007
@@ -0,0 +1,10 @@
+; RUN: llvm-as < %s | opt -tailcallelim | grep call
+; Don't turn this into an infinite loop, this is probably the implementation
+; of fabs and we expect the codegen to lower fabs.
+
+define double @fabs(double %f) {
+entry:
+        %tmp2 = call double @fabs( double %f )          ; <double> [#uses=1]
+        ret double %tmp2
+}
+





More information about the llvm-commits mailing list