1 ; Tests that the readnone function which cross suspend points wouldn't be misoptimized.
2 ; RUN: opt < %s -S -passes='default<O3>' | FileCheck %s --check-prefixes=CHECK,CHECK_SPLITTED
3 ; RUN: opt < %s -S -passes='early-cse' | FileCheck %s --check-prefixes=CHECK,CHECK_UNSPLITTED
4 ; RUN: opt < %s -S -passes='gvn' | FileCheck %s --check-prefixes=CHECK,CHECK_UNSPLITTED
5 ; RUN: opt < %s -S -passes='newgvn' | FileCheck %s --check-prefixes=CHECK,CHECK_UNSPLITTED
7 define ptr @f() presplitcoroutine {
9 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
10 %size = call i32 @llvm.coro.size.i32()
11 %alloc = call ptr @malloc(i32 %size)
12 %hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc)
13 %j = call i32 @readnone_func() readnone
14 %sus_result = call i8 @llvm.coro.suspend(token none, i1 false)
15 switch i8 %sus_result, label %suspend [i8 0, label %resume
18 %i = call i32 @readnone_func() readnone
19 %cmp = icmp eq i32 %i, %j
20 br i1 %cmp, label %same, label %diff
23 call void @print_same()
27 call void @print_diff()
31 %mem = call ptr @llvm.coro.free(token %id, ptr %hdl)
32 call void @free(ptr %mem)
36 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
40 ; Tests that normal functions wouldn't be affected.
41 define i1 @normal_function() {
43 %i = call i32 @readnone_func() readnone
44 %j = call i32 @readnone_func() readnone
45 %cmp = icmp eq i32 %i, %j
46 br i1 %cmp, label %same, label %diff
49 call void @print_same()
53 call void @print_diff()
57 ; CHECK_SPLITTED-LABEL: normal_function(
58 ; CHECK_SPLITTED-NEXT: entry
59 ; CHECK_SPLITTED-NEXT: call i32 @readnone_func()
60 ; CHECK_SPLITTED-NEXT: call void @print_same()
61 ; CHECK_SPLITTED-NEXT: ret i1 true
63 ; CHECK_SPLITTED-LABEL: f.resume(
64 ; CHECK_UNSPLITTED-LABEL: @f(
65 ; CHECK: br i1 %cmp, label %same, label %diff
68 ; CHECK-NEXT: call void @print_same()
69 ; CHECK-NEXT: br label
72 ; CHECK-NEXT: call void @print_diff()
73 ; CHECK-NEXT: br label
75 declare i32 @readnone_func() readnone
77 declare void @print_same()
78 declare void @print_diff()
79 declare ptr @llvm.coro.free(token, ptr)
80 declare i32 @llvm.coro.size.i32()
81 declare i8 @llvm.coro.suspend(token, i1)
83 declare token @llvm.coro.id(i32, ptr, ptr, ptr)
84 declare i1 @llvm.coro.alloc(token)
85 declare ptr @llvm.coro.begin(token, ptr)
86 declare i1 @llvm.coro.end(ptr, i1, token)
88 declare noalias ptr @malloc(i32)
89 declare void @free(ptr)