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 6 7define ptr @f() presplitcoroutine { 8entry: 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 16 i8 1, label %cleanup] 17resume: 18 %i = call i32 @readnone_func() readnone 19 %cmp = icmp eq i32 %i, %j 20 br i1 %cmp, label %same, label %diff 21 22same: 23 call void @print_same() 24 br label %cleanup 25 26diff: 27 call void @print_diff() 28 br label %cleanup 29 30cleanup: 31 %mem = call ptr @llvm.coro.free(token %id, ptr %hdl) 32 call void @free(ptr %mem) 33 br label %suspend 34 35suspend: 36 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none) 37 ret ptr %hdl 38} 39 40; Tests that normal functions wouldn't be affected. 41define i1 @normal_function() { 42entry: 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 47 48same: 49 call void @print_same() 50 ret i1 true 51 52diff: 53 call void @print_diff() 54 ret i1 false 55} 56 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 62; 63; CHECK_SPLITTED-LABEL: f.resume( 64; CHECK_UNSPLITTED-LABEL: @f( 65; CHECK: br i1 %cmp, label %same, label %diff 66; CHECK-EMPTY: 67; CHECK-NEXT: same: 68; CHECK-NEXT: call void @print_same() 69; CHECK-NEXT: br label 70; CHECK-EMPTY: 71; CHECK-NEXT: diff: 72; CHECK-NEXT: call void @print_diff() 73; CHECK-NEXT: br label 74 75declare i32 @readnone_func() readnone 76 77declare void @print_same() 78declare void @print_diff() 79declare ptr @llvm.coro.free(token, ptr) 80declare i32 @llvm.coro.size.i32() 81declare i8 @llvm.coro.suspend(token, i1) 82 83declare token @llvm.coro.id(i32, ptr, ptr, ptr) 84declare i1 @llvm.coro.alloc(token) 85declare ptr @llvm.coro.begin(token, ptr) 86declare i1 @llvm.coro.end(ptr, i1, token) 87 88declare noalias ptr @malloc(i32) 89declare void @free(ptr) 90