1 ; REQUIRES: asserts && x86_64-linux
2 ; Check that the profile annotator works: we hit an exit and non-zero paths to
3 ; already visited blocks count as taken (i.e. the flow continues through them).
5 ; RUN: split-file %s %t
6 ; RUN: llvm-ctxprof-util fromJSON --input=%t/profile_ok.json --output=%t/profile_ok.ctxprofdata
7 ; RUN: llvm-ctxprof-util fromJSON --input=%t/profile_pump.json --output=%t/profile_pump.ctxprofdata
8 ; RUN: llvm-ctxprof-util fromJSON --input=%t/profile_unreachable.json --output=%t/profile_unreachable.ctxprofdata
10 ; RUN: opt -passes=ctx-prof-flatten %t/example_ok.ll -use-ctx-profile=%t/profile_ok.ctxprofdata -S -o - | FileCheck %s
11 ; RUN: not --crash opt -passes=ctx-prof-flatten %t/message_pump.ll -use-ctx-profile=%t/profile_pump.ctxprofdata -S 2>&1 | FileCheck %s --check-prefix=ASSERTION
12 ; RUN: not --crash opt -passes=ctx-prof-flatten %t/unreachable.ll -use-ctx-profile=%t/profile_unreachable.ctxprofdata -S 2>&1 | FileCheck %s --check-prefix=ASSERTION
14 ; CHECK: br i1 %x, label %b1, label %exit, !prof ![[PROF1:[0-9]+]]
15 ; CHECK: br i1 %y, label %blk, label %exit, !prof ![[PROF2:[0-9]+]]
16 ; CHECK: ![[PROF1]] = !{!"branch_weights", i32 1, i32 1}
17 ; CHECK: ![[PROF2]] = !{!"branch_weights", i32 0, i32 1}
18 ; ASSERTION: Assertion `allTakenPathsExit()
20 ; b1->exit is the only way out from b1, but the exit block would have been
21 ; already visited from blk. That should not result in an assertion, though.
23 define void @foo(i32 %t) !guid !0 {
25 call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 0)
28 call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 1)
29 %x = icmp eq i32 %t, 0
30 br i1 %x, label %b1, label %exit
32 call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 2)
33 %y = icmp eq i32 %t, 0
34 br i1 %y, label %blk, label %exit
36 call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 3)
42 [{"Guid":1234, "Counters":[2, 2, 1, 2]}]
45 ; This is a message pump: the loop never exits. This should result in an
46 ; assertion because we can't reach an exit BB
48 define void @foo(i32 %t) !guid !0 {
50 call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 0)
53 call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 1)
54 %x = icmp eq i32 %t, 0
55 br i1 %x, label %blk, label %exit
57 call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 2)
62 ;--- profile_pump.json
63 [{"Guid":1234, "Counters":[2, 10, 0]}]
66 ; An unreachable block is reached, that's an error
67 define void @foo(i32 %t) !guid !0 {
69 call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 0)
72 call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 1)
73 %x = icmp eq i32 %t, 0
74 br i1 %x, label %b1, label %exit
76 call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 2)
79 call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 3)
84 ;--- profile_unreachable.json
85 [{"Guid":1234, "Counters":[2, 1, 1, 2]}]