|
| 1 | +; Check that the return value of @llvm.coro.suspend gets spilled to the frame |
| 2 | +; if it may be used across suspend points. |
| 3 | +; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s |
| 4 | + |
| 5 | + |
| 6 | +; %sp1 should be part of the frame (the i8 value). |
| 7 | +; CHECK: %f.Frame = type { ptr, ptr, i1, i8 } |
| 8 | + |
| 9 | +; If the coro resumes, %sp1 is set to 0. |
| 10 | +; CHECK-LABEL: define{{.*}} void @f.resume |
| 11 | +; CHECK: AfterCoroSuspend: |
| 12 | +; CHECK: %sp1.spill.addr = getelementptr inbounds %f.Frame |
| 13 | +; CHECK: store i8 0, ptr %sp1.spill.addr |
| 14 | + |
| 15 | +; In the coro destroy function, %sp1 is reloaded from the frame. Its value |
| 16 | +; depends on whether the coroutine was resumed or not. |
| 17 | +; CHECK-LABEL: define{{.*}} void @f.destroy |
| 18 | +; CHECK: cleanup: |
| 19 | +; CHECK: %sp1.reload.addr = getelementptr inbounds %f.Frame |
| 20 | +; CHECK: %sp1.reload = load i8, ptr %sp1.reload.addr |
| 21 | +; CHECK: call void @print(i8 %sp1.reload) |
| 22 | + |
| 23 | + |
| 24 | +define ptr @f(i32 %n) presplitcoroutine { |
| 25 | +entry: |
| 26 | + %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null) |
| 27 | + %size = call i32 @llvm.coro.size.i32() |
| 28 | + %alloc = call ptr @malloc(i32 %size) |
| 29 | + %hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc) |
| 30 | + |
| 31 | + %sp1 = call i8 @llvm.coro.suspend(token none, i1 false) |
| 32 | + switch i8 %sp1, label %suspend [i8 0, label %resume1 |
| 33 | + i8 1, label %cleanup] |
| 34 | + |
| 35 | +resume1: |
| 36 | + %sp2 = call i8 @llvm.coro.suspend(token none, i1 false) |
| 37 | + switch i8 %sp2, label %suspend [i8 0, label %resume2 |
| 38 | + i8 1, label %cleanup] |
| 39 | + |
| 40 | +resume2: |
| 41 | + br label %cleanup |
| 42 | + |
| 43 | +cleanup: |
| 44 | + ; This use of %sp1 may cross a suspend point (%sp2). |
| 45 | + call void @print(i8 %sp1) |
| 46 | + |
| 47 | + %mem = call ptr @llvm.coro.free(token %id, ptr %hdl) |
| 48 | + call void @free(ptr %mem) |
| 49 | + br label %suspend |
| 50 | + |
| 51 | +suspend: |
| 52 | + call i1 @llvm.coro.end(ptr %hdl, i1 0, token none) |
| 53 | + ret ptr %hdl |
| 54 | +} |
| 55 | + |
| 56 | + |
| 57 | +declare noalias ptr @malloc(i32) |
| 58 | +declare void @print(i8) |
| 59 | +declare void @free(ptr) |
0 commit comments