[PATCH] D26270: Avoid tail recursion elimination across calls with operand bundles

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 7 13:11:34 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL286147: Avoid tail recursion elimination across calls with operand bundles (authored by sanjoy).

Changed prior to commit:
  https://reviews.llvm.org/D26270?vs=76815&id=77087#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26270

Files:
  llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
  llvm/trunk/test/Transforms/TailCallElim/deopt-bundle.ll


Index: llvm/trunk/test/Transforms/TailCallElim/deopt-bundle.ll
===================================================================
--- llvm/trunk/test/Transforms/TailCallElim/deopt-bundle.ll
+++ llvm/trunk/test/Transforms/TailCallElim/deopt-bundle.ll
@@ -0,0 +1,57 @@
+; RUN: opt < %s -tailcallelim -S | FileCheck %s
+
+define i32 @f_1(i32 %x) {
+; CHECK-LABEL: @f_1(
+wentry:
+  %cond = icmp ugt i32 %x, 0
+  br i1 %cond, label %return, label %body
+
+body:
+; CHECK: body:
+; CHECK: call i32 @f_1(i32 %y) [ "deopt"() ]
+  %y = add i32 %x, 1
+  %tmp = call i32 @f_1(i32 %y) [ "deopt"() ]
+  ret i32 0
+
+return:
+  ret i32 1
+}
+
+define i32 @f_2(i32 %x) {
+; CHECK-LABEL: @f_2
+
+entry:
+  %cond = icmp ugt i32 %x, 0
+  br i1 %cond, label %return, label %body
+
+body:
+; CHECK: body:
+; CHECK: call i32 @f_2(i32 %y) [ "unknown"() ]
+  %y = add i32 %x, 1
+  %tmp = call i32 @f_2(i32 %y) [ "unknown"() ]
+  ret i32 0
+
+return:
+  ret i32 1
+}
+
+declare void @func()
+
+define void @f_3(i1 %B) personality i8 42 {
+; CHECK-LABEL: @f_3(
+entry:
+  invoke void @func()
+          to label %exit unwind label %merge
+merge:
+  %cs1 = catchswitch within none [label %catch] unwind to caller
+
+catch:
+; CHECK: catch:
+; CHECK: call void @f_3(i1 %B) [ "funclet"(token %cp) ]
+  %cp = catchpad within %cs1 []
+  call void @f_3(i1 %B) [ "funclet"(token %cp) ]
+  ret void
+
+exit:
+  ret void
+}
Index: llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
+++ llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
@@ -236,7 +236,7 @@
       if (!CI || CI->isTailCall())
         continue;
 
-      bool IsNoTail = CI->isNoTailCall();
+      bool IsNoTail = CI->isNoTailCall() || CI->hasOperandBundles();
 
       if (!IsNoTail && CI->doesNotAccessMemory()) {
         // A call to a readnone function whose arguments are all things computed
@@ -256,6 +256,7 @@
           SafeToTail = false;
           break;
         }
+        SafeToTail &= CI->hasOperandBundles();
         if (SafeToTail) {
           emitOptimizationRemark(
               F.getContext(), "tailcallelim", F, CI->getDebugLoc(),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26270.77087.patch
Type: text/x-patch
Size: 2247 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161107/638b96c8/attachment.bin>


More information about the llvm-commits mailing list