[PATCH] D130038: [coro async] Add missing llvm.coro.id.async intrinsic to declaresCoroCleanupIntrinsics

Arnold Schwaighofer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 18 12:51:48 PDT 2022


aschwaighofer created this revision.
aschwaighofer added a reviewer: nate_chandler.
Herald added a subscriber: hiraditya.
Herald added a project: All.
aschwaighofer requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

rdar://97214593


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130038

Files:
  llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
  llvm/test/Transforms/Coroutines/coro-async-coro-id-async-bug.ll


Index: llvm/test/Transforms/Coroutines/coro-async-coro-id-async-bug.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Coroutines/coro-async-coro-id-async-bug.ll
@@ -0,0 +1,44 @@
+; RUN: opt < %s -passes='default<O2>' -S | FileCheck --check-prefixes=CHECK %s
+target datalayout = "p:64:64:64"
+
+%swift.async_func_pointer = type <{ i32, i32 }>
+%swift.context = type { %swift.context*, void (%swift.context*)* }
+
+ at repoTU = global %swift.async_func_pointer <{ i32 trunc (i64 sub (i64 ptrtoint (void (%swift.context*)* @repo to i64), i64 ptrtoint (%swift.async_func_pointer* @repoTU to i64)) to i32), i32 16 }>, align 8
+
+define swifttailcc void @repo(%swift.context* swiftasync %0) {
+entry:
+  %1 = alloca %swift.context*, align 8
+  %2 = bitcast %swift.context* %0 to <{ %swift.context*, void (%swift.context*)* }>*
+  %3 = call token @llvm.coro.id.async(i32 16, i32 16, i32 0, i8* bitcast (%swift.async_func_pointer* @repoTU to i8*))
+  %4 = call i8* @llvm.coro.begin(token %3, i8* null)
+  store %swift.context* %0, %swift.context** %1, align 8
+  %5 = load %swift.context*, %swift.context** %1, align 8
+  %6 = bitcast %swift.context* %5 to <{ %swift.context*, void (%swift.context*)* }>*
+  %7 = getelementptr inbounds <{ %swift.context*, void (%swift.context*)* }>, <{ %swift.context*, void (%swift.context*)* }>* %6, i32 0, i32 1
+  %8 = load void (%swift.context*)*, void (%swift.context*)** %7, align 8
+  %9 = load %swift.context*, %swift.context** %1, align 8
+  %10 = bitcast void (%swift.context*)* %8 to i8*
+  %11 = call i1 (i8*, i1, ...) @llvm.coro.end.async(i8* %4, i1 false, void (i8*, %swift.context*)* @repo.0, i8* %10, %swift.context* %9)
+  unreachable
+}
+
+; CHECK-NOT: llvm.coro.id.async
+
+define internal swifttailcc void @repo.0(i8* %0, %swift.context* %1) #1 {
+entry:
+  %2 = bitcast i8* %0 to void (%swift.context*)*
+  musttail call swifttailcc void %2(%swift.context* swiftasync %1)
+  ret void
+}
+
+; Function Attrs: nounwind
+declare token @llvm.coro.id.async(i32, i32, i32, i8*) #1
+
+; Function Attrs: nounwind
+declare i8* @llvm.coro.begin(token, i8* writeonly) #1
+
+; Function Attrs: nounwind
+declare i1 @llvm.coro.end.async(i8*, i1, ...) #1
+
+attributes #1 = { nounwind }
Index: llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
===================================================================
--- llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
+++ llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
@@ -112,8 +112,8 @@
   return coro::declaresIntrinsics(
       M, {"llvm.coro.alloc", "llvm.coro.begin", "llvm.coro.subfn.addr",
           "llvm.coro.free", "llvm.coro.id", "llvm.coro.id.retcon",
-          "llvm.coro.id.retcon.once", "llvm.coro.async.size.replace",
-          "llvm.coro.async.resume"});
+          "llvm.coro.id.async", "llvm.coro.id.retcon.once",
+          "llvm.coro.async.size.replace", "llvm.coro.async.resume"});
 }
 
 PreservedAnalyses CoroCleanupPass::run(Module &M,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130038.445606.patch
Type: text/x-patch
Size: 2997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220718/7be9147c/attachment.bin>


More information about the llvm-commits mailing list