Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / ELF / arm-thumb-range-thunk-os-no-ext.s
blob3daf1e52df9b5bc858d113e06063db9617634766
1 // REQUIRES: arm
2 // RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=thumbv4t-none-linux-gnueabi %s -o %t.o
3 // RUN: ld.lld %t.o -o %t2
4 /// The output file is large, most of it zeroes. We dissassemble only the
5 /// parts we need to speed up the test and avoid a large output file.
6 // RUN: llvm-objdump --no-show-raw-insn -d %t2 --start-address=0x100000 --stop-address=0x10000c | FileCheck --check-prefix=CHECK1 %s
7 // RUN: llvm-objdump --no-show-raw-insn -d %t2 --start-address=0x200000 --stop-address=0x200002 | FileCheck --check-prefix=CHECK2 %s
8 // RUN: llvm-objdump --no-show-raw-insn -d %t2 --start-address=0x300000 --stop-address=0x300002 | FileCheck --check-prefix=CHECK3 %s
9 // RUN: llvm-objdump --no-show-raw-insn -d %t2 --start-address=0x400000 --stop-address=0x400028 | FileCheck --check-prefix=CHECK4 %s
10 // RUN: llvm-objdump --no-show-raw-insn -d %t2 --start-address=0x700000 --stop-address=0x700014 | FileCheck --check-prefix=CHECK5 %s
11 // RUN: llvm-objdump --no-show-raw-insn -d %t2 --start-address=0x800000 --stop-address=0x800004 | FileCheck --check-prefix=CHECK6 %s
12 // RUN: llvm-objdump --no-show-raw-insn -d %t2 --start-address=0x900000 --stop-address=0x900004 | FileCheck --check-prefix=CHECK7 %s
13 // RUN: llvm-objdump --no-show-raw-insn -d %t2 --start-address=0xa00000 --stop-address=0xa00018 | FileCheck --check-prefix=CHECK8 %s
14 // RUN: llvm-objdump --no-show-raw-insn -d %t2 --start-address=0xb00000 --stop-address=0xb00004 | FileCheck --check-prefix=CHECK9 %s
16 /// Test the Range extension Thunks for Thumb when all the code is in a single
17 /// OutputSection. The Thumb BL instruction has a range of 4Mb. We create a
18 /// series of functions a megabyte apart. We expect range extension thunks to be
19 /// created when a branch is out of range. Thunks will be reused whenever they
20 /// are in range.
21 .syntax unified
23 /// Define a function aligned on a megabyte boundary.
24 .macro FUNCTION suff
25 .section .text.\suff\(), "ax", %progbits
26 .thumb
27 .balign 0x100000
28 .globl tfunc\suff\()
29 .type tfunc\suff\(), %function
30 tfunc\suff\():
31 bx lr
32 .endm
34 .section .text, "ax", %progbits
35 .thumb
36 .globl _start
37 _start:
38 /// tfunc00 and tfunc03 are within 4MB, so no Range Thunks expected.
39 bl tfunc00
40 bl tfunc03
41 /// tfunc04 is > 4MB away, expect a Range Thunk to be generated, to go into
42 /// the first of the pre-created ThunkSections.
43 bl tfunc04
45 // CHECK1-LABEL: <_start>:
46 // CHECK1-NEXT: 100000: bl 0x200000 <tfunc00> @ imm = #0xffffc
47 // CHECK1-NEXT: bl 0x500000 <tfunc03> @ imm = #0x3ffff8
48 // CHECK1-NEXT: bl 0x400008 <__Thumbv4ABSLongThunk_tfunc04> @ imm = #0x2ffffc
50 FUNCTION 00
51 // CHECK2-LABEL: <tfunc00>:
52 // CHECK2-NEXT: 200000: bx lr
54 FUNCTION 01
55 // CHECK3-LABEL: <tfunc01>:
56 // CHECK3-NEXT: 300000: bx lr
58 FUNCTION 02
59 bl tfunc07
60 /// The thunks should not generate a v7-style short thunk.
61 // CHECK4-LABEL: <tfunc02>:
62 // CHECK4-NEXT: 400000: bx lr
63 // CHECK4-NEXT: bl 0x400018 <__Thumbv4ABSLongThunk_tfunc07> @ imm = #0x12
64 // CHECK4-NEXT: bmi 0x3fffb2 <tfunc01+0xfffb2> @ imm = #-0x58
65 // CHECK4-EMPTY:
66 // CHECK4-NEXT: <__Thumbv4ABSLongThunk_tfunc04>:
67 // CHECK4-NEXT: 400008: bx pc
68 // CHECK4-NEXT: b 0x400008 <__Thumbv4ABSLongThunk_tfunc04> @ imm = #-0x6
69 // CHECK4-NEXT: 40000c: ldr r12, [pc] @ 0x400014 <__Thumbv4ABSLongThunk_tfunc04+0xc>
70 // CHECK4-NEXT: bx r12
71 // CHECK4-NEXT: 400014: 01 00 60 00 .word 0x00600001
72 // CHECK4-EMPTY:
73 // CHECK4-NEXT: <__Thumbv4ABSLongThunk_tfunc07>:
74 // CHECK4-NEXT: 400018: bx pc
75 // CHECK4-NEXT: b 0x400018 <__Thumbv4ABSLongThunk_tfunc07> @ imm = #-0x6
76 // CHECK4-NEXT: 40001c: ldr r12, [pc] @ 0x400024 <__Thumbv4ABSLongThunk_tfunc07+0xc>
77 // CHECK4-NEXT: bx r12
78 // CHECK4-NEXT: 400024: 01 00 90 00 .word 0x00900001
80 FUNCTION 03
81 FUNCTION 04
82 FUNCTION 05
83 // CHECK5-LABEL: <tfunc05>:
84 // CHECK5-NEXT: 700000: bx lr
85 // CHECK5-NEXT: bmi 0x6fffae <tfunc04+0xfffae> @ imm = #-0x58
86 // CHECK5-EMPTY:
87 // CHECK5-NEXT: <__Thumbv4ABSLongThunk_tfunc03>:
88 // CHECK5-NEXT: 700004: bx pc
89 // CHECK5-NEXT: b 0x700004 <__Thumbv4ABSLongThunk_tfunc03> @ imm = #-0x6
90 // CHECK5-NEXT: 700008: ldr r12, [pc] @ 0x700010 <__Thumbv4ABSLongThunk_tfunc03+0xc>
91 // CHECK5-NEXT: bx r12
92 // CHECK5-NEXT: 700010: 01 00 50 00 .word 0x00500001
94 FUNCTION 06
95 /// The backwards branch is within range, so no range extension necessary.
96 bl tfunc04
97 // CHECK6-LABEL: <tfunc06>:
98 // CHECK6-NEXT: 800000: bx lr
99 // CHECK6-NEXT: bl 0x600000 <tfunc04> @ imm = #-0x200006
101 FUNCTION 07
102 /// The backwards branch is out of range.
103 bl tfunc03
104 // CHECK7-LABEL: <tfunc07>:
105 // CHECK7-NEXT: 900000: bx lr
106 // CHECK7-NEXT: bl 0x700004 <__Thumbv4ABSLongThunk_tfunc03> @ imm = #-0x200002
108 FUNCTION 08
109 /// 2nd backwards branch outside of range to same fn. Should share thunk with
110 /// previous call.
111 bl tfunc03
112 // CHECK8-LABEL: <tfunc08>:
113 // CHECK8-NEXT: a00000: bx lr
114 // CHECK8-NEXT: bl 0x700004 <__Thumbv4ABSLongThunk_tfunc03> @ imm = #-0x300002
115 // CHECK8-NEXT: bmi 0x9fffb2 <tfunc07+0xfffb2> @ imm = #-0x58
116 // CHECK8-EMPTY:
117 // CHECK8-NEXT: <__Thumbv4ABSLongThunk_tfunc03>:
118 // CHECK8-NEXT: a00008: bx pc
119 // CHECK8-NEXT: a0000a: b 0xa00008 <__Thumbv4ABSLongThunk_tfunc03> @ imm = #-0x6
120 // CHECK8-NEXT: a0000c: ldr r12, [pc] @ 0xa00014 <__Thumbv4ABSLongThunk_tfunc03+0xc>
121 // CHECK8-NEXT: a00010: bx r12
122 // CHECK8-NEXT: a00014: 01 00 50 00 .word 0x00500001
124 FUNCTION 09
125 /// This call is out of range of ThunkSection at 0700004.
126 /// These 3 calls to tfunc03 could have used the same thunk (section), but
127 /// we are not that sophisticated.
128 bl tfunc03
129 // CHECK9-LABEL: <tfunc09>:
130 // CHECK9-NEXT: b00000: bx lr
131 // CHECK9-NEXT: bl 0xa00008 <__Thumbv4ABSLongThunk_tfunc03> @ imm = #-0xffffe
132 FUNCTION 10
133 FUNCTION 11