xref: /llvm-project/llvm/test/Transforms/PGOProfile/instrprof_burst_sampling_fast.ll (revision b4fcaa137f057e68a9011b26c11627a16a8c9374)
1; RUN: opt < %s --passes=instrprof --sampled-instrumentation -S | FileCheck %s --check-prefixes=SAMPLE-VAR,SAMPLE-CODE,SAMPLE-DURATION,SAMPLE-WEIGHT
2; RUN: opt < %s --passes=instrprof --sampled-instrumentation --sampled-instr-burst-duration=100 -S | FileCheck %s --check-prefixes=SAMPLE-VAR,SAMPLE-CODE,SAMPLE-DURATION100,SAMPLE-WEIGHT100
3; RUN: opt < %s --passes=instrprof --sampled-instrumentation --sampled-instr-burst-duration=65536 -S | FileCheck %s --check-prefixes=SAMPLE-VAR,SAMPLE-CODE,UNSAMPLED-DURATION,UNSAMPLED-WEIGHT
4
5target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6target triple = "x86_64-unknown-linux-gnu"
7
8$__llvm_profile_raw_version = comdat any
9
10; SAMPLE-VAR: $__llvm_profile_sampling = comdat any
11
12@__llvm_profile_raw_version = constant i64 72057594037927940, comdat
13@__profn_f = private constant [1 x i8] c"f"
14
15; SAMPLE-VAR: @__llvm_profile_sampling = thread_local global i16 0, comdat
16; SAMPLE-VAR: @__profc_f = private global [1 x i64] zeroinitializer, section "__llvm_prf_cnts", comdat, align 8
17; SAMPLE-VAR: @__profd_f = private global { i64, i64, i64, i64, ptr, ptr, i32, [3 x i16], i32 } { i64 -3706093650706652785, i64 12884901887, i64 sub (i64 ptrtoint (ptr @__profc_f to i64), i64 ptrtoint (ptr @__profd_f to i64)), i64 0, ptr @f.local, ptr null, i32 1, [3 x i16] zeroinitializer, i32 0 }, section "__llvm_prf_data", comdat($__profc_f), align 8
18; SAMPLE-VAR: @__llvm_prf_nm = private constant {{.*}}, section "__llvm_prf_names", align 1
19; SAMPLE-VAR: @llvm.compiler.used = appending global [2 x ptr] [ptr @__llvm_profile_sampling, ptr @__profd_f], section "llvm.metadata"
20; SAMPLE-VAR: @llvm.used = appending global [1 x ptr] [ptr @__llvm_prf_nm], section "llvm.metadata"
21
22
23define void @f() {
24; SAMPLE-CODE-LABEL: @f(
25; SAMPLE-CODE:  entry:
26; SAMPLE-CODE-NEXT:    [[TMP0:%.*]] = load i16, ptr @__llvm_profile_sampling, align 2
27; SAMPLE-DURATION:         [[TMP1:%.*]] = icmp ule i16 [[TMP0]], 199
28; SAMPLE-DURATION100:     [[TMP1:%.*]] = icmp ule i16 [[TMP0]], 99
29; UNSAMPLED-DURATION:     [[TMP1:%.*]] = icmp ule i16 [[TMP0]], -1
30; SAMPLE-CODE:         br i1 [[TMP1]], label %[[TMP2:.*]], label %[[TMP4:.*]], !prof !0
31; SAMPLE-CODE:       [[TMP2]]:
32; SAMPLE-CODE-NEXT:    [[PGOCOUNT:%.*]] = load i64, ptr @__profc_f
33; SAMPLE-CODE-NEXT:    [[TMP3:%.*]] = add i64 [[PGOCOUNT]], 1
34; SAMPLE-CODE-NEXT:    store i64 [[TMP3]], ptr @__profc_f
35; SAMPLE-CODE-NEXT:    br label %[[TMP4]]
36; SAMPLE-CODE:       [[TMP4]]:
37; SAMPLE-CODE-NEXT:    [[TMP5:%.*]] = add i16 [[TMP0]], 1
38; SAMPLE-CODE-NEXT:    store i16 [[TMP5]],  ptr @__llvm_profile_sampling, align 2
39; SAMPLE-CODE-NEXT:    ret void
40;
41entry:
42  call void @llvm.instrprof.increment(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @__profn_f, i32 0, i32 0), i64 12884901887, i32 1, i32 0)
43  ret void
44}
45
46; SAMPLE-WEIGHT: !0 = !{!"branch_weights", i32 200, i32 65336}
47; SAMPLE-WEIGHT100: !0 = !{!"branch_weights", i32 100, i32 65436}
48; UNSAMPLED-WEIGHT: !0 = !{!"branch_weights", i32 65536, i32 0}
49
50declare void @llvm.instrprof.increment(i8*, i64, i32, i32)
51