blob: 0ad96eba1e48e763d5584d6c29ab89ae87d0ca03 [file] [log] [blame]
; Tests that coro-split will optimize the lifetime.start maker of each local variable,
; sink them to the places after the suspend block.
; RUN: opt < %s -coro-split -S | FileCheck %s
; RUN: opt < %s -passes=coro-split -S | FileCheck %s
%"struct.std::coroutine_handle" = type { i8* }
%"struct.std::coroutine_handle.0" = type { %"struct.std::coroutine_handle" }
%"struct.lean_future<int>::Awaiter" = type { i32, %"struct.std::coroutine_handle.0" }
declare i8* @malloc(i64)
declare void @print(i32)
declare void @consume.i8(i8)
define void @a() "coroutine.presplit"="1" {
%ref.tmp7 = alloca %"struct.lean_future<int>::Awaiter", align 8
%testval = alloca i8
; lifetime of %testval starts here, but not used until await.ready.
call void @llvm.lifetime.start.p0i8(i64 1, i8* %testval)
%id = call token 0, i8* null, i8* null, i8* null)
%alloc = call i8* @malloc(i64 16) #3
%vFrame = call noalias nonnull i8* @llvm.coro.begin(token %id, i8* %alloc)
%save = call token* null)
%Result.i19 = getelementptr inbounds %"struct.lean_future<int>::Awaiter", %"struct.lean_future<int>::Awaiter"* %ref.tmp7, i64 0, i32 0
%suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
switch i8 %suspend, label %exit [
i8 0, label %await.ready
i8 1, label %exit
%StrayCoroSave = call token* null)
%val = load i32, i32* %Result.i19
%test = load i8, i8* %testval
call void @consume.i8(i8 %test)
call void @llvm.lifetime.end.p0i8(i64 1, i8* %testval)
call void @print(i32 %val)
br label %exit
call i1 @llvm.coro.end(i8* null, i1 false)
ret void
; CHECK-LABEL: @a.resume(
; CHECK: %testval = alloca i8, align 1
; CHECK-NEXT: getelementptr inbounds %a.Frame
; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 1, i8* %testval)
; CHECK-NEXT: getelementptr inbounds %"struct.lean_future<int>::Awaiter"
; CHECK-NEXT: %val = load i32, i32* %Result
; CHECK-NEXT: %test = load i8, i8* %testval
; CHECK-NEXT: call void @consume.i8(i8 %test)
; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 1, i8* %testval)
; CHECK-NEXT: call void @print(i32 %val)
; CHECK-NEXT: ret void
declare token, i8* readnone, i8* nocapture readonly, i8*)
declare i1 @llvm.coro.alloc(token) #3
declare noalias nonnull i8* @"\01??2@YAPEAX_K@Z"(i64) local_unnamed_addr
declare i64 @llvm.coro.size.i64() #5
declare i8* @llvm.coro.begin(token, i8* writeonly) #3
declare void @"\01?puts@@YAXZZ"(...)
declare token*) #3
declare i8* @llvm.coro.frame() #5
declare i8 @llvm.coro.suspend(token, i1) #3
declare void @"\01??3@YAXPEAX@Z"(i8*) local_unnamed_addr #10
declare i8*, i8* nocapture readonly) #2
declare i1 @llvm.coro.end(i8*, i1) #3
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #4
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #4