File: handle-select.ll

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.6-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,304 kB
  • sloc: cpp: 7,438,677; ansic: 1,393,822; asm: 1,012,926; python: 241,650; f90: 86,635; objc: 75,479; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (83 lines) | stat: -rw-r--r-- 2,988 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
; Check that we handle `step` instrumentations. These addorn `select`s.
; We don't want to confuse the `step` with normal increments, the latter of which
; we use for BB ID-ing: we want to keep the `step`s after inlining, except if
; the `select` is elided.
;
; RUN: split-file %s %t
; RUN: llvm-ctxprof-util fromYAML --input=%t/profile.yaml --output=%t/profile.ctxprofdata
;
; RUN: opt -passes=ctx-instr-gen %t/example.ll -use-ctx-profile=%t/profile.ctxprofdata -S -o - | FileCheck %s --check-prefix=INSTR
; 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
; 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

; INSTR-LABEL: yes:
; INSTR-NEXT:   call void @llvm.instrprof.increment(ptr @foo, i64 [[#]], i32 2, i32 1)
; INSTR-NEXT:   call void @llvm.instrprof.callsite(ptr @foo, i64 [[#]], i32 2, i32 0, ptr @bar)

; INSTR-LABEL: no:
; INSTR-NEXT:   call void @llvm.instrprof.callsite(ptr @foo, i64 [[#]], i32 2, i32 1, ptr @bar)

; INSTR-LABEL: define i32 @bar
; INSTR-NEXT:   call void @llvm.instrprof.increment(ptr @bar, i64 [[#]], i32 2, i32 0)
; INSTR-NEXT:   %inc =
; INSTR:        %test = icmp eq i32 %t, 0
; INSTR-NEXT:   %1  = zext i1 %test to i64
; INSTR-NEXT:   call void @llvm.instrprof.increment.step(ptr @bar, i64 [[#]], i32 2, i32 1, i64 %1)
; INSTR-NEXT:   %res = select

; POST-INL-LABEL: yes:
; POST-INL-NEXT:   call void @llvm.instrprof.increment
; POST-INL:        call void @llvm.instrprof.increment.step
; POST-INL-NEXT:   %res.i = select

; POST-INL-LABEL: no:
; POST-INL-NEXT:   call void @llvm.instrprof.increment
; POST-INL-NEXT:   br label

; POST-INL-LABEL: exit:
; POST-INL-NEXT:   %res = phi i32 [ %res.i, %yes ], [ 1, %no ]

; FLATTEN-LABEL: yes:
; FLATTEN:          %res.i = select i1 %test.i, i32 %inc.i, i32 %dec.i, !prof ![[SELPROF:[0-9]+]]
; FLATTEN-LABEL: no:
;
; See the profile, in the "yes" case we set the step counter's value, in @bar, to 3. The total
; entry count of that BB is 4.
; ![[SELPROF]] = !{!"branch_weights", i32 3, i32 1}

;--- example.ll
define i32 @foo(i32 %t) !guid !0 {
  %test = icmp slt i32 %t, 0
  br i1 %test, label %yes, label %no
yes:
  %res1 = call i32 @bar(i32 %t) alwaysinline
  br label %exit
no:
  ; this will result in eliding the select in @bar, when inlined.
  %res2 = call i32 @bar(i32 0) alwaysinline
  br label %exit
exit:
  %res = phi i32 [%res1, %yes], [%res2, %no]
  ret i32 %res
}

define i32 @bar(i32 %t) !guid !1 {
  %inc = add i32 %t, 1
  %dec = sub i32 %t, 1
  %test = icmp eq i32 %t, 0
  %res = select i1 %test, i32 %inc, i32 %dec
  ret i32 %res
}

!0 = !{i64 1234}
!1 = !{i64 5678}

;--- profile.yaml
- Guid: 1234
  Counters: [10, 4]
  Callsites:  -
                - Guid: 5678
                  Counters: [4,3]
              - 
                - Guid: 5678
                  Counters: [6,6]