1// RUN: rm -fr %t.promo.prof
2// RUN: rm -fr %t.nopromo.prof
3// RUN: %clang_pgogen=%t.promo.prof/ -o %t.promo.gen -O2 %s
4// RUN: %clang_pgogen=%t.promo.prof/ -o %t.promo.gen.ll -emit-llvm -S -O2 %s
5// RUN: cat %t.promo.gen.ll | FileCheck --check-prefix=PROMO %s
6// RUN: %run %t.promo.gen
7// RUN: llvm-profdata merge -o %t.promo.profdata %t.promo.prof/
8// RUN: llvm-profdata show --counts --all-functions %t.promo.profdata > %t.promo.dump
9// RUN: %clang_pgogen=%t.nopromo.prof/ -mllvm -do-counter-promotion=false -o %t.nopromo.gen -O2 %s
10// RUN: %run %t.nopromo.gen
11// RUN: llvm-profdata merge -o %t.nopromo.profdata %t.nopromo.prof/
12// RUN: llvm-profdata show --counts --all-functions %t.nopromo.profdata > %t.nopromo.dump
13// RUN: diff <(llvm-profdata show %t.promo.profdata) <(llvm-profdata show %t.nopromo.profdata)
14int g;
15__attribute__((noinline)) void bar() {
16 g++;
17}
18
19extern int printf(const char*,...);
20
21int c = 10;
22
23int main()
24// PROMO-LABEL: @main
25// PROMO: load{{.*}}@__profc_main{{.*}}
26// PROMO-NEXT: add
27// PROMO-NEXT: store{{.*}}@__profc_main{{.*}}
28// PROMO: load{{.*}}@__profc_main{{.*}}
29// PROMO-NEXT: add
30// PROMO-NEXT: store{{.*}}@__profc_main{{.*}}
31// PROMO-NEXT: load{{.*}}@__profc_main{{.*}}
32// PROMO-NEXT: add
33// PROMO-NEXT: store{{.*}}@__profc_main{{.*}}
34{
35 int i, j, k;
36
37 g = 0;
38 for (i = 0; i < c; i++)
39 for (j = 0; j < c; j++)
40 for (k = 0; k < c; k++)
41 bar();
42
43 for (i = 0; i < c; i++)
44 for (j = 0; j < 10*c;j++)
45 bar();
46
47 for (i = 0; i < 100*c; i++)
48 bar();
49
50 return 0;
51}
52

source code of compiler-rt/test/profile/Linux/counter_promo_nest.c