Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / profile / instrprof-write-file.c
blobe2f5e112e0643a0424a17970d9679bfda624b7f9
1 // RUN: rm -rf %t1.profraw %t2.profraw
2 // RUN: %clang_profgen -o %t -O3 %s
3 // RUN: env LLVM_PROFILE_FILE=%t1.profraw %run %t %t2.profraw
4 // RUN: llvm-profdata merge -o %t1.profdata %t1.profraw
5 // RUN: %clang_profuse=%t1.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK
6 // RUN: llvm-profdata merge -o %t2.profdata %t2.profraw
7 // RUN: %clang_profuse=%t2.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=CHECK2 --check-prefix=CHECK
9 int __llvm_profile_write_file(void);
10 void __llvm_profile_set_filename(const char *);
11 int foo(int);
12 int main(int argc, const char *argv[]) {
13 // CHECK-LABEL: define {{.*}} @main(
14 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]]
15 if (argc < 2)
16 return 1;
18 // Write out the profile.
19 __llvm_profile_write_file();
21 // Change the profile.
22 int Ret = foo(0);
24 // It'll write out again at exit; change the filename so we get two files.
25 __llvm_profile_set_filename(argv[1]);
26 return Ret;
28 int foo(int X) {
29 // CHECK-LABEL: define {{.*}} @foo(
30 // CHECK1: br i1 %{{.*}}, label %{{.*}}, label %{{[^,]+$}}
31 // CHECK2: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD2:[0-9]+]]
32 return X <= 0 ? -X : X;
34 // CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
35 // CHECK2: ![[PD2]] = !{!"branch_weights", i32 2, i32 1}