xref: /llvm-project/bolt/test/X86/split-func-icf.s (revision 11791ae7b0b05b8bd8d806331ff51da618912cf8)
1## This reproduces an issue where two cold fragments are folded into one, so the
2## fragment has two parents.
3## The fragment is only reachable through a jump table, so all functions must be
4## ignored.
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 %t.exe -o %t.out -v=1 --print-only=main2.cold.1 --print-disasm 2>&1 | FileCheck %s
12
13# CHECK-NOT: unclaimed PC-relative relocations left in data
14# CHECK-DAG: BOLT-INFO: marking main2.cold.1(*2) as a fragment of main2
15# CHECK-DAG: BOLT-INFO: marking main2.cold.1(*2) as a fragment of main
16# CHECK: Binary Function "main2.cold.1(*2)" after disassembly
17# CHECK: End of Function "main2.cold.1(*2)"
18# CHECK-DAG: BOLT-WARNING: Ignoring main2
19# CHECK-DAG: BOLT-WARNING: Ignoring main
20# CHECK-DAG: BOLT-WARNING: Ignoring main2.cold.1(*2)
21# CHECK: BOLT-WARNING: skipped 3 functions due to cold fragments
22  .text
23  .globl main
24  .type main, %function
25  .p2align 2
26main:
27LBB0:
28  andl $0xf, %ecx
29  cmpb $0x4, %cl
30  ## exit through ret
31  ja LBB3
32
33## jump table dispatch, jumping to label indexed by val in %ecx
34LBB1:
35  leaq JUMP_TABLE1(%rip), %r8
36  movzbl %cl, %ecx
37  movslq (%r8,%rcx,4), %rax
38  addq %rax, %r8
39  jmpq *%r8
40
41LBB2:
42  xorq %rax, %rax
43LBB3:
44  addq $0x8, %rsp
45  ret
46.size main, .-main
47
48  .globl main2
49  .type main2, %function
50  .p2align 2
51main2:
52LBB20:
53  andl $0xb, %ebx
54  cmpb $0x1, %cl
55  # exit through ret
56  ja LBB23
57
58## jump table dispatch, jumping to label indexed by val in %ecx
59LBB21:
60  leaq JUMP_TABLE2(%rip), %r8
61  movzbl %cl, %ecx
62  movslq (%r8,%rcx,4), %rax
63  addq %rax, %r8
64  jmpq *%r8
65
66LBB22:
67  xorq %rax, %rax
68LBB23:
69  addq $0x8, %rsp
70  ret
71.size main2, .-main2
72
73## cold fragment is only reachable through jump table
74  .globl main2.cold.1
75  .type main2.cold.1, %function
76main2.cold.1:
77  .globl main.cold.1
78  .type main.cold.1, %function
79  .p2align 2
80main.cold.1:
81  ## load bearing nop: pad LBB4 so that it can't be treated
82  ## as __builtin_unreachable by analyzeJumpTable
83  nop
84LBB4:
85  callq abort
86.size main.cold.1, .-main.cold.1
87
88  .rodata
89## jmp table, entries must be R_X86_64_PC32 relocs
90  .globl JUMP_TABLE1
91JUMP_TABLE1:
92  .long LBB2-JUMP_TABLE1
93  .long LBB3-JUMP_TABLE1
94  .long LBB4-JUMP_TABLE1
95  .long LBB3-JUMP_TABLE1
96
97  .globl JUMP_TABLE2
98JUMP_TABLE2:
99  .long LBB22-JUMP_TABLE2
100  .long LBB23-JUMP_TABLE2
101  .long LBB4-JUMP_TABLE2
102  .long LBB23-JUMP_TABLE2
103