Skip to content

Commit ddb32a6

Browse files
[NFC] Add a precommit test for aarch64 jump table partitioning (#125987)
1 parent 9b63a92 commit ddb32a6

File tree

1 file changed

+245
-0
lines changed

1 file changed

+245
-0
lines changed
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
; The llc commands override two options
2+
; - 'aarch64-enable-atomic-cfg-tidy' to false to turn off simplifycfg pass,
3+
; which can simplify away switch instructions before isel lowers switch instructions.
4+
; - 'aarch64-min-jump-table-entries' so 'switch' needs fewer cases to generate
5+
; a jump table.
6+
7+
; The static-data-splitter pass doesn't run.
8+
; RUN: llc -mtriple=aarch64-unknown-linux-gnu -function-sections=true \
9+
; RUN: -aarch64-enable-atomic-cfg-tidy=false -aarch64-min-jump-table-entries=2 \
10+
; RUN: -unique-section-names=true %s -o - 2>&1 | FileCheck %s --check-prefixes=DEFAULT
11+
12+
; DEFAULT: .section .rodata.hot.foo,"a",@progbits
13+
; DEFAULT: .LJTI0_0:
14+
; DEFAULT: .LJTI0_1:
15+
; DEFAULT: .LJTI0_2:
16+
; DEFAULT: .LJTI0_3:
17+
; DEFAULT: .section .rodata.func_without_profile,"a",@progbits
18+
; DEFAULT: .LJTI1_0:
19+
; DEFAULT: .section .rodata.bar_prefix.bar,"a",@progbits
20+
; DEFAULT: .LJTI2_0
21+
22+
; RUN: llc -mtriple=aarch64-unknown-linux-gnu -enable-split-machine-functions \
23+
; RUN: -partition-static-data-sections=true -function-sections=true \
24+
; RUN: -aarch64-enable-atomic-cfg-tidy=false -aarch64-min-jump-table-entries=2 \
25+
; RUN: -unique-section-names=false %s -o - 2>&1 | FileCheck %s --check-prefixes=NUM,JT
26+
27+
; Section names will optionally have `.<func>` if -function-sections is enabled.
28+
; RUN: llc -mtriple=aarch64-unknown-linux-gnu -enable-split-machine-functions \
29+
; RUN: -partition-static-data-sections=true -function-sections=true \
30+
; RUN: -aarch64-enable-atomic-cfg-tidy=false -aarch64-min-jump-table-entries=2 \
31+
; RUN: %s -o - 2>&1 | FileCheck %s --check-prefixes=FUNC,JT
32+
33+
; RUN: llc -mtriple=aarch64-unknown-linux-gnu -enable-split-machine-functions \
34+
; RUN: -partition-static-data-sections=true -function-sections=false \
35+
; RUN: -aarch64-enable-atomic-cfg-tidy=false -aarch64-min-jump-table-entries=2 \
36+
; RUN: %s -o - 2>&1 | FileCheck %s --check-prefixes=FUNCLESS,JT
37+
38+
; A function's section prefix is used for all jump tables of this function.
39+
; @foo is hot so its jump table data section has a hot prefix.
40+
; NUM: .section .rodata.hot.,"a",@progbits,unique,2
41+
; FUNC: .section .rodata.hot.foo,"a",@progbits
42+
; FUNCLESS: .section .rodata.hot.,"a",@progbits
43+
; JT: .LJTI0_0:
44+
; JT: .LJTI0_1:
45+
; JT: .LJTI0_2:
46+
; JT: .LJTI0_3:
47+
48+
; func_without_profile doesn't have profiles, so its jumptable doesn't have
49+
; hotness-based prefix.
50+
; NUM: .section .rodata,"a",@progbits,unique,4
51+
; FUNC: .section .rodata.func_without_profile,"a",@progbits
52+
; FUNCLESS: .section .rodata,"a",@progbits
53+
; JT: .LJTI1_0:
54+
55+
; @bar doesn't have profile information and it has a section prefix.
56+
; Tests that its jump tables are placed in sections with function prefixes.
57+
; NUM: .section .rodata.bar_prefix.,"a",@progbits,unique,
58+
; FUNC: .section .rodata.bar_prefix.bar
59+
; FUNCLESS: .section .rodata.bar_prefix.,"a"
60+
; JT: .LJTI2_0
61+
62+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
63+
target triple = "aarch64-unknown-linux-gnu"
64+
65+
@str.9 = private constant [7 x i8] c".str.9\00"
66+
@str.10 = private constant [8 x i8] c".str.10\00"
67+
@str.11 = private constant [8 x i8] c".str.11\00"
68+
69+
@case2 = private constant [7 x i8] c"case 2\00"
70+
@case1 = private constant [7 x i8] c"case 1\00"
71+
@default = private constant [8 x i8] c"default\00"
72+
@jt3 = private constant [4 x i8] c"jt3\00"
73+
74+
; jt0 and jt2 are hot. jt1 and jt3 are cold.
75+
define i32 @foo(i32 %num) !prof !13 {
76+
entry:
77+
%mod3 = sdiv i32 %num, 3
78+
switch i32 %mod3, label %jt0.default [
79+
i32 1, label %jt0.bb1
80+
i32 2, label %jt0.bb2
81+
], !prof !14
82+
83+
jt0.bb1:
84+
call i32 @puts(ptr @case1)
85+
br label %jt0.epilog
86+
87+
jt0.bb2:
88+
call i32 @puts(ptr @case2)
89+
br label %jt0.epilog
90+
91+
jt0.default:
92+
call i32 @puts(ptr @default)
93+
br label %jt0.epilog
94+
95+
jt0.epilog:
96+
%zero = icmp eq i32 %num, 0
97+
br i1 %zero, label %hot, label %cold, !prof !17
98+
99+
hot:
100+
%c2 = call i32 @transform(i32 %num)
101+
switch i32 %c2, label %jt2.default [
102+
i32 1, label %jt2.bb1
103+
i32 2, label %jt2.bb2
104+
], !prof !14
105+
106+
jt2.bb1:
107+
call i32 @puts(ptr @case1)
108+
br label %jt1.epilog
109+
110+
jt2.bb2:
111+
call i32 @puts(ptr @case2)
112+
br label %jt1.epilog
113+
114+
jt2.default:
115+
call i32 @puts(ptr @default)
116+
br label %jt2.epilog
117+
118+
jt2.epilog:
119+
%c2cmp = icmp ne i32 %c2, 0
120+
br i1 %c2cmp, label %return, label %jt3.prologue, !prof !18
121+
122+
cold:
123+
%c1 = call i32 @compute(i32 %num)
124+
switch i32 %c1, label %jt1.default [
125+
i32 1, label %jt1.bb1
126+
i32 2, label %jt1.bb2
127+
], !prof !14
128+
129+
jt1.bb1:
130+
call i32 @puts(ptr @case1)
131+
br label %jt1.epilog
132+
133+
jt1.bb2:
134+
call i32 @puts(ptr @case2)
135+
br label %jt1.epilog
136+
137+
jt1.default:
138+
call i32 @puts(ptr @default)
139+
br label %jt1.epilog
140+
141+
jt1.epilog:
142+
br label %return
143+
144+
jt3.prologue:
145+
%c3 = call i32 @cleanup(i32 %num)
146+
switch i32 %c3, label %jt3.default [
147+
i32 1, label %jt3.bb1
148+
i32 2, label %jt3.bb2
149+
], !prof !14
150+
151+
jt3.bb1:
152+
call i32 @puts(ptr @case1)
153+
br label %jt3.epilog
154+
155+
jt3.bb2:
156+
call i32 @puts(ptr @case2)
157+
br label %jt3.epilog
158+
159+
jt3.default:
160+
call i32 @puts(ptr @default)
161+
br label %jt3.epilog
162+
163+
jt3.epilog:
164+
call i32 @puts(ptr @jt3)
165+
br label %return
166+
167+
return:
168+
ret i32 %mod3
169+
}
170+
171+
define void @func_without_profile(i32 %num) {
172+
entry:
173+
switch i32 %num, label %sw.default [
174+
i32 1, label %sw.bb
175+
i32 2, label %sw.bb1
176+
]
177+
178+
sw.bb:
179+
call i32 @puts(ptr @str.10)
180+
br label %sw.epilog
181+
182+
sw.bb1:
183+
call i32 @puts(ptr @str.9)
184+
br label %sw.epilog
185+
186+
sw.default:
187+
call i32 @puts(ptr @str.11)
188+
br label %sw.epilog
189+
190+
sw.epilog:
191+
ret void
192+
}
193+
194+
define void @bar(i32 %num) !section_prefix !20 {
195+
entry:
196+
switch i32 %num, label %sw.default [
197+
i32 1, label %sw.bb
198+
i32 2, label %sw.bb1
199+
]
200+
201+
sw.bb:
202+
call i32 @puts(ptr @str.10)
203+
br label %sw.epilog
204+
205+
sw.bb1:
206+
call i32 @puts(ptr @str.9)
207+
br label %sw.epilog
208+
209+
sw.default:
210+
call i32 @puts(ptr @str.11)
211+
br label %sw.epilog
212+
213+
sw.epilog:
214+
ret void
215+
}
216+
217+
declare i32 @puts(ptr)
218+
declare i32 @printf(ptr, ...)
219+
declare i32 @compute(i32)
220+
declare i32 @transform(i32)
221+
declare i32 @cleanup(i32)
222+
223+
!llvm.module.flags = !{!0}
224+
225+
!0 = !{i32 1, !"ProfileSummary", !1}
226+
!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
227+
!2 = !{!"ProfileFormat", !"InstrProf"}
228+
!3 = !{!"TotalCount", i64 230002}
229+
!4 = !{!"MaxCount", i64 100000}
230+
!5 = !{!"MaxInternalCount", i64 50000}
231+
!6 = !{!"MaxFunctionCount", i64 100000}
232+
!7 = !{!"NumCounts", i64 14}
233+
!8 = !{!"NumFunctions", i64 3}
234+
!9 = !{!"DetailedSummary", !10}
235+
!10 = !{!11, !12}
236+
!11 = !{i32 990000, i64 10000, i32 7}
237+
!12 = !{i32 999999, i64 1, i32 9}
238+
!13 = !{!"function_entry_count", i64 100000}
239+
!14 = !{!"branch_weights", i32 60000, i32 20000, i32 20000}
240+
!15 = !{!"function_entry_count", i64 1}
241+
!16 = !{!"branch_weights", i32 1, i32 0, i32 0, i32 0, i32 0, i32 0}
242+
!17 = !{!"branch_weights", i32 99999, i32 1}
243+
!18 = !{!"branch_weights", i32 99998, i32 1}
244+
!19 = !{!"branch_weights", i32 97000, i32 1000, i32 1000, i32 1000}
245+
!20 = !{!"function_section_prefix", !"bar_prefix"}

0 commit comments

Comments
 (0)