| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --include-generated-funcs --version 6 |
| ; Check that we can handle the case when both alloc function and |
| ; the user body consume the same argument. |
| ; Verify that %this is added to the frame, spilled into the frame, and loaded from the frame. |
| ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s |
| |
| ; using this directly (as it would happen under -O2) |
| define ptr @f_direct(i64 %this) presplitcoroutine { |
| entry: |
| %id = call token @llvm.coro.id(i32 0, ptr null, ptr @f_direct, ptr null) |
| %size = call i32 @llvm.coro.size.i32() |
| %alloc = call ptr @myAlloc(i64 %this, i32 %size) |
| %hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc) |
| %0 = call i8 @llvm.coro.suspend(token none, i1 false) |
| switch i8 %0, label %suspend [i8 0, label %resume |
| i8 1, label %cleanup] |
| resume: |
| call void @print2(i64 %this) |
| br label %cleanup |
| |
| cleanup: |
| %mem = call ptr @llvm.coro.free(token %id, ptr %hdl) |
| call void @free(ptr %mem) |
| br label %suspend |
| suspend: |
| call void @llvm.coro.end(ptr %hdl, i1 0, token none) |
| ret ptr %hdl |
| } |
| |
| declare ptr @llvm.coro.free(token, ptr) |
| declare i32 @llvm.coro.size.i32() |
| declare i8 @llvm.coro.suspend(token, i1) |
| declare void @llvm.coro.resume(ptr) |
| declare void @llvm.coro.destroy(ptr) |
| |
| declare token @llvm.coro.id(i32, ptr, ptr, ptr) |
| declare i1 @llvm.coro.alloc(token) |
| declare ptr @llvm.coro.begin(token, ptr) |
| declare void @llvm.coro.end(ptr, i1, token) |
| |
| declare noalias ptr @myAlloc(i64, i32) |
| declare double @print(double) |
| declare void @print2(i64) |
| declare void @free(ptr) |
| ; CHECK-LABEL: define ptr @f_direct( |
| ; CHECK-SAME: i64 [[THIS:%.*]]) { |
| ; CHECK-NEXT: [[ENTRY:.*:]] |
| ; CHECK-NEXT: [[ID:%.*]] = call token @llvm.coro.id(i32 0, ptr null, ptr @f_direct, ptr @f_direct.resumers) |
| ; CHECK-NEXT: [[ALLOC:%.*]] = call ptr @myAlloc(i64 [[THIS]], i32 32) |
| ; CHECK-NEXT: [[HDL:%.*]] = call noalias nonnull ptr @llvm.coro.begin(token [[ID]], ptr [[ALLOC]]) |
| ; CHECK-NEXT: store ptr @f_direct.resume, ptr [[HDL]], align 8 |
| ; CHECK-NEXT: [[DESTROY_ADDR:%.*]] = getelementptr inbounds i8, ptr [[HDL]], i64 8 |
| ; CHECK-NEXT: store ptr @f_direct.destroy, ptr [[DESTROY_ADDR]], align 8 |
| ; CHECK-NEXT: [[THIS_SPILL_ADDR:%.*]] = getelementptr inbounds i8, ptr [[HDL]], i64 16 |
| ; CHECK-NEXT: store i64 [[THIS]], ptr [[THIS_SPILL_ADDR]], align 4 |
| ; CHECK-NEXT: [[INDEX_ADDR1:%.*]] = getelementptr inbounds i8, ptr [[HDL]], i64 24 |
| ; CHECK-NEXT: store i1 false, ptr [[INDEX_ADDR1]], align 1 |
| ; CHECK-NEXT: ret ptr [[HDL]] |
| ; |
| ; |
| ; CHECK-LABEL: define internal fastcc void @f_direct.resume( |
| ; CHECK-SAME: ptr noundef nonnull align 8 dereferenceable(32) [[HDL:%.*]]) { |
| ; CHECK-NEXT: [[ENTRY_RESUME:.*:]] |
| ; CHECK-NEXT: [[THIS_RELOAD_ADDR:%.*]] = getelementptr inbounds i8, ptr [[HDL]], i64 16 |
| ; CHECK-NEXT: [[THIS_RELOAD:%.*]] = load i64, ptr [[THIS_RELOAD_ADDR]], align 4 |
| ; CHECK-NEXT: call void @print2(i64 [[THIS_RELOAD]]) |
| ; CHECK-NEXT: [[MEM:%.*]] = call ptr @llvm.coro.free(token poison, ptr [[HDL]]) |
| ; CHECK-NEXT: call void @free(ptr [[MEM]]) |
| ; CHECK-NEXT: ret void |
| ; |
| ; |
| ; CHECK-LABEL: define internal fastcc void @f_direct.destroy( |
| ; CHECK-SAME: ptr noundef nonnull align 8 dereferenceable(32) [[HDL:%.*]]) { |
| ; CHECK-NEXT: [[ENTRY_DESTROY:.*:]] |
| ; CHECK-NEXT: [[MEM:%.*]] = call ptr @llvm.coro.free(token poison, ptr [[HDL]]) |
| ; CHECK-NEXT: call void @free(ptr [[MEM]]) |
| ; CHECK-NEXT: ret void |
| ; |
| ; |
| ; CHECK-LABEL: define internal fastcc void @f_direct.cleanup( |
| ; CHECK-SAME: ptr noundef nonnull align 8 dereferenceable(32) [[HDL:%.*]]) { |
| ; CHECK-NEXT: [[ENTRY_CLEANUP:.*:]] |
| ; CHECK-NEXT: call void @free(ptr null) |
| ; CHECK-NEXT: ret void |
| ; |