]> granicus.if.org Git - llvm/commitdiff
[SimplifyCFG] Don't split musttail call from ret
authorJoseph Tremoulet <jotrem@microsoft.com>
Tue, 2 Apr 2019 15:48:58 +0000 (15:48 +0000)
committerJoseph Tremoulet <jotrem@microsoft.com>
Tue, 2 Apr 2019 15:48:58 +0000 (15:48 +0000)
Summary:
When inserting an `unreachable` after a noreturn call, we must ensure
that it's not a musttail call to avoid breaking the IR invariants for
musttail calls.

Reviewers: fedor.sergeev, majnemer

Reviewed By: majnemer

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D60080

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

lib/Transforms/Utils/Local.cpp
test/Transforms/SimplifyCFG/noreturn-call.ll

index 429ae85596f74e314274f6cd2019e95fa5c8bffc..7024c663e30878c00d0c63f83bb58fa77698c3b7 100644 (file)
@@ -2054,7 +2054,7 @@ static bool markAliveBlocks(Function &F,
           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.
index b45477828374ee022bfb55c6e182114a80f0b384..88d4f85713bc16d4d5f4abcd8b2dbaca24f2a86e 100644 (file)
@@ -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 }