partial-tail-dup.ll
3.4 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
@gvar = external global i32
; dupbb has two predecessors, p1 and p2. p1 is hot, p2 is cold. So dupbb
; should be placed after p1, and not duplicated into p2.
;
; CHECK-LABEL: test1
; CHECK: %p1
; CHECK: .LBB0_4: # %dupbb
; CHECK: %p2
; CHECK: jmp .LBB0_4
define void @test1(i32* %p) !prof !1 {
entry:
br label %header
header:
%call = call zeroext i1 @a()
br i1 %call, label %p1, label %p2, !prof !2
p1:
call void @b()
br label %dupbb
p2:
call void @c()
br label %dupbb
dupbb:
%cond = icmp eq i32* @gvar, %p
br i1 %cond, label %header, label %latch, !prof !3
latch:
%call3 = call zeroext i1 @a()
br i1 %call3, label %header, label %end, !prof !2
end:
ret void
}
; dupbb has four predecessors p1, p2, p3 and p4. p1 and p2 are hot, p3 and p4
; are cold. So dupbb should be placed after p1, duplicated into p2. p3 and p4
; should jump to dupbb.
;
; CHECK-LABEL: test2
; CHECK: %p1
; CHECK: .LBB1_8: # %dupbb
;
; CHECK: %p2
; CHECK: callq c
; CHECK-NEXT: cmpq
; CHECK-NEXT: je
; CHECK-NEXT: jmp
;
; CHECK: %p3
; CHECK: jmp .LBB1_8
; CHECK: %p4
; CHECK: jmp .LBB1_8
define void @test2(i32* %p) !prof !1 {
entry:
br label %header
header:
%call = call zeroext i1 @a()
br i1 %call, label %bb1, label %bb2, !prof !2
bb1:
%call1 = call zeroext i1 @a()
br i1 %call1, label %p1, label %p2, !prof !4
bb2:
%call2 = call zeroext i1 @a()
br i1 %call2, label %p3, label %p4, !prof !4
p1:
call void @b()
br label %dupbb
p2:
call void @c()
br label %dupbb
p3:
call void @d()
br label %dupbb
p4:
call void @e()
br label %dupbb
dupbb:
%cond = icmp eq i32* @gvar, %p
br i1 %cond, label %bb3, label %bb4, !prof !4
bb3:
call void @b()
br label %bb4
bb4:
%call4 = call zeroext i1 @a()
br i1 %call4, label %header, label %latch, !prof !3
latch:
%call3 = call zeroext i1 @a()
br i1 %call3, label %header, label %end, !prof !2
end:
ret void
}
; dupbb has three predecessors p1, p2 and p3. p3 has two successors, so dupbb
; can't be duplicated into p3, but it should not block it to be duplicated into
; other predecessors.
;
; CHECK-LABEL: test3
; CHECK: %p1
; CHECK: .LBB2_6: # %dupbb
;
; CHECK: %p2
; CHECK: callq c
; CHECK: cmpq
; CHECK-NEXT: je
; CHECK-NEXT: jmp
;
; CHECK: %p3
; CHECK: jne .LBB2_6
define void @test3(i32* %p) !prof !1 {
entry:
br label %header
header:
%call = call zeroext i1 @a()
br i1 %call, label %bb1, label %p3, !prof !2
bb1:
%call1 = call zeroext i1 @a()
br i1 %call1, label %p1, label %p2, !prof !4
p1:
call void @b()
br label %dupbb
p2:
call void @c()
br label %dupbb
p3:
%call2 = call zeroext i1 @a()
br i1 %call2, label %dupbb, label %bb4, !prof !4
dupbb:
%cond = icmp eq i32* @gvar, %p
br i1 %cond, label %bb3, label %bb4, !prof !4
bb3:
call void @b()
br label %bb4
bb4:
%call4 = call zeroext i1 @a()
br i1 %call4, label %header, label %latch, !prof !3
latch:
%call3 = call zeroext i1 @a()
br i1 %call3, label %header, label %end, !prof !2
end:
ret void
}
declare zeroext i1 @a()
declare void @b()
declare void @c()
declare void @d()
declare void @e()
declare void @f()
!1 = !{!"function_entry_count", i64 1000}
!2 = !{!"branch_weights", i32 100, i32 1}
!3 = !{!"branch_weights", i32 1, i32 100}
!4 = !{!"branch_weights", i32 60, i32 40}