1 ; Verifies that we can insert the spill for a PHI preceding the catchswitch
2 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
4 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
5 target triple = "i686-pc-windows-msvc"
7 ; CHECK-LABEL: define void @f(
8 define void @f(i1 %cond) presplitcoroutine personality i32 0 {
10 %id = call token @llvm.coro.id(i32 8, ptr null, ptr null, ptr null)
11 %size = call i32 @llvm.coro.size.i32()
12 %alloc = call ptr @malloc(i32 %size)
13 %hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc)
14 br i1 %cond, label %if.else, label %if.then
17 invoke void @may_throw1()
18 to label %coro.ret unwind label %catch.dispatch
21 invoke void @may_throw2()
22 to label %coro.ret unwind label %catch.dispatch
24 catch.dispatch: ; preds = %if.else, %if.then
25 %val = phi i32 [ 1, %if.then ], [ 2, %if.else ]
26 %switch = catchswitch within none [label %catch] unwind label %cleanuppad
28 ; Verifies that we split out the PHI into a separate block
29 ; added a cleanuppad spill cleanupret unwinding into the catchswitch.
31 ; CHECK: catch.dispatch:
32 ; CHECK: %val = phi i32 [ 2, %if.else ], [ 1, %if.then ]
33 ; CHECK: %[[Pad:.+]] = cleanuppad within none []
34 ; CHECK: %val.spill.addr = getelementptr inbounds %f.Frame, ptr %hdl, i32 0, i32 2
35 ; CHECK: store i32 %val, ptr %val.spill.addr
36 ; CHECK: cleanupret from %[[Pad]] unwind label %[[Switch:.+]]
39 ; CHECK: %switch = catchswitch within none [label %catch] unwind to caller
41 catch: ; preds = %catch.dispatch
42 %pad = catchpad within %switch [ptr null, i32 64, ptr null]
43 catchret from %pad to label %suspend
46 %sp = call i8 @llvm.coro.suspend(token none, i1 false)
47 switch i8 %sp, label %coro.ret [
52 resume: ; preds = %await2.suspend
53 call void @print(i32 %val)
57 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
61 %cpad = cleanuppad within none []
62 cleanupret from %cpad unwind to caller
65 ; Function Attrs: argmemonly nounwind readonly
66 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1
68 ; Function Attrs: nounwind
69 declare i1 @llvm.coro.alloc(token) #2
71 ; Function Attrs: nobuiltin
72 declare i32 @llvm.coro.size.i32() #4
73 declare ptr @llvm.coro.begin(token, ptr writeonly) #2
74 declare token @llvm.coro.save(ptr)
75 declare i8 @llvm.coro.suspend(token, i1)
77 declare void @may_throw1()
78 declare void @may_throw2()
79 declare void @print(i32)
80 declare noalias ptr @malloc(i32)
81 declare void @free(ptr)
83 declare i1 @llvm.coro.end(ptr, i1, token) #2
85 ; Function Attrs: nobuiltin nounwind
87 ; Function Attrs: argmemonly nounwind readonly
88 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1