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 -lite=0 -v=1 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 main
15# CHECK-DAG: BOLT-INFO: marking main2.cold.1(*2) as a fragment of main2
16# CHECK-DAG: BOLT-WARNING: Ignoring main2
17# CHECK-DAG: BOLT-WARNING: Ignoring main
18# CHECK-DAG: BOLT-WARNING: Ignoring main2.cold.1(*2)
19# CHECK: BOLT-WARNING: ignored 3 functions due to cold fragments
20  .text
21  .globl main
22  .type main, %function
23  .p2align 2
24main:
25LBB0:
26  andl $0xf, %ecx
27  cmpb $0x4, %cl
28  # exit through ret
29  ja LBB3
30
31# jump table dispatch, jumping to label indexed by val in %ecx
32LBB1:
33  leaq JUMP_TABLE1(%rip), %r8
34  movzbl %cl, %ecx
35  movslq (%r8,%rcx,4), %rax
36  addq %rax, %r8
37  jmpq *%r8
38
39LBB2:
40  xorq %rax, %rax
41LBB3:
42  addq $0x8, %rsp
43  ret
44.size main, .-main
45
46  .globl main2
47  .type main2, %function
48  .p2align 2
49main2:
50LBB20:
51  andl $0xb, %ebx
52  cmpb $0x1, %cl
53  # exit through ret
54  ja LBB23
55
56# jump table dispatch, jumping to label indexed by val in %ecx
57LBB21:
58  leaq JUMP_TABLE2(%rip), %r8
59  movzbl %cl, %ecx
60  movslq (%r8,%rcx,4), %rax
61  addq %rax, %r8
62  jmpq *%r8
63
64LBB22:
65  xorq %rax, %rax
66LBB23:
67  addq $0x8, %rsp
68  ret
69.size main2, .-main2
70
71# cold fragment is only reachable through jump table
72  .globl main2.cold.1
73  .type main2.cold.1, %function
74main2.cold.1:
75  .globl main.cold.1
76  .type main.cold.1, %function
77  .p2align 2
78main.cold.1:
79  # load bearing nop: pad LBB4 so that it can't be treated
80  # as __builtin_unreachable by analyzeJumpTable
81  nop
82LBB4:
83  callq abort
84.size main.cold.1, .-main.cold.1
85
86  .rodata
87# jmp table, entries must be R_X86_64_PC32 relocs
88  .globl JUMP_TABLE1
89JUMP_TABLE1:
90  .long LBB2-JUMP_TABLE1
91  .long LBB3-JUMP_TABLE1
92  .long LBB4-JUMP_TABLE1
93  .long LBB3-JUMP_TABLE1
94
95  .globl JUMP_TABLE2
96JUMP_TABLE2:
97  .long LBB22-JUMP_TABLE2
98  .long LBB23-JUMP_TABLE2
99  .long LBB4-JUMP_TABLE2
100  .long LBB23-JUMP_TABLE2
101