summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp2
-rw-r--r--llvm/test/Transforms/SimplifyCFG/noreturn-call.ll22
2 files changed, 21 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 429ae85596f..7024c663e30 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -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.
diff --git a/llvm/test/Transforms/SimplifyCFG/noreturn-call.ll b/llvm/test/Transforms/SimplifyCFG/noreturn-call.ll
index b4547782837..88d4f85713b 100644
--- a/llvm/test/Transforms/SimplifyCFG/noreturn-call.ll
+++ b/llvm/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 }
OpenPOWER on IntegriCloud