Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / bolt / test / X86 / jt-symbol-disambiguation-3.s
blobc472b6bbf9c6a20ecf940a2361685bd7cced9c7b
1 # In this test case, we reproduce the behavior seen in gcc where the
2 # base address of a jump table is decremented by some number and ends up
3 # at the exact addess of a jump table from another function. After
4 # linking, the instruction references another jump table and that
5 # confuses BOLT.
6 # We repro here the following issue:
7 # Before assembler: Instruction operand is: jumptable - 32
8 # After linking: Instruction operand is: another_jumptable
10 # REQUIRES: system-linux, asserts
12 # XFAIL: *
14 # RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
15 # RUN: llvm-strip --strip-unneeded %t.o
16 # RUN: %clang %cflags -no-pie -nostartfiles -nostdlib -lc %t.o -o %t.exe -Wl,-q
18 # RUN: llvm-bolt %t.exe -o %t.exe.bolt --relocs=1 --lite=0 \
19 # RUN: --reorder-blocks=reverse
21 # Useful when manually testing this. Currently we just check that
22 # the test does not cause BOLT to assert.
23 # COM: %t.exe.bolt 1 2
25 .file "jt-symbol-disambiguation-3.s"
26 .text
28 # ----
29 # Func foo contains a jump table whose start is colocated with a
30 # jump table reference in another function. However, the other function
31 # does not use the first entries of it and is merely doing arithmetics
32 # to save the creation of unused first entries.
33 # ----
34 .globl foo
35 .type foo, @function
36 foo:
37 .cfi_startproc
38 xor %rax,%rax
39 cmpq $3, %rdi
40 ja .LBBAD
41 jmpq *.JT1(,%rdi,8)
42 .LBB1:
43 movl $0x4,%eax
44 jmp .LBB5
45 .LBB2:
46 movl $0x5,%eax
47 jmp .LBB5
48 .LBB3:
49 movl $0x6,%eax
50 jmp .LBB5
51 .LBB4:
52 movl $0x7,%eax
53 .LBB5:
54 retq
55 .LBBAD:
56 mov $1, %rdi
57 callq exit@PLT
58 retq
59 .cfi_endproc
60 .size foo, .-foo
62 # ----
63 # Func _start scans an object with indexed access using %rax * 8 as an
64 # index. However, %rax is known to be at least one, so the compiler
65 # loads the pointer for the base address as object - 8 instead of just
66 # object.
67 # ----
68 .globl _start
69 .type _start, @function
70 _start:
71 .cfi_startproc
72 movq (%rsp), %rdi
73 callq foo
74 movq $1, %rdi
75 cmpq $7, %rax
76 ja .LBB10
77 # Here the compiler uses the knowledge that the first four entries
78 # of the jump table are not accessed and subtracts 32 from the base
79 # address of it, so it doesn't have to allocate four unused entries in
80 # memory. Unfortunately this can confuse BOLT since it ends up being a
81 # direct reference to JT1, after linker is done.
82 jmpq *.JT2-32(,%rax,8)
83 .LBB6:
84 xorq %rdi, %rdi
85 jmp .LBB10
86 .LBB7:
87 xorq %rdi, %rdi
88 jmp .LBB10
89 .LBB8:
90 xorq %rdi, %rdi
91 jmp .LBB10
92 .LBB9:
93 xorq %rdi, %rdi
94 jmp .LBB10
95 .LBB10:
96 callq exit@PLT
97 retq
98 .cfi_endproc
99 .size _start, .-_start
101 # ----
102 # Data section
103 # ----
104 .section .rodata,"a",@progbits
105 .p2align 3
106 .JT1:
107 .quad .LBB1
108 .quad .LBB2
109 .quad .LBB3
110 .quad .LBB4
111 .JT2:
112 .quad .LBB6
113 .quad .LBB7
114 .quad .LBB8
115 .quad .LBB9