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) "coroutine.presplit"="1" personality i32 0 {
10 %id = call token @llvm.coro.id(i32 8, i8* null, i8* null, i8* null)
11 %size = call i32 @llvm.coro.size.i32()
12 %alloc = call i8* @malloc(i32 %size)
13 %hdl = call i8* @llvm.coro.begin(token %id, i8* %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, %f.Frame* %FramePtr, i32 0, i32 2
35 ; CHECK: store i32 %val, i32* %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 [i8* null, i32 64, i8* 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(i8* %hdl, i1 0)
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, i8* readnone, i8* nocapture readonly, i8*) #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 i8* @llvm.coro.begin(token, i8* writeonly) #2
74 declare token @llvm.coro.save(i8*)
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 i8* @malloc(i32)
81 declare void @free(i8*)
83 declare i1 @llvm.coro.end(i8*, i1) #2
85 ; Function Attrs: nobuiltin nounwind
87 ; Function Attrs: argmemonly nounwind readonly
88 declare i8* @llvm.coro.free(token, i8* nocapture readonly) #1