1 ; Check that we handle `step` instrumentations. These addorn `select`s.
2 ; We don't want to confuse the `step` with normal increments, the latter of which
3 ; we use for BB ID-ing: we want to keep the `step`s after inlining, except if
4 ; the `select` is elided.
6 ; RUN: split-file %s %t
7 ; RUN: llvm-ctxprof-util fromJSON --input=%t/profile.json --output=%t/profile.ctxprofdata
9 ; RUN: opt -passes=ctx-instr-gen %t/example.ll -use-ctx-profile=%t/profile.ctxprofdata -S -o - | FileCheck %s --check-prefix=INSTR
10 ; RUN: opt -passes=ctx-instr-gen,module-inline %t/example.ll -use-ctx-profile=%t/profile.ctxprofdata -S -o - | FileCheck %s --check-prefix=POST-INL
11 ; RUN: opt -passes=ctx-instr-gen,module-inline,ctx-prof-flatten %t/example.ll -use-ctx-profile=%t/profile.ctxprofdata -S -o - | FileCheck %s --check-prefix=FLATTEN
14 ; INSTR-NEXT: call void @llvm.instrprof.increment(ptr @foo, i64 [[#]], i32 2, i32 1)
15 ; INSTR-NEXT: call void @llvm.instrprof.callsite(ptr @foo, i64 [[#]], i32 2, i32 0, ptr @bar)
18 ; INSTR-NEXT: call void @llvm.instrprof.callsite(ptr @foo, i64 [[#]], i32 2, i32 1, ptr @bar)
20 ; INSTR-LABEL: define i32 @bar
21 ; INSTR-NEXT: call void @llvm.instrprof.increment(ptr @bar, i64 [[#]], i32 2, i32 0)
23 ; INSTR: %test = icmp eq i32 %t, 0
24 ; INSTR-NEXT: %1 = zext i1 %test to i64
25 ; INSTR-NEXT: call void @llvm.instrprof.increment.step(ptr @bar, i64 [[#]], i32 2, i32 1, i64 %1)
26 ; INSTR-NEXT: %res = select
28 ; POST-INL-LABEL: yes:
29 ; POST-INL-NEXT: call void @llvm.instrprof.increment
30 ; POST-INL: call void @llvm.instrprof.increment.step
31 ; POST-INL-NEXT: %res.i = select
34 ; POST-INL-NEXT: call void @llvm.instrprof.increment
35 ; POST-INL-NEXT: br label
37 ; POST-INL-LABEL: exit:
38 ; POST-INL-NEXT: %res = phi i32 [ %res.i, %yes ], [ 1, %no ]
41 ; FLATTEN: %res.i = select i1 %test.i, i32 %inc.i, i32 %dec.i, !prof ![[SELPROF:[0-9]+]]
44 ; See the profile, in the "yes" case we set the step counter's value, in @bar, to 3. The total
45 ; entry count of that BB is 4.
46 ; ![[SELPROF]] = !{!"branch_weights", i32 3, i32 1}
49 define i32 @foo(i32 %t) !guid !0 {
50 %test = icmp slt i32 %t, 0
51 br i1 %test, label %yes, label %no
53 %res1 = call i32 @bar(i32 %t) alwaysinline
56 ; this will result in eliding the select in @bar, when inlined.
57 %res2 = call i32 @bar(i32 0) alwaysinline
60 %res = phi i32 [%res1, %yes], [%res2, %no]
64 define i32 @bar(i32 %t) !guid !1 {
67 %test = icmp eq i32 %t, 0
68 %res = select i1 %test, i32 %inc, i32 %dec
76 [{"Guid":1234, "Counters":[10, 4], "Callsites":[[{"Guid": 5678, "Counters":[4,3]}],[{"Guid": 5678, "Counters":[6,6]}]]}]