1 ; Check that we can handle edge splits leading into a landingpad
2 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-unknown-linux-gnu"
7 ; CHECK-LABEL: define internal fastcc void @g.resume(
8 define void @g(i1 %cond, i32 %x, i32 %y) presplitcoroutine personality i32 0 {
10 %id = call token @llvm.coro.id(i32 16, i8* null, i8* null, i8* null)
11 %size = tail call i64 @llvm.coro.size.i64()
12 %alloc = call i8* @malloc(i64 %size)
13 %hdl = call i8* @llvm.coro.begin(token %id, i8* %alloc)
14 %sp = call i8 @llvm.coro.suspend(token none, i1 false)
15 switch i8 %sp, label %coro.ret [
21 br i1 %cond, label %invoke1, label %invoke2
24 invoke void @may_throw1()
25 to label %unreach unwind label %pad.with.phi
27 invoke void @may_throw2()
28 to label %unreach unwind label %pad.with.phi
30 ; Verify that we created cleanuppads on every edge and inserted a reload of the spilled value
32 ; CHECK: pad.with.phi.from.invoke2:
33 ; CHECK: %0 = cleanuppad within none []
34 ; CHECK: %y.reload.addr = getelementptr inbounds %g.Frame, %g.Frame* %FramePtr, i32 0, i32 3
35 ; CHECK: %y.reload = load i32, i32* %y.reload.addr
36 ; CHECK: cleanupret from %0 unwind label %pad.with.phi
38 ; CHECK: pad.with.phi.from.invoke1:
39 ; CHECK: %1 = cleanuppad within none []
40 ; CHECK: %x.reload.addr = getelementptr inbounds %g.Frame, %g.Frame* %FramePtr, i32 0, i32 2
41 ; CHECK: %x.reload = load i32, i32* %x.reload.addr
42 ; CHECK: cleanupret from %1 unwind label %pad.with.phi
44 ; CHECK: pad.with.phi:
45 ; CHECK: %val = phi i32 [ %x.reload, %pad.with.phi.from.invoke1 ], [ %y.reload, %pad.with.phi.from.invoke2 ]
46 ; CHECK: %tok = cleanuppad within none []
47 ; CHECK: call void @use_val(i32 %val)
48 ; CHECK: cleanupret from %tok unwind to caller
51 %val = phi i32 [ %x, %invoke1 ], [ %y, %invoke2 ]
52 %tok = cleanuppad within none []
53 call void @use_val(i32 %val)
54 cleanupret from %tok unwind to caller
56 cleanup: ; preds = %invoke.cont15, %if.else, %if.then, %ehcleanup21, %init.suspend
57 %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
58 call void @free(i8* %mem)
62 call i1 @llvm.coro.end(i8* null, i1 false)
69 ; Function Attrs: argmemonly nounwind readonly
70 declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*)
71 declare noalias i8* @malloc(i64)
72 declare i64 @llvm.coro.size.i64()
73 declare i8* @llvm.coro.begin(token, i8* writeonly)
75 ; Function Attrs: nounwind
76 declare token @llvm.coro.save(i8*)
77 declare i8 @llvm.coro.suspend(token, i1)
79 ; Function Attrs: argmemonly nounwind
80 declare void @may_throw1()
81 declare void @may_throw2()
83 declare i8* @__cxa_begin_catch(i8*)
85 declare void @use_val(i32)
86 declare void @__cxa_end_catch()
88 ; Function Attrs: nounwind
89 declare i1 @llvm.coro.end(i8*, i1)
90 declare void @free(i8*)
91 declare i8* @llvm.coro.free(token, i8* nocapture readonly)