Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / bolt / test / X86 / split-func-icf.s
blob259c301864002b292b5d6a2a0a9f75fae402480e
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.
6 # REQUIRES: system-linux
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
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
26 main:
27 LBB0:
28 andl $0xf, %ecx
29 cmpb $0x4, %cl
30 # exit through ret
31 ja LBB3
33 # jump table dispatch, jumping to label indexed by val in %ecx
34 LBB1:
35 leaq JUMP_TABLE1(%rip), %r8
36 movzbl %cl, %ecx
37 movslq (%r8,%rcx,4), %rax
38 addq %rax, %r8
39 jmpq *%r8
41 LBB2:
42 xorq %rax, %rax
43 LBB3:
44 addq $0x8, %rsp
45 ret
46 .size main, .-main
48 .globl main2
49 .type main2, %function
50 .p2align 2
51 main2:
52 LBB20:
53 andl $0xb, %ebx
54 cmpb $0x1, %cl
55 # exit through ret
56 ja LBB23
58 # jump table dispatch, jumping to label indexed by val in %ecx
59 LBB21:
60 leaq JUMP_TABLE2(%rip), %r8
61 movzbl %cl, %ecx
62 movslq (%r8,%rcx,4), %rax
63 addq %rax, %r8
64 jmpq *%r8
66 LBB22:
67 xorq %rax, %rax
68 LBB23:
69 addq $0x8, %rsp
70 ret
71 .size main2, .-main2
73 # cold fragment is only reachable through jump table
74 .globl main2.cold.1
75 .type main2.cold.1, %function
76 main2.cold.1:
77 .globl main.cold.1
78 .type main.cold.1, %function
79 .p2align 2
80 main.cold.1:
81 # load bearing nop: pad LBB4 so that it can't be treated
82 # as __builtin_unreachable by analyzeJumpTable
83 nop
84 LBB4:
85 callq abort
86 .size main.cold.1, .-main.cold.1
88 .rodata
89 # jmp table, entries must be R_X86_64_PC32 relocs
90 .globl JUMP_TABLE1
91 JUMP_TABLE1:
92 .long LBB2-JUMP_TABLE1
93 .long LBB3-JUMP_TABLE1
94 .long LBB4-JUMP_TABLE1
95 .long LBB3-JUMP_TABLE1
97 .globl JUMP_TABLE2
98 JUMP_TABLE2:
99 .long LBB22-JUMP_TABLE2
100 .long LBB23-JUMP_TABLE2
101 .long LBB4-JUMP_TABLE2
102 .long LBB23-JUMP_TABLE2