xref: /llvm-project/bolt/test/X86/split-func-jump-table-fragment-bidirection.s (revision 11791ae7b0b05b8bd8d806331ff51da618912cf8)
1## This reproduces an issue where two fragments of same function access same
2## jump table, which means at least one fragment visits the other, i.e., one
3## of them has split jump table. As a result, all of them will be marked as
4## non-simple function.
5
6# REQUIRES: system-linux
7
8# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
9# RUN: llvm-strip --strip-unneeded %t.o
10# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
11# RUN: llvm-bolt -print-cfg -v=3 %t.exe -o %t.out 2>&1 | FileCheck %s
12
13# CHECK: BOLT-INFO: Multiple fragments access same jump table: main; main.cold.1
14# CHECK: PIC Jump table JUMP_TABLE1 for function main, main.cold.1 at {{.*}}  with a total count of 0:
15
16  .text
17  .globl main
18  .type main, %function
19  .p2align 2
20main:
21LBB0:
22  andl $0xf, %ecx
23  cmpb $0x4, %cl
24  ## exit through ret
25  ja LBB3
26
27## jump table dispatch, jumping to label indexed by val in %ecx
28LBB1:
29  leaq JUMP_TABLE1(%rip), %r8
30  movzbl %cl, %ecx
31  movslq (%r8,%rcx,4), %rax
32  addq %rax, %r8
33  jmpq *%r8
34
35LBB2:
36  xorq %rax, %rax
37LBB3:
38  addq $0x8, %rsp
39  ret
40.size main, .-main
41
42## cold fragment is only reachable
43  .globl main.cold.1
44  .type main.cold.1, %function
45  .p2align 2
46main.cold.1:
47  ## load bearing nop: pad LBB8 so that it can't be treated
48  ## as __builtin_unreachable by analyzeJumpTable
49  nop
50LBB4:
51  andl $0xb, %ebx
52  cmpb $0x1, %cl
53  # exit through ret
54  ja LBB7
55
56## jump table dispatch, jumping to label indexed by val in %ecx
57LBB5:
58  leaq JUMP_TABLE1(%rip), %r8
59  movzbl %cl, %ecx
60  movslq (%r8,%rcx,4), %rax
61  addq %rax, %r8
62  jmpq *%r8
63
64LBB6:
65  xorq %rax, %rax
66LBB7:
67  addq $0x8, %rsp
68  ret
69LBB8:
70  callq abort
71.size main.cold.1, .-main.cold.1
72
73  .rodata
74## jmp table, entries must be R_X86_64_PC32 relocs
75  .globl JUMP_TABLE1
76JUMP_TABLE1:
77  .long LBB2-JUMP_TABLE1
78  .long LBB3-JUMP_TABLE1
79  .long LBB8-JUMP_TABLE1
80  .long LBB6-JUMP_TABLE1
81  .long LBB7-JUMP_TABLE1
82