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
7 declare token @llvm.coro.id(i32, ptr, ptr, ptr)
8 declare i1 @llvm.coro.alloc(token)
9 declare ptr @llvm.coro.begin(token, ptr)
10 declare noalias ptr @malloc(i32)
12 %f.Frame = type { ptr, ptr, i1 }
14 ; resume part of the coroutine
15 define fastcc void @f.resume(ptr noalias nonnull align 8 dereferenceable(24) %FramePtr) {
20 ; destroy part of the coroutine
21 define fastcc void @f.destroy(ptr noalias nonnull align 8 dereferenceable(24) %FramePtr) {
26 ; cleanup part of the coroutine
27 define fastcc void @f.cleanup(ptr noalias nonnull align 8 dereferenceable(24) %FramePtr) {
32 @f.resumers = private constant [3 x ptr] [ptr @f.resume, ptr @f.destroy, ptr @f.cleanup]
34 ; Test that chr will skip block containing llvm.coro.id.
35 define ptr @test_chr_with_coro_id(ptr %i) !prof !14 {
36 ; CHECK-LABEL: @test_chr_with_coro_id(
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]+]]
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]+]]
51 ; CHECK-NEXT: call void @foo()
52 ; CHECK-NEXT: br label [[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]]
58 ; CHECK-NEXT: call void @foo()
59 ; CHECK-NEXT: br label [[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]]
75 %2 = icmp eq i32 %1, 0
76 br i1 %2, label %bb1, label %bb0, !prof !15
84 %4 = icmp eq i32 %3, 0
85 br i1 %4, label %bb2, label %bb.coro.id, !prof !15
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
97 %alloc = call ptr @malloc(i32 24)
98 br label %bb.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)
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}
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}