1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2;RUN: opt < %s -passes='require<profile-summary>,function(chr,instcombine,simplifycfg)' -S | FileCheck %s 3 4declare void @foo() 5declare void @bar() 6 7declare token @llvm.coro.id(i32, ptr, ptr, ptr) 8declare i1 @llvm.coro.alloc(token) 9declare ptr @llvm.coro.begin(token, ptr) 10declare noalias ptr @malloc(i32) 11 12%f.Frame = type { ptr, ptr, i1 } 13 14; resume part of the coroutine 15define fastcc void @f.resume(ptr noalias nonnull align 8 dereferenceable(24) %FramePtr) { 16 tail call void @bar() 17 ret void 18} 19 20; destroy part of the coroutine 21define fastcc void @f.destroy(ptr noalias nonnull align 8 dereferenceable(24) %FramePtr) { 22 tail call void @bar() 23 ret void 24} 25 26; cleanup part of the coroutine 27define fastcc void @f.cleanup(ptr noalias nonnull align 8 dereferenceable(24) %FramePtr) { 28 tail call void @bar() 29 ret void 30} 31 32@f.resumers = private constant [3 x ptr] [ptr @f.resume, ptr @f.destroy, ptr @f.cleanup] 33 34; Test that chr will skip block containing llvm.coro.id. 35define ptr @test_chr_with_coro_id(ptr %i) !prof !14 { 36; CHECK-LABEL: @test_chr_with_coro_id( 37; CHECK-NEXT: entry: 38; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[I:%.*]], align 4 39; CHECK-NEXT: [[DOTFR1:%.*]] = freeze i32 [[TMP0]] 40; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[DOTFR1]], 3 41; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 3 42; CHECK-NEXT: br i1 [[TMP2]], label [[BB0:%.*]], label [[ENTRY_SPLIT_NONCHR:%.*]], !prof [[PROF15:![0-9]+]] 43; CHECK: bb0: 44; CHECK-NEXT: call void @foo() 45; CHECK-NEXT: br label [[BB_CORO_ID:%.*]] 46; CHECK: entry.split.nonchr: 47; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[DOTFR1]], 1 48; CHECK-NEXT: [[DOTNOT:%.*]] = icmp eq i32 [[TMP3]], 0 49; CHECK-NEXT: br i1 [[DOTNOT]], label [[BB1_NONCHR:%.*]], label [[BB0_NONCHR:%.*]], !prof [[PROF16:![0-9]+]] 50; CHECK: bb0.nonchr: 51; CHECK-NEXT: call void @foo() 52; CHECK-NEXT: br label [[BB1_NONCHR]] 53; CHECK: bb1.nonchr: 54; CHECK-NEXT: [[TMP4:%.*]] = and i32 [[DOTFR1]], 2 55; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[TMP4]], 0 56; CHECK-NEXT: br i1 [[TMP5]], label [[BB2_NONCHR:%.*]], label [[BB_CORO_ID]], !prof [[PROF16]] 57; CHECK: bb2.nonchr: 58; CHECK-NEXT: call void @foo() 59; CHECK-NEXT: br label [[BB_CORO_ID]] 60; CHECK: bb.coro.id: 61; CHECK-NEXT: [[ID:%.*]] = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr nonnull @f.resumers) 62; CHECK-NEXT: [[NEED_DYN_ALLOC:%.*]] = call i1 @llvm.coro.alloc(token [[ID]]) 63; CHECK-NEXT: br i1 [[NEED_DYN_ALLOC]], label [[BB_CORO_DYN_ALLOC:%.*]], label [[BB_CORO_BEGIN:%.*]] 64; CHECK: bb.coro.dyn.alloc: 65; CHECK-NEXT: [[ALLOC:%.*]] = call ptr @malloc(i32 24) 66; CHECK-NEXT: br label [[BB_CORO_BEGIN]] 67; CHECK: bb.coro.begin: 68; CHECK-NEXT: [[PHI:%.*]] = phi ptr [ null, [[BB_CORO_ID]] ], [ [[ALLOC]], [[BB_CORO_DYN_ALLOC]] ] 69; CHECK-NEXT: [[HDL:%.*]] = call noalias nonnull ptr @llvm.coro.begin(token [[ID]], ptr [[PHI]]) 70; CHECK-NEXT: ret ptr [[HDL]] 71; 72entry: 73 %0 = load i32, ptr %i 74 %1 = and i32 %0, 1 75 %2 = icmp eq i32 %1, 0 76 br i1 %2, label %bb1, label %bb0, !prof !15 77 78bb0: 79 call void @foo() 80 br label %bb1 81 82bb1: 83 %3 = and i32 %0, 2 84 %4 = icmp eq i32 %3, 0 85 br i1 %4, label %bb2, label %bb.coro.id, !prof !15 86 87bb2: 88 call void @foo() 89 br label %bb.coro.id 90 91bb.coro.id: 92 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr @f.resumers) 93 %need.dyn.alloc = call i1 @llvm.coro.alloc(token %id) 94 br i1 %need.dyn.alloc, label %bb.coro.dyn.alloc, label %bb.coro.begin 95 96bb.coro.dyn.alloc: 97 %alloc = call ptr @malloc(i32 24) 98 br label %bb.coro.begin 99 100bb.coro.begin: 101 %phi = phi ptr [ null, %bb.coro.id ], [ %alloc, %bb.coro.dyn.alloc ] 102 %hdl = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %phi) 103 ret ptr %hdl 104} 105 106!llvm.module.flags = !{!0} 107!0 = !{i32 1, !"ProfileSummary", !1} 108!1 = !{!2, !3, !4, !5, !6, !7, !8, !9} 109!2 = !{!"ProfileFormat", !"InstrProf"} 110!3 = !{!"TotalCount", i64 10000} 111!4 = !{!"MaxCount", i64 10} 112!5 = !{!"MaxInternalCount", i64 1} 113!6 = !{!"MaxFunctionCount", i64 1000} 114!7 = !{!"NumCounts", i64 3} 115!8 = !{!"NumFunctions", i64 3} 116!9 = !{!"DetailedSummary", !10} 117!10 = !{!11, !12, !13} 118!11 = !{i32 10000, i64 100, i32 1} 119!12 = !{i32 999000, i64 100, i32 1} 120!13 = !{i32 999999, i64 1, i32 2} 121 122!14 = !{!"function_entry_count", i64 100} 123!15 = !{!"branch_weights", i32 0, i32 1} 124!16 = !{!"branch_weights", i32 1, i32 1} 125!17 = !{!"branch_weights", i32 0, i32 0} 126; CHECK: !15 = !{!"branch_weights", i32 1000, i32 0} 127; CHECK: !16 = !{!"branch_weights", i32 0, i32 1} 128