86 lines · plain
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 which3; we use for BB ID-ing: we want to keep the `step`s after inlining, except if4; the `select` is elided.5;6; RUN: split-file %s %t7; RUN: llvm-ctxprof-util fromYAML --input=%t/profile.yaml --output=%t/profile.ctxprofdata8;9; RUN: opt -passes=ctx-instr-gen %t/1234.ll -use-ctx-profile=%t/profile.ctxprofdata -S -o - | FileCheck %s --check-prefix=INSTR10; RUN: opt -passes=ctx-instr-gen,module-inline %t/1234.ll -use-ctx-profile=%t/profile.ctxprofdata -S -o - | FileCheck %s --check-prefix=POST-INL11; RUN: opt -passes=ctx-instr-gen,module-inline,ctx-prof-flatten %t/1234.ll -use-ctx-profile=%t/profile.ctxprofdata -S -o - | FileCheck %s --check-prefix=FLATTEN12 13; INSTR-LABEL: yes: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)16 17; INSTR-LABEL: no:18; INSTR-NEXT: call void @llvm.instrprof.callsite(ptr @foo, i64 [[#]], i32 2, i32 1, ptr @bar)19 20; INSTR-LABEL: define i32 @bar21; INSTR-NEXT: call void @llvm.instrprof.increment(ptr @bar, i64 [[#]], i32 2, i32 0)22; INSTR-NEXT: %inc =23; INSTR: %test = icmp eq i32 %t, 024; INSTR-NEXT: %1 = zext i1 %test to i6425; INSTR-NEXT: call void @llvm.instrprof.increment.step(ptr @bar, i64 [[#]], i32 2, i32 1, i64 %1)26; INSTR-NEXT: %res = select27 28; POST-INL-LABEL: yes:29; POST-INL-NEXT: call void @llvm.instrprof.increment30; POST-INL: call void @llvm.instrprof.increment.step31; POST-INL-NEXT: %res.i = select32 33; POST-INL-LABEL: no:34; POST-INL-NEXT: call void @llvm.instrprof.increment35; POST-INL-NEXT: br label36 37; POST-INL-LABEL: exit:38; POST-INL-NEXT: %res = phi i32 [ %res.i, %yes ], [ 1, %no ]39 40; FLATTEN-LABEL: yes:41; FLATTEN: %res.i = select i1 %test.i, i32 %inc.i, i32 %dec.i, !prof ![[SELPROF:[0-9]+]]42; FLATTEN-LABEL: no:43;44; See the profile, in the "yes" case we set the step counter's value, in @bar, to 3. The total45; entry count of that BB is 4.46; ![[SELPROF]] = !{!"branch_weights", i32 3, i32 1}47 48;--- 1234.ll49define i32 @foo(i32 %t) !guid !0 {50 %test = icmp slt i32 %t, 051 br i1 %test, label %yes, label %no52yes:53 %res1 = call i32 @bar(i32 %t) alwaysinline54 br label %exit55no:56 ; this will result in eliding the select in @bar, when inlined.57 %res2 = call i32 @bar(i32 0) alwaysinline58 br label %exit59exit:60 %res = phi i32 [%res1, %yes], [%res2, %no]61 ret i32 %res62}63 64define i32 @bar(i32 %t) !guid !1 {65 %inc = add i32 %t, 166 %dec = sub i32 %t, 167 %test = icmp eq i32 %t, 068 %res = select i1 %test, i32 %inc, i32 %dec69 ret i32 %res70}71 72!0 = !{i64 1234}73!1 = !{i64 5678}74 75;--- profile.yaml76Contexts:77 - Guid: 123478 TotalRootEntryCount: 10079 Counters: [10, 4]80 Callsites: -81 - Guid: 567882 Counters: [4,3]83 - 84 - Guid: 567885 Counters: [6,6]86