xref: /llvm-project/bolt/test/X86/Inputs/jump-table-pic.s (revision 5a343994c3f5b546a4afc02a90ad7ecb2ce0d3ca)
1# Test case with a simple PIC-style jump table where the register containing
2# the jump table address is defined outside of the basic block containing the
3# jump on register.
4#
5# One of the destinations of the jump table points past the end of the function
6# similar to the code generated for __builtin_unreachable().
7
8	.text
9	.globl	main
10	.type	main, @function
11main:
12	.cfi_startproc
13	pushq	%rbx
14	.cfi_def_cfa_offset 16
15	.cfi_offset 3, -16
16	leaq	.LJUMPTABLE(%rip), %rcx
17.L13:
18	cmpl	$3, %edi
19	ja	.L2
20
21	movslq	(%rcx,%rdi,4), %rax
22	addq	%rcx, %rax
23	jmp	*%rax
24
25.L12:
26	movq	%rdi, %rax
27	popq	%rbx
28	.cfi_remember_state
29	.cfi_def_cfa_offset 8
30	ret
31
32.L5:
33	.cfi_restore_state
34	addq	$9, %rdi
35	jmp	.L12
36.L6:
37	addq	$8, %rdi
38	jmp	.L12
39.L2:
40	addq	$2, %rdi
41	jmp	.L12
42.LUNREACHABLE:
43	.cfi_endproc
44	.size	main, .-main
45
46	.section	.rodata
47	.align 4
48.LJUMPTABLE:
49	.long	.L2-.LJUMPTABLE
50	.long	.L6-.LJUMPTABLE
51	.long	.L5-.LJUMPTABLE
52	.long	.LUNREACHABLE-.LJUMPTABLE
53