[Inline] Precommit tests for dead calls and willreturn.
authorFlorian Hahn <flo@fhahn.com>
Tue, 5 Jan 2021 18:46:17 +0000 (18:46 +0000)
committerFlorian Hahn <flo@fhahn.com>
Fri, 22 Jan 2021 21:29:43 +0000 (21:29 +0000)
precommit tests for D94106.

llvm/test/Transforms/Inline/dead-calls-willreturn.ll [new file with mode: 0644]

diff --git a/llvm/test/Transforms/Inline/dead-calls-willreturn.ll b/llvm/test/Transforms/Inline/dead-calls-willreturn.ll
new file mode 100644 (file)
index 0000000..463cc58
--- /dev/null
@@ -0,0 +1,53 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -inline -S %s | FileCheck %s
+
+; readnone but may not return according to attributes.
+define void @readnone_may_not_return() nounwind readnone ssp {
+; CHECK-LABEL: @readnone_may_not_return(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br label [[WHILE_BODY:%.*]]
+; CHECK:       while.body:
+; CHECK-NEXT:    br label [[WHILE_BODY]]
+;
+entry:
+  br label %while.body
+
+while.body:
+  br label %while.body
+}
+
+; readnone and guaranteed to return according to attributes.
+define void @readnone_willreturn() willreturn nounwind readnone ssp {
+; CHECK-LABEL: @readnone_willreturn(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    ret void
+;
+entry:
+  ret void
+}
+
+; Make sure the call to @readnone is not treated as dead, because it is not
+; marked as willreturn.
+define void @caller_may_not_return() ssp {
+; CHECK-LABEL: @caller_may_not_return(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    ret void
+;
+entry:
+  call void @readnone_may_not_return()
+  call void @readnone_willreturn()
+  ret void
+}
+
+; @caller_willreturn is marked as willreturn, so all called functions also must
+; return. All calls are dead.
+define void @caller_willreturn() ssp willreturn {
+; CHECK-LABEL: @caller_willreturn(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    ret void
+;
+entry:
+  call void @readnone_may_not_return()
+  call void @readnone_willreturn()
+  ret void
+}