[PATCH] D60080: [SimplifyCFG] Don't split musttail call from ret

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 2 08:47:38 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL357485: [SimplifyCFG] Don't split musttail call from ret (authored by josepht, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60080?vs=193135&id=193303#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60080/new/

https://reviews.llvm.org/D60080

Files:
  llvm/trunk/lib/Transforms/Utils/Local.cpp
  llvm/trunk/test/Transforms/SimplifyCFG/noreturn-call.ll


Index: llvm/trunk/test/Transforms/SimplifyCFG/noreturn-call.ll
===================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/noreturn-call.ll
+++ llvm/trunk/test/Transforms/SimplifyCFG/noreturn-call.ll
@@ -1,11 +1,29 @@
-; RUN: opt < %s -simplifycfg -S | grep unreachable
+; RUN: opt < %s -simplifycfg -S | FileCheck %s
 ; PR1796
 
 declare void @Finisher(i32) noreturn
 
-define void @YYY(i32) {
+; Make sure we optimize a sequence of two calls (second unreachable);
+define void @double_call(i32) {
+; CHECK-LABEL: @double_call(
+; CHECK-NEXT:    tail call void @Finisher(i32 %0) #0
+; CHECK-NEXT:    unreachable
+;
   tail call void @Finisher(i32 %0) noreturn
   tail call void @Finisher(i32 %0) noreturn
   ret void
 }
 
+; Make sure we DON'T try to optimize a musttail call (the IR invariant
+; is that it must be followed by [optional bitcast then] ret).
+define void @must_tail(i32) {
+; CHECK-LABEL: @must_tail(
+; CHECK-NEXT:    musttail call void @Finisher(i32 %0) #0
+; CHECK-NEXT:    ret void
+;
+  musttail call void @Finisher(i32 %0) #0
+  ret void
+}
+
+; CHECK: attributes #0 = { noreturn }
+attributes #0 = { noreturn }
Index: llvm/trunk/lib/Transforms/Utils/Local.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp
@@ -2054,7 +2054,7 @@
           Changed = true;
           break;
         }
-        if (CI->doesNotReturn()) {
+        if (CI->doesNotReturn() && !CI->isMustTailCall()) {
           // If we found a call to a no-return function, insert an unreachable
           // instruction after it.  Make sure there isn't *already* one there
           // though.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60080.193303.patch
Type: text/x-patch
Size: 1751 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190402/be6a475a/attachment.bin>


More information about the llvm-commits mailing list