2 ; RUN: opt -S -hoist-common-insts -hoist-common-insts -passes=simplifycfg < %s | FileCheck %s --check-prefixes=CHECK
3 target datalayout = "p:64:64:64"
4 %swift.async_func_pointer = type <{ i32, i32 }>
5 %swift.context = type { ptr, ptr }
9 declare ptr @llvm.coro.async.resume()
10 declare { ptr } @llvm.coro.suspend.async.sl_p0i8s(i32, ptr, ptr, ...)
11 declare ptr @llvm.coro.begin(token, ptr writeonly)
12 declare token @llvm.coro.id.async(i32, i32, i32, ptr)
14 declare i1 @llvm.coro.end.async(ptr, i1, ...)
16 define linkonce_odr hidden ptr @__swift_async_resume_get_context(ptr %0) {
21 @repoTU = hidden global %swift.async_func_pointer <{ i32 trunc (i64 sub (i64 ptrtoint (ptr @repo to i64), i64 ptrtoint (ptr @repoTU to i64)) to i32), i32 16 }>, align 8
23 ; This test used to crash in optimized mode because simplify cfg would sink the
24 ; suspend.async() instruction into a common successor block.
26 ; CHECK: swifttailcc void @repo
27 ; CHECK:llvm.coro.suspend.async.sl_p0s
29 ; CHECK:llvm.coro.suspend.async.sl_p0s
33 define hidden swifttailcc void @repo(ptr swiftasync %0, i1 %cond) {
35 %tok = call token @llvm.coro.id.async(i32 16, i32 16, i32 0, ptr @repoTU)
36 %id = call ptr @llvm.coro.begin(token %tok, ptr null)
37 br i1 %cond, label %bb1, label %bb2
41 %ptr0 = call ptr @llvm.coro.async.resume()
43 ; Simplifycfg must not sink the suspend instruction.
44 %t3 = call { ptr } (i32, ptr, ptr, ...) @llvm.coro.suspend.async.sl_p0i8s(i32 0, ptr %ptr0, ptr @__swift_async_resume_get_context, ptr @repo.1, ptr %ptr0, ptr %0)
49 %ptr1 = call ptr @llvm.coro.async.resume()
51 ; Simplifycfg must not sink the suspend instruction.
52 %t4 = call { ptr } (i32, ptr, ptr, ...) @llvm.coro.suspend.async.sl_p0i8s(i32 0, ptr %ptr1, ptr @__swift_async_resume_get_context, ptr @repo.1, ptr %ptr1, ptr %0)
56 %t = call i1 (ptr, i1, ...) @llvm.coro.end.async(ptr %id, i1 false, ptr @repo.0, ptr @return, ptr %0)
60 define internal swifttailcc void @repo.0(ptr %0, ptr %1) {
62 musttail call swifttailcc void %0(ptr swiftasync %1)
66 declare swifttailcc void @swift_task_switch(ptr, ptr)
68 define internal swifttailcc void @repo.1(ptr %0, ptr %1) {
70 musttail call swifttailcc void @swift_task_switch(ptr swiftasync %1, ptr %0)
74 declare swifttailcc void @return(ptr swiftasync)
76 @repoTU2 = hidden global %swift.async_func_pointer <{ i32 trunc (i64 sub (i64 ptrtoint (ptr @repo2 to i64), i64 ptrtoint (ptr @repoTU2 to i64)) to i32), i32 16 }>, align 8
78 ; This test used to crash in optimized mode because simplify cfg would hoist the
79 ; async.resume() instruction into a common block.
81 ; CHECK: swifttailcc void @repo2
85 ; CHECK: @llvm.coro.async.resume()
86 ; CHECK: llvm.coro.suspend.async.sl_p0s
89 ; CHECK:@llvm.coro.async.resume()
90 ; CHECK:llvm.coro.suspend.async.sl_p0s
95 define hidden swifttailcc void @repo2(ptr swiftasync %0, i1 %cond) {
97 %tok = call token @llvm.coro.id.async(i32 16, i32 16, i32 0, ptr @repoTU2)
98 %id = call ptr @llvm.coro.begin(token %tok, ptr null)
99 br i1 %cond, label %bb1, label %bb2
102 ; Simplifycfg must not hoist the resume instruction.
103 %ptr0 = call ptr @llvm.coro.async.resume()
105 %t3 = call { ptr } (i32, ptr, ptr, ...) @llvm.coro.suspend.async.sl_p0i8s(i32 0, ptr %ptr0, ptr @__swift_async_resume_get_context, ptr @repo.1, ptr %ptr0, ptr %0)
110 ; Simplifycfg must not hoist the resume instruction.
111 %ptr1 = call ptr @llvm.coro.async.resume()
113 %t4 = call { ptr } (i32, ptr, ptr, ...) @llvm.coro.suspend.async.sl_p0i8s(i32 0, ptr %ptr1, ptr @__swift_async_resume_get_context, ptr @repo.1, ptr %ptr1, ptr %0)
118 %t = call i1 (ptr, i1, ...) @llvm.coro.end.async(ptr %id, i1 false, ptr @repo.0, ptr @return, ptr %0)