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 2 3; SAMPLING: $__llvm_profile_sampling = comdat any 4; SAMPLING: @__llvm_profile_sampling = thread_local global i16 0, comdat 5 6define void @foo(i32 %n, i32 %N) { 7; SAMPLING-LABEL: @foo 8; SAMPLING: %[[VV0:[0-9]+]] = load i16, ptr @__llvm_profile_sampling, align 2 9; SAMPLING: %[[VV1:[0-9]+]] = icmp ule i16 %[[VV0]], 199 10; SAMPLING: br i1 %[[VV1]], label {{.*}}, label {{.*}}, !prof !0 11; SAMPLING: {{.*}} = load {{.*}} @__profc_foo{{.*}} 3) 12; SAMPLING-NEXT: add 13; SAMPLING-NEXT: store {{.*}}@__profc_foo{{.*}}3) 14bb: 15 %tmp = add nsw i32 %n, 1 16 %tmp1 = add nsw i32 %n, -1 17 br label %bb2 18 19bb2: 20; PROMO: phi {{.*}} 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 27 28bb4: 29 tail call void @bar(i32 1) 30 br label %bb9 31 32bb5: 33 %tmp6 = icmp slt i32 %i.0, %tmp1 34 br i1 %tmp6, label %bb7, label %bb8 35 36bb7: 37 tail call void @bar(i32 2) 38 br label %bb9 39 40bb8: 41 tail call void @bar(i32 3) 42 br label %bb9 43 44bb9: 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 60 61bb12: 62 ret void 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{{.*}}) 73 74} 75 76declare void @bar(i32) 77 78; SAMPLING: !0 = !{!"branch_weights", i32 200, i32 65336} 79