82 lines · plain
1; Tests that coro-split removes cleanup code after coro.end in resume functions2; and retains it in the start function.3; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s4 5define ptr @f2(i1 %val) presplitcoroutine personality i32 4 {6entry:7 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)8 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)9 call void @print(i32 0)10 br i1 %val, label %resume, label %susp11 12susp:13 %0 = call i8 @llvm.coro.suspend(token none, i1 false)14 switch i8 %0, label %suspend [i8 0, label %resume15 i8 1, label %suspend]16resume:17 invoke void @print(i32 1) to label %suspend unwind label %lpad18 19suspend:20 call void @llvm.coro.end(ptr %hdl, i1 0, token none)21 call void @print(i32 0) ; should not be present in f.resume22 ret ptr %hdl23 24lpad:25 %tok = cleanuppad within none []26 call void @print(i32 2)27 call void @llvm.coro.end(ptr null, i1 true, token none) [ "funclet"(token %tok) ]28 cleanupret from %tok unwind label %cleanup.cont29 30cleanup.cont:31 %tok2 = cleanuppad within none []32 call void @print(i32 3) ; should not be present in f.resume33 cleanupret from %tok2 unwind to caller34}35 36; Verify that start function contains both print calls the one before and after coro.end37; CHECK-LABEL: define ptr @f2(38; CHECK: invoke void @print(i32 1)39; CHECK: to label %AfterCoroEnd unwind label %lpad40 41; CHECK: AfterCoroEnd:42; CHECK: call void @print(i32 0)43; CHECK: ret ptr %hdl44 45; CHECK: lpad:46; CHECK-NEXT: %tok = cleanuppad within none []47; CHECK-NEXT: call void @print(i32 2)48; CHECK-NEXT: call void @print(i32 3)49; CHECK-NEXT: cleanupret from %tok unwind to caller50 51; VERIFY Resume Parts52 53; Verify that resume function does not contains both print calls appearing after coro.end54; CHECK-LABEL: define internal fastcc void @f2.resume55; CHECK: invoke void @print(i32 1)56; CHECK: to label %CoroEnd unwind label %lpad57 58; CHECK: CoroEnd:59; CHECK-NEXT: ret void60 61; CHECK: lpad:62; CHECK-NEXT: %tok = cleanuppad within none []63; CHECK-NEXT: call void @print(i32 2)64; Checks that the coroutine would be marked as done if it exits in unwinding path.65; CHECK-NEXT: store ptr null, ptr %hdl, align 866; CHECK-NEXT: cleanupret from %tok unwind to caller67 68declare ptr @llvm.coro.free(token, ptr)69declare i32 @llvm.coro.size.i32()70declare i8 @llvm.coro.suspend(token, i1)71declare void @llvm.coro.resume(ptr)72declare void @llvm.coro.destroy(ptr)73 74declare token @llvm.coro.id(i32, ptr, ptr, ptr)75declare ptr @llvm.coro.alloc(token)76declare ptr @llvm.coro.begin(token, ptr)77declare void @llvm.coro.end(ptr, i1, token)78 79declare noalias ptr @malloc(i32)80declare void @print(i32)81declare void @free(ptr)82