1 ; RUN: opt < %s --passes=pgo-instr-gen,instrprof --do-counter-promotion=true --sampled-instrumentation=true --skip-ret-exit-block=0 -S | FileCheck --check-prefixes=SAMPLING,PROMO %s
3 ; SAMPLING: $__llvm_profile_sampling = comdat any
4 ; SAMPLING: @__llvm_profile_sampling = thread_local global i16 0, comdat
6 define void @foo(i32 %n, i32 %N) {
8 ; SAMPLING: %[[VV0:[0-9]+]] = load i16, ptr @__llvm_profile_sampling, align 2
9 ; SAMPLING: %[[VV1:[0-9]+]] = icmp ule i16 %[[VV0]], 200
10 ; SAMPLING: br i1 %[[VV1]], label {{.*}}, label {{.*}}, !prof !0
11 ; SAMPLING: {{.*}} = load {{.*}} @__profc_foo{{.*}} 3)
13 ; SAMPLING-NEXT: store {{.*}}@__profc_foo{{.*}}3)
15 %tmp = add nsw i32 %n, 1
16 %tmp1 = add nsw i32 %n, -1
21 ; PROMO-NEXT: phi {{.*}}
22 ; PROMO-NEXT: phi {{.*}}
23 ; PROMO-NEXT: phi {{.*}}
24 %i.0 = phi i32 [ 0, %bb ], [ %tmp10, %bb9 ]
25 %tmp3 = icmp slt i32 %i.0, %tmp
26 br i1 %tmp3, label %bb4, label %bb5
29 tail call void @bar(i32 1)
33 %tmp6 = icmp slt i32 %i.0, %tmp1
34 br i1 %tmp6, label %bb7, label %bb8
37 tail call void @bar(i32 2)
41 tail call void @bar(i32 3)
45 ; SAMPLING: phi {{.*}}
46 ; SAMPLING-NEXT: %[[V1:[0-9]+]] = add i16 {{.*}}, 1
47 ; SAMPLING-NEXT: store i16 %[[V1]], ptr @__llvm_profile_sampling, align 2
48 ; SAMPLING: phi {{.*}}
49 ; SAMPLING-NEXT: %[[V2:[0-9]+]] = add i16 {{.*}}, 1
50 ; SAMPLING-NEXT: store i16 %[[V2]], ptr @__llvm_profile_sampling, align 2
51 ; SAMPLING: phi {{.*}}
52 ; SAMPLING-NEXT: %[[V3:[0-9]+]] = add i16 {{.*}}, 1
53 ; SAMPLING-NEXT: store i16 %[[V3]], ptr @__llvm_profile_sampling, align 2
54 ; PROMO: %[[LIVEOUT3:[a-z0-9]+]] = phi {{.*}}
55 ; PROMO-NEXT: %[[LIVEOUT2:[a-z0-9]+]] = phi {{.*}}
56 ; PROMO-NEXT: %[[LIVEOUT1:[a-z0-9]+]] = phi {{.*}}
57 %tmp10 = add nsw i32 %i.0, 1
58 %tmp11 = icmp slt i32 %tmp10, %N
59 br i1 %tmp11, label %bb2, label %bb12
63 ; PROMO: %[[CHECK1:[a-z0-9.]+]] = load {{.*}} @__profc_foo{{.*}}
64 ; PROMO-NEXT: add {{.*}} %[[CHECK1]], %[[LIVEOUT1]]
65 ; PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}
66 ; PROMO-NEXT: %[[CHECK2:[a-z0-9.]+]] = load {{.*}} @__profc_foo{{.*}} 1)
67 ; PROMO-NEXT: add {{.*}} %[[CHECK2]], %[[LIVEOUT2]]
68 ; PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}1)
69 ; PROMO-NEXT: %[[CHECK3:[a-z0-9.]+]] = load {{.*}} @__profc_foo{{.*}} 2)
70 ; PROMO-NEXT: add {{.*}} %[[CHECK3]], %[[LIVEOUT3]]
71 ; PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}2)
72 ; PROMO-NOT: @__profc_foo{{.*}})
76 declare void @bar(i32)
78 ; SAMPLING: !0 = !{!"branch_weights", i32 200, i32 65336}