xref: /llvm-project/bolt/test/X86/jump-table-icp.test (revision 11791ae7b0b05b8bd8d806331ff51da618912cf8)
1RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \
2RUN:   %p/Inputs/jump_table_icp.s -o %t.o
3RUN: link_fdata %p/Inputs/jump_table_icp.s %t.o %t.fdata --nmtool llvm-nm
4RUN: llvm-strip --strip-unneeded %t.o
5RUN: %clang %cflags -no-pie %t.o -o %t.exe -Wl,-q
6
7## This test has commands that rely on shell capabilities that won't execute
8## correctly on Windows e.g. subshell execution
9REQUIRES: shell
10
11RUN: (llvm-bolt %t.exe --data %t.fdata -o %t --relocs \
12RUN:   --reorder-blocks=cache --split-functions --split-all-cold \
13RUN:   --use-gnu-stack --dyno-stats --indirect-call-promotion=jump-tables \
14RUN:   --print-icp -v=0 \
15RUN:   --enable-bat --print-cache-metrics \
16RUN:   --icp-jt-remaining-percent-threshold=10 \
17RUN:   --icp-jt-total-percent-threshold=2 \
18RUN:   --indirect-call-promotion-topn=1 \
19RUN:   --icp-jump-tables-targets --align-functions-max-bytes=7 2>&1 && \
20RUN:   llvm-objdump -d %t --print-imm-hex) | FileCheck %s
21
22BOLT-INFO: ICP total indirect callsites = 0
23BOLT-INFO: ICP total jump table callsites = 2
24BOLT-INFO: ICP total number of calls = 2137
25BOLT-INFO: ICP percentage of calls that are indirect = 0.0%
26BOLT-INFO: ICP percentage of indirect calls that can be optimized = 0.0%
27BOLT-INFO: ICP percentage of indirect calls that are optimized = 0.0%
28BOLT-INFO: ICP percentage of jump table calls that can be optimized = 17.7%
29BOLT-INFO: ICP percentage of jump table calls that are optimized = 100.0%
30
31CHECK: Binary Function "_Z3inci" after indirect-call-promotion
32CHECK: .LBB{{.*}} (8 instructions, align : 1)
33CHECK-NEXT:   Entry Point
34CHECK-NEXT:   Exec Count : 1073
35CHECK:   Successors: .Ltmp{{.*}} (mispreds: 189, count: 189), .LFT{{.*}} (mispreds: 0, count: 881)
36
37CHECK: .LFT{{.*}} (4 instructions, align : 1)
38CHECK-NEXT:   Exec Count : 881
39CHECK:   Predecessors: .LBB{{.*}}
40CHECK:     je {{.*}} # Offset: 28
41CHECK-NEXT: Successors: .Ltmp{{.*}} (mispreds: 138, count: 155), .Ltmp{{.*}} (mispreds: 0, count: 726)
42
43CHECK: .Ltmp{{.*}} (1 instructions, align : 1)
44CHECK-NEXT:   Exec Count : 726
45CHECK:   Predecessors: .LFT{{.*}}
46CHECK:     jmpq {{.*}} # Offset: 28
47CHECK-NEXT: Successors: .L{{.*}} (mispreds: 126, count: 157), .L{{.*}} (mispreds: 140, count: 156), .L{{.*}} (mispreds: 134, count: 152), .L{{.*}} (mispreds: 137, count: 150), .L{{.*}} (mispreds: 129, count: 148), .L{{.*}} (mispreds: 0, count: 0)
48
49CHECK: .Ltmp{{.*}} (5 instructions, align : 1)
50CHECK-NEXT:  Exec Count : 167
51CHECK:  Predecessors: .Ltmp{{.*}}, .LFT{{.*}}
52
53CHECK: .Ltmp{{.*}} (5 instructions, align : 1)
54CHECK-NEXT:  Exec Count : 156
55CHECK:  Predecessors: .Ltmp{{.*}}
56
57CHECK: .Ltmp{{.*}} (5 instructions, align : 1)
58CHECK-NEXT:  Exec Count : 157
59CHECK:  Predecessors: .Ltmp{{.*}}
60
61CHECK: .Ltmp{{.*}} (5 instructions, align : 1)
62CHECK-NEXT:  Exec Count : 148
63CHECK:  Predecessors: .Ltmp{{.*}}
64
65CHECK: .Ltmp{{.*}} (5 instructions, align : 1)
66CHECK-NEXT:  Exec Count : 150
67CHECK:  Predecessors: .Ltmp{{.*}}
68
69CHECK: Binary Function "_Z7inc_dupi" after indirect-call-promotion
70CHECK: .LBB{{.*}} (8 instructions, align : 1)
71CHECK-NEXT:   Entry Point
72CHECK-NEXT:   Exec Count : 1064
73CHECK:   Successors: .Ltmp{{.*}} (mispreds: 143, count: 144), .LFT{{.*}} (mispreds: 0, count: 777)
74
75CHECK: .LFT{{.*}} (4 instructions, align : 1)
76CHECK-NEXT:   Exec Count : 777
77CHECK:   Predecessors: .LBB{{.*}}
78CHECK:   Successors: .Ltmp{{.*}} (mispreds: 120, count: 138), .Ltmp{{.*}} (mispreds: 0, count: 639)
79
80CHECK: .Ltmp{{.*}} (1 instructions, align : 1)
81CHECK-NEXT:   Exec Count : 639
82CHECK:   Predecessors: .LFT{{.*}}
83CHECK:   Successors: .L{{.*}} (mispreds: 130, count: 137), .L{{.*}} (mispreds: 126, count: 136), .L{{.*}} (mispreds: 122, count: 130), .L{{.*}} (mispreds: 111, count: 130), .L{{.*}} (mispreds: 104, count: 114), .L{{.*}} (mispreds: 0, count: 0)
84
85CHECK: .Ltmp{{.*}} (5 instructions, align : 1)
86CHECK-NEXT:   Exec Count : 137
87CHECK:   Predecessors: .Ltmp{{.*}}
88CHECK:   Successors: .Ltmp{{.*}} (mispreds: 0, count: 106)
89
90CHECK: .Ltmp{{.*}} (5 instructions, align : 1)
91CHECK-NEXT:   Exec Count : 136
92CHECK:   Predecessors: .Ltmp{{.*}}
93CHECK:   Successors: .Ltmp{{.*}} (mispreds: 0, count: 113)
94
95CHECK: .Ltmp{{.*}} (5 instructions, align : 1)
96CHECK-NEXT:   Exec Count : 130
97CHECK:   Predecessors: .Ltmp{{.*}}
98CHECK:   Successors: .Ltmp{{.*}} (mispreds: 0, count: 97)
99
100CHECK: .Ltmp{{.*}} (5 instructions, align : 1)
101CHECK-NEXT:   Exec Count : 130
102CHECK:   Predecessors: .Ltmp{{.*}}
103CHECK:   Successors: .Ltmp{{.*}} (mispreds: 0, count: 105)
104
105CHECK: .Ltmp{{.*}} (5 instructions, align : 1)
106CHECK-NEXT:   Exec Count : 140
107CHECK:   Predecessors: .Ltmp{{.*}}, .LFT{{.*}}
108CHECK:   Successors: .Ltmp{{.*}} (mispreds: 0, count: 98)
109
110CHECK:     <_Z3inci>:
111CHECK:        	movq    0x{{.*}}(,%rax,8), %rax
112CHECK-NEXT:    cmpq    $0x{{.*}}, %rax
113CHECK-NEXT:    je {{.*}} <_Z3inci+0x{{.*}}>
114CHECK-NEXT:   	jmpq   *%rax
115
116CHECK:     <_Z7inc_dupi>:
117CHECK:        	movq    0x{{.*}}(,%rax,8), %rax
118CHECK-NEXT:    cmpq $0x{{.*}}, %rax
119CHECK-NEXT:    je {{.*}} <_Z7inc_dupi+0x{{.*}}>
120CHECK-NEXT:   	jmpq   *%rax
121