1// RUN: %clang_profgen -o %t -O3 %s
2// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
3// RUN: llvm-profdata merge -o %t.profdata %t.profraw
4// RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=COMMON --check-prefix=ORIG
5//
6// RUN: rm -fr %t.dir1
7// RUN: mkdir -p %t.dir1
8// RUN: env LLVM_PROFILE_FILE=%t.dir1/profraw_e_%1m %run %t
9// RUN: env LLVM_PROFILE_FILE=%t.dir1/profraw_e_%1m %run %t
10// RUN: llvm-profdata merge -o %t.em.profdata %t.dir1
11// RUN: %clang_profuse=%t.em.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=COMMON --check-prefix=MERGE
12//
13// RUN: rm -fr %t.dir2
14// RUN: mkdir -p %t.dir2
15// RUN: %clang_profgen=%t.dir2/%m.profraw -o %t.merge -O3 %s
16// RUN: %run %t.merge
17// RUN: %run %t.merge
18// RUN: llvm-profdata merge -o %t.m.profdata %t.dir2/
19// RUN: %clang_profuse=%t.m.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=COMMON --check-prefix=MERGE
20//
21// Test that merging is enabled by default with -fprofile-generate=
22// RUN: rm -fr %t.dir3
23// RUN: mkdir -p %t.dir3
24// RUN: %clang_pgogen=%t.dir3/ -o %t.merge3 -O0 %s
25// RUN: %run %t.merge3
26// RUN: %run %t.merge3
27// RUN: %run %t.merge3
28// RUN: %run %t.merge3
29// RUN: llvm-profdata merge -o %t.m3.profdata %t.dir3/
30// RUN: %clang_profuse=%t.m3.profdata -O0 -o - -S -emit-llvm %s | FileCheck %s --check-prefix=COMMON --check-prefix=PGOMERGE
31//
32// Test that merging is enabled by default with -fprofile-generate
33// RUN: rm -fr %t.dir4
34// RUN: mkdir -p %t.dir4
35// RUN: %clang_pgogen -o %t.dir4/merge4 -O0 %s
36// RUN: cd %t.dir4
37// RUN: %run %t.dir4/merge4
38// RUN: %run %t.dir4/merge4
39// RUN: %run %t.dir4/merge4
40// RUN: %run %t.dir4/merge4
41// RUN: rm -f %t.dir4/merge4
42// RUN: llvm-profdata merge -o %t.m4.profdata ./
43// RUN: %clang_profuse=%t.m4.profdata -O0 -o - -S -emit-llvm %s | FileCheck %s --check-prefix=COMMON --check-prefix=PGOMERGE
44
45/// Test that the merge pool size can be larger than 10.
46// RUN: rm -fr %t.dir5
47// RUN: mkdir -p %t.dir5
48// RUN: env LLVM_PROFILE_FILE=%t.dir5/e_%20m.profraw %run %t
49// RUN: not ls %t.dir5/e_%20m.profraw
50// RUN: ls %t.dir5/e_*.profraw | count 1
51
52int begin(int i) {
53 // COMMON: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]]
54 if (i)
55 return 0;
56 return 1;
57}
58
59int end(int i) {
60 // COMMON: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD2:[0-9]+]]
61 if (i)
62 return 0;
63 return 1;
64}
65
66int main(int argc, const char *argv[]) {
67 begin(0);
68 end(1);
69
70 // COMMON: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD2:[0-9]+]]
71 if (argc)
72 return 0;
73 return 1;
74}
75
76// ORIG: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
77// ORIG: ![[PD2]] = !{!"branch_weights", i32 2, i32 1}
78// MERGE: ![[PD1]] = !{!"branch_weights", i32 1, i32 3}
79// MERGE: ![[PD2]] = !{!"branch_weights", i32 3, i32 1}
80// PGOMERGE: ![[PD1]] = !{!"branch_weights", i32 0, i32 4}
81// PGOMERGE: ![[PD2]] = !{!"branch_weights", i32 4, i32 0}
82