| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --include-generated-funcs --version 6 |
| ; Check that we can handle edge splits leading into a landingpad. |
| ; Verify that we create cleanuppads on every edge and insert a reload of the spilled value. |
| ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s |
| |
| target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| target triple = "x86_64-unknown-linux-gnu" |
| |
| define void @h(i1 %cond, i32 %x, i32 %y) presplitcoroutine personality i32 0 { |
| entry: |
| %id = call token @llvm.coro.id(i32 16, ptr null, ptr @h, ptr null) |
| %size = tail call i64 @llvm.coro.size.i64() |
| %alloc = call ptr @malloc(i64 %size) |
| %hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc) |
| %sp = call i8 @llvm.coro.suspend(token none, i1 false) |
| switch i8 %sp, label %coro.ret [ |
| i8 0, label %resume |
| i8 1, label %cleanup |
| ] |
| |
| resume: |
| br i1 %cond, label %invoke1, label %invoke2 |
| |
| invoke1: |
| invoke void @may_throw1() |
| to label %coro.ret unwind label %pad.with.phi |
| invoke2: |
| invoke void @may_throw2() |
| to label %coro.ret unwind label %pad.with.phi |
| |
| pad.with.phi: |
| %val = phi i32 [ %x, %invoke1 ], [ %y, %invoke2 ] |
| %switch = catchswitch within none [label %catch] unwind to caller |
| |
| catch: ; preds = %catch.dispatch |
| %pad = catchpad within %switch [ptr null, i32 64, ptr null] |
| call void @use_val(i32 %val) |
| catchret from %pad to label %coro.ret |
| |
| cleanup: ; preds = %invoke.cont15, %if.else, %if.then, %ehcleanup21, %init.suspend |
| %mem = call ptr @llvm.coro.free(token %id, ptr %hdl) |
| call void @free(ptr %mem) |
| br label %coro.ret |
| |
| coro.ret: |
| call void @llvm.coro.end(ptr null, i1 false, token none) |
| ret void |
| } |
| |
| ; Function Attrs: argmemonly nounwind readonly |
| declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) |
| declare noalias ptr @malloc(i64) |
| declare i64 @llvm.coro.size.i64() |
| declare ptr @llvm.coro.begin(token, ptr writeonly) |
| |
| ; Function Attrs: nounwind |
| declare token @llvm.coro.save(ptr) |
| declare i8 @llvm.coro.suspend(token, i1) |
| |
| ; Function Attrs: argmemonly nounwind |
| declare void @may_throw1() |
| declare void @may_throw2() |
| |
| declare ptr @__cxa_begin_catch(ptr) |
| |
| declare void @use_val(i32) |
| declare void @__cxa_end_catch() |
| |
| ; Function Attrs: nounwind |
| declare void @llvm.coro.end(ptr, i1, token) |
| declare void @free(ptr) |
| declare ptr @llvm.coro.free(token, ptr nocapture readonly) |
| ; CHECK-LABEL: define void @h( |
| ; CHECK-SAME: i1 [[COND:%.*]], i32 [[X:%.*]], i32 [[Y:%.*]]) personality i32 0 { |
| ; CHECK-NEXT: [[ENTRY:.*:]] |
| ; CHECK-NEXT: [[ID:%.*]] = call token @llvm.coro.id(i32 16, ptr null, ptr @h, ptr @h.resumers) |
| ; CHECK-NEXT: [[ALLOC:%.*]] = call ptr @malloc(i64 32) |
| ; CHECK-NEXT: [[HDL:%.*]] = call noalias nonnull ptr @llvm.coro.begin(token [[ID]], ptr [[ALLOC]]) |
| ; CHECK-NEXT: store ptr @h.resume, ptr [[HDL]], align 8 |
| ; CHECK-NEXT: [[DESTROY_ADDR:%.*]] = getelementptr inbounds i8, ptr [[HDL]], i64 8 |
| ; CHECK-NEXT: store ptr @h.destroy, ptr [[DESTROY_ADDR]], align 8 |
| ; CHECK-NEXT: [[Y_SPILL_ADDR:%.*]] = getelementptr inbounds i8, ptr [[HDL]], i64 20 |
| ; CHECK-NEXT: store i32 [[Y]], ptr [[Y_SPILL_ADDR]], align 4 |
| ; CHECK-NEXT: [[X_SPILL_ADDR:%.*]] = getelementptr inbounds i8, ptr [[HDL]], i64 16 |
| ; CHECK-NEXT: store i32 [[X]], ptr [[X_SPILL_ADDR]], align 4 |
| ; CHECK-NEXT: [[COND_SPILL_ADDR:%.*]] = getelementptr inbounds i8, ptr [[HDL]], i64 25 |
| ; CHECK-NEXT: store i1 [[COND]], ptr [[COND_SPILL_ADDR]], align 1 |
| ; CHECK-NEXT: [[INDEX_ADDR1:%.*]] = getelementptr inbounds i8, ptr [[HDL]], i64 24 |
| ; CHECK-NEXT: store i1 false, ptr [[INDEX_ADDR1]], align 1 |
| ; CHECK-NEXT: ret void |
| ; |
| ; |
| ; CHECK-LABEL: define internal fastcc void @h.resume( |
| ; CHECK-SAME: ptr noundef nonnull align 8 dereferenceable(32) [[HDL:%.*]]) personality i32 0 { |
| ; CHECK-NEXT: [[ENTRY_RESUME:.*:]] |
| ; CHECK-NEXT: [[COND_RELOAD_ADDR:%.*]] = getelementptr inbounds i8, ptr [[HDL]], i64 25 |
| ; CHECK-NEXT: [[COND_RELOAD:%.*]] = load i1, ptr [[COND_RELOAD_ADDR]], align 1 |
| ; CHECK-NEXT: br i1 [[COND_RELOAD]], label %[[INVOKE1:.*]], label %[[INVOKE2:.*]] |
| ; CHECK: [[INVOKE1]]: |
| ; CHECK-NEXT: invoke void @may_throw1() |
| ; CHECK-NEXT: to label %[[COROEND:.*]] unwind label %[[PAD_WITH_PHI_FROM_INVOKE1:.*]] |
| ; CHECK: [[INVOKE2]]: |
| ; CHECK-NEXT: invoke void @may_throw2() |
| ; CHECK-NEXT: to label %[[COROEND]] unwind label %[[PAD_WITH_PHI_FROM_INVOKE2:.*]] |
| ; CHECK: [[PAD_WITH_PHI_FROM_INVOKE2]]: |
| ; CHECK-NEXT: [[TMP0:%.*]] = cleanuppad within none [] |
| ; CHECK-NEXT: [[Y_RELOAD_ADDR:%.*]] = getelementptr inbounds i8, ptr [[HDL]], i64 20 |
| ; CHECK-NEXT: [[Y_RELOAD:%.*]] = load i32, ptr [[Y_RELOAD_ADDR]], align 4 |
| ; CHECK-NEXT: cleanupret from [[TMP0]] unwind label %[[PAD_WITH_PHI:.*]] |
| ; CHECK: [[PAD_WITH_PHI_FROM_INVOKE1]]: |
| ; CHECK-NEXT: [[TMP1:%.*]] = cleanuppad within none [] |
| ; CHECK-NEXT: [[X_RELOAD_ADDR:%.*]] = getelementptr inbounds i8, ptr [[HDL]], i64 16 |
| ; CHECK-NEXT: [[X_RELOAD:%.*]] = load i32, ptr [[X_RELOAD_ADDR]], align 4 |
| ; CHECK-NEXT: cleanupret from [[TMP1]] unwind label %[[PAD_WITH_PHI]] |
| ; CHECK: [[PAD_WITH_PHI]]: |
| ; CHECK-NEXT: [[VAL:%.*]] = phi i32 [ [[X_RELOAD]], %[[PAD_WITH_PHI_FROM_INVOKE1]] ], [ [[Y_RELOAD]], %[[PAD_WITH_PHI_FROM_INVOKE2]] ] |
| ; CHECK-NEXT: [[SWITCH:%.*]] = catchswitch within none [label %[[CATCH:.*]]] unwind to caller |
| ; CHECK: [[CATCH]]: |
| ; CHECK-NEXT: [[PAD:%.*]] = catchpad within [[SWITCH]] [ptr null, i32 64, ptr null] |
| ; CHECK-NEXT: call void @use_val(i32 [[VAL]]) |
| ; CHECK-NEXT: catchret from [[PAD]] to label %[[COROEND]] |
| ; CHECK: [[COROEND]]: |
| ; CHECK-NEXT: ret void |
| ; |
| ; |
| ; CHECK-LABEL: define internal fastcc void @h.destroy( |
| ; CHECK-SAME: ptr noundef nonnull align 8 dereferenceable(32) [[HDL:%.*]]) personality i32 0 { |
| ; 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 @h.cleanup( |
| ; CHECK-SAME: ptr noundef nonnull align 8 dereferenceable(32) [[HDL:%.*]]) personality i32 0 { |
| ; CHECK-NEXT: [[ENTRY_CLEANUP:.*:]] |
| ; CHECK-NEXT: call void @free(ptr null) |
| ; CHECK-NEXT: ret void |
| ; |