File: select-to-branch.mir

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (117 lines) | stat: -rw-r--r-- 4,295 bytes parent folder | download | duplicates (21)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple powerpc64le-unknown-linux-gnu \
# RUN:   -run-pass=codegenprepare -o - %s | FileCheck %s
# RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple powerpc64le-unknown-linux-gnu \
# RUN:   -run-pass=codegenprepare -o - %s | FileCheck %s
--- |
  define i32 @weighted_select1(i32 %a, i32 %b) {
    %cmp = icmp ne i32 %a, 0
    %sel = select i1 %cmp, i32 %a, i32 %b, !prof !14
    ret i32 %sel

  ; If branch_weights > 99% or branch_weights < 1%, the select will be
  ; converted to branch, here !14 = 99/100, !14 = 99%, so it will do nothing.
  ; CHECK-LABEL: weighted_select1
  ; CHECK:         %cmp = icmp ne i32 %a, 0
  ; CHECK-NEXT:    %sel = select i1 %cmp, i32 %a, i32 %b, !prof !14
  ; CHECK-NEXT:    ret i32 %sel
  }

  define i32 @weighted_select2(i32 %a, i32 %b) {
    %cmp = icmp ne i32 %a, 0
    %sel = select i1 %cmp, i32 %a, i32 %b, !prof !15
    ret i32 %sel

  ; If branch_weights > 99% or branch_weights < 1%, the select will be converted
  ; to branch, here !15 = 100/101, !15 > 99%, so it will convert select to
  ; branch.
  ; CHECK-LABEL: weighted_select2
  ; CHECK:         %sel.frozen = freeze i32 %a
  ; CHECK:         %cmp = icmp ne i32 %sel.frozen, 0
  ; CHECK-NEXT:    br i1 %cmp, label %select.end, label %select.false, !prof !15
  ; CHECK:       select.false:
  ; CHECK-NEXT:    br label %select.end
  ; CHECK:       select.end:
  ; CHECK-NEXT:    %sel = phi i32 [ %a, %0 ], [ %b, %select.false ]
  ; CHECK-NEXT:    ret i32 %sel
  }

  define i32 @weighted_select3(i32 %a, i32 %b) {
    %cmp = icmp ne i32 %a, 0
    %sel = select i1 %cmp, i32 %a, i32 %b, !prof !16
    ret i32 %sel

  ; If branch_weights > 99% or branch_weights < 1%, the select will be converted
  ; to branch, here !16 = 1/101, !16 < 1%, so it will convert select to branch.
  ; CHECK-LABEL: weighted_select3
  ; CHECK:         %sel.frozen = freeze i32 %a
  ; CHECK:         %cmp = icmp ne i32 %sel.frozen, 0
  ; CHECK-NEXT:    br i1 %cmp, label %select.end, label %select.false, !prof !16
  ; CHECK:       select.false:
  ; CHECK-NEXT:    br label %select.end
  ; CHECK:       select.end:
  ; CHECK-NEXT:    %sel = phi i32 [ %a, %0 ], [ %b, %select.false ]
  ; CHECK-NEXT:    ret i32 %sel
  }

  define i32 @unweighted_select(i32 %a, i32 %b) {
    %cmp = icmp ne i32 %a, 0
    %sel = select i1 %cmp, i32 %a, i32 %b, !prof !17
    ret i32 %sel

  ; There is no weight_branch information, so it will do nothing.
  ; CHECK-LABEL: unweighted_select
  ; CHECK:         %cmp = icmp ne i32 %a, 0
  ; CHECK-NEXT:    %sel = select i1 %cmp, i32 %a, i32 %b, !prof !17
  ; CHECK-NEXT:    ret i32 %sel
  }

  ; Function Attrs: optsize
  define i32 @weighted_select_optsize(i32 %a, i32 %b) #0 {
    %cmp = icmp ne i32 %a, 0
    %sel = select i1 %cmp, i32 %a, i32 %b, !prof !15
    ret i32 %sel

  ; This function has used the optsize flag, so it will do nothing.
  ; CHECK-LABEL: weighted_select_optsize
  ; CHECK:         %cmp = icmp ne i32 %a, 0
  ; CHECK-NEXT:    %sel = select i1 %cmp, i32 %a, i32 %b, !prof !15
  ; CHECK-NEXT:    ret i32 %sel
  }

  define i32 @weighted_select_pgso(i32 %a, i32 %b) !prof !18 {
    %cmp = icmp ne i32 %a, 0
    %sel = select i1 %cmp, i32 %a, i32 %b, !prof !15
    ret i32 %sel

  ; The function_entry_count of this function is 0, so it will do nothing.
  ; CHECK-LABEL: weighted_select_pgso
  ; CHECK:         %cmp = icmp ne i32 %a, 0
  ; CHECK-NEXT:    %sel = select i1 %cmp, i32 %a, i32 %b, !prof !15
  ; CHECK-NEXT:    ret i32 %sel
  }
  
  attributes #0 = { optsize }
  
  !llvm.module.flags = !{!0}
  
  !0 = !{i32 1, !"ProfileSummary", !1}
  !1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
  !2 = !{!"ProfileFormat", !"InstrProf"}
  !3 = !{!"TotalCount", i64 10000}
  !4 = !{!"MaxCount", i64 10}
  !5 = !{!"MaxInternalCount", i64 1}
  !6 = !{!"MaxFunctionCount", i64 1000}
  !7 = !{!"NumCounts", i64 3}
  !8 = !{!"NumFunctions", i64 3}
  !9 = !{!"DetailedSummary", !10}
  !10 = !{!11, !12, !13}
  !11 = !{i32 10000, i64 100, i32 1}
  !12 = !{i32 999000, i64 100, i32 1}
  !13 = !{i32 999999, i64 1, i32 2}
  !14 = !{!"branch_weights", i32 1, i32 99}
  !15 = !{!"branch_weights", i32 1, i32 100}
  !16 = !{!"branch_weights", i32 100, i32 1}
  !17 = !{!"branch_weights", i32 0, i32 0}
  !18 = !{!"function_entry_count", i64 0}

...