xref: /llvm-project/llvm/test/MC/ARM/ldr-pseudo.s (revision 5193c80830995d951049db7bcf510e38b0b1521e)
1e407d093SDavid Peixotto@ This test has a partner (ldr-pseudo-darwin.s) that contains matching
2e407d093SDavid Peixotto@ tests for the ldr-pseudo on darwin targets. We need separate files
3e407d093SDavid Peixotto@ because the syntax for switching sections and temporary labels differs
4e407d093SDavid Peixotto@ between darwin and linux. Any tests added here should have a matching
5e407d093SDavid Peixotto@ test added there.
6e407d093SDavid Peixotto
7608cb5deSRenato Golin@RUN: llvm-mc -triple   armv7-unknown-linux-gnueabi %s | FileCheck --check-prefix=CHECK-ARM --check-prefix=CHECK %s
8608cb5deSRenato Golin@RUN: llvm-mc -triple   armv5-unknown-linux-gnueabi %s | FileCheck --check-prefix=CHECK-ARMV5 --check-prefix=CHECK %s
9608cb5deSRenato Golin@RUN: llvm-mc -triple thumbv5-unknown-linux-gnueabi %s | FileCheck --check-prefix=CHECK-THUMB --check-prefix=CHECK %s
10608cb5deSRenato Golin@RUN: llvm-mc -triple thumbv7-unknown-linux-gnueabi %s | FileCheck --check-prefix=CHECK-THUMB2 --check-prefix=CHECK %s
11608cb5deSRenato Golin@RUN: llvm-mc -triple thumbv8m.base-unknown-linux-gnueabi %s | FileCheck --check-prefix=CHECK-BASELINE --check-prefix=CHECK %s
12e407d093SDavid Peixotto@
13e407d093SDavid Peixotto@ Check that large constants are converted to ldr from constant pool
14e407d093SDavid Peixotto@
15e407d093SDavid Peixotto@ simple test
16e407d093SDavid Peixotto.section b,"ax",%progbits
17e407d093SDavid Peixotto@ CHECK-LABEL: f3:
18e407d093SDavid Peixottof3:
19d5491ab1SRenato Golin  ldr r0, =0x10002
20f010b985SOliver Stannard@ CHECK: ldr r0, .Ltmp[[TMP0:[0-9]+]]
21e407d093SDavid Peixotto
22e407d093SDavid Peixotto@ loading multiple constants
23e407d093SDavid Peixotto.section c,"ax",%progbits
24e407d093SDavid Peixotto@ CHECK-LABEL: f4:
25e407d093SDavid Peixottof4:
26d5491ab1SRenato Golin  ldr r0, =0x10003
27f010b985SOliver Stannard@ CHECK: ldr r0, .Ltmp[[TMP1:[0-9]+]]
28e407d093SDavid Peixotto  adds r0, r0, #1
29e407d093SDavid Peixotto  adds r0, r0, #1
30e407d093SDavid Peixotto  adds r0, r0, #1
31e407d093SDavid Peixotto  adds r0, r0, #1
32d5491ab1SRenato Golin  ldr r0, =0x10004
33f010b985SOliver Stannard@ CHECK: ldr r0, .Ltmp[[TMP2:[0-9]+]]
34e407d093SDavid Peixotto  adds r0, r0, #1
35e407d093SDavid Peixotto  adds r0, r0, #1
36e407d093SDavid Peixotto
37e407d093SDavid Peixotto@ TODO: the same constants should have the same constant pool location
38e407d093SDavid Peixotto.section d,"ax",%progbits
39e407d093SDavid Peixotto@ CHECK-LABEL: f5:
40e407d093SDavid Peixottof5:
41d5491ab1SRenato Golin  ldr r0, =0x10005
42f010b985SOliver Stannard@ CHECK: ldr r0, .Ltmp[[TMP3:[0-9]+]]
43e407d093SDavid Peixotto  adds r0, r0, #1
44e407d093SDavid Peixotto  adds r0, r0, #1
45e407d093SDavid Peixotto  adds r0, r0, #1
46e407d093SDavid Peixotto  adds r0, r0, #1
47e407d093SDavid Peixotto  adds r0, r0, #1
48e407d093SDavid Peixotto  adds r0, r0, #1
49e407d093SDavid Peixotto  adds r0, r0, #1
50d5491ab1SRenato Golin  ldr r0, =0x10005
51*5193c808SJames Molloy@ CHECK: ldr r0, .Ltmp[[TMP3:[0-9]+]]
52e407d093SDavid Peixotto  adds r0, r0, #1
53e407d093SDavid Peixotto  adds r0, r0, #1
54e407d093SDavid Peixotto  adds r0, r0, #1
55e407d093SDavid Peixotto  adds r0, r0, #1
56e407d093SDavid Peixotto  adds r0, r0, #1
57e407d093SDavid Peixotto  adds r0, r0, #1
58e407d093SDavid Peixotto
59e407d093SDavid Peixotto@ a section defined in multiple pieces should be merged and use a single constant pool
60e407d093SDavid Peixotto.section e,"ax",%progbits
61e407d093SDavid Peixotto@ CHECK-LABEL: f6:
62e407d093SDavid Peixottof6:
63e407d093SDavid Peixotto  ldr r0, =0x10006
64f010b985SOliver Stannard@ CHECK: ldr r0, .Ltmp[[TMP5:[0-9]+]]
65e407d093SDavid Peixotto  adds r0, r0, #1
66e407d093SDavid Peixotto  adds r0, r0, #1
67e407d093SDavid Peixotto  adds r0, r0, #1
68e407d093SDavid Peixotto
69e407d093SDavid Peixotto.section f, "ax", %progbits
70e407d093SDavid Peixotto@ CHECK-LABEL: f7:
71e407d093SDavid Peixottof7:
72e407d093SDavid Peixotto  adds r0, r0, #1
73e407d093SDavid Peixotto  adds r0, r0, #1
74e407d093SDavid Peixotto  adds r0, r0, #1
75e407d093SDavid Peixotto
76e407d093SDavid Peixotto.section e, "ax", %progbits
77e407d093SDavid Peixotto@ CHECK-LABEL: f8:
78e407d093SDavid Peixottof8:
79e407d093SDavid Peixotto  adds r0, r0, #1
80e407d093SDavid Peixotto  ldr r0, =0x10007
81f010b985SOliver Stannard@ CHECK: ldr r0, .Ltmp[[TMP6:[0-9]+]]
82e407d093SDavid Peixotto  adds r0, r0, #1
83e407d093SDavid Peixotto  adds r0, r0, #1
84e407d093SDavid Peixotto
85e407d093SDavid Peixotto@
86e407d093SDavid Peixotto@ Check that symbols can be loaded using ldr pseudo
87e407d093SDavid Peixotto@
88e407d093SDavid Peixotto
89e407d093SDavid Peixotto@ load an undefined symbol
90e407d093SDavid Peixotto.section g,"ax",%progbits
91e407d093SDavid Peixotto@ CHECK-LABEL: f9:
92e407d093SDavid Peixottof9:
93e407d093SDavid Peixotto  ldr r0, =foo
94f010b985SOliver Stannard@ CHECK: ldr r0, .Ltmp[[TMP7:[0-9]+]]
95e407d093SDavid Peixotto
96e407d093SDavid Peixotto@ load a symbol from another section
97e407d093SDavid Peixotto.section h,"ax",%progbits
98e407d093SDavid Peixotto@ CHECK-LABEL: f10:
99e407d093SDavid Peixottof10:
100e407d093SDavid Peixotto  ldr r0, =f5
101f010b985SOliver Stannard@ CHECK: ldr r0, .Ltmp[[TMP8:[0-9]+]]
102e407d093SDavid Peixotto
103e407d093SDavid Peixotto@ load a symbol from the same section
104e407d093SDavid Peixotto.section i,"ax",%progbits
105e407d093SDavid Peixotto@ CHECK-LABEL: f11:
106e407d093SDavid Peixottof11:
107e407d093SDavid Peixotto  ldr r0, =f12
108f010b985SOliver Stannard@ CHECK: ldr r0, .Ltmp[[TMP9:[0-9]+]]
109e407d093SDavid Peixotto
110e407d093SDavid Peixotto@ CHECK-LABEL: f12:
111e407d093SDavid Peixottof12:
112e407d093SDavid Peixotto  adds r0, r0, #1
113e407d093SDavid Peixotto  adds r0, r0, #1
114e407d093SDavid Peixotto
115e407d093SDavid Peixotto.section j,"ax",%progbits
116e407d093SDavid Peixotto@ mix of symbols and constants
117e407d093SDavid Peixotto@ CHECK-LABEL: f13:
118e407d093SDavid Peixottof13:
119e407d093SDavid Peixotto  adds r0, r0, #1
120e407d093SDavid Peixotto  adds r0, r0, #1
121d5491ab1SRenato Golin  ldr r0, =0x10008
122f010b985SOliver Stannard@ CHECK: ldr r0, .Ltmp[[TMP10:[0-9]+]]
123e407d093SDavid Peixotto  adds r0, r0, #1
124e407d093SDavid Peixotto  adds r0, r0, #1
125e407d093SDavid Peixotto  ldr r0, =bar
126f010b985SOliver Stannard@ CHECK: ldr r0, .Ltmp[[TMP11:[0-9]+]]
127e407d093SDavid Peixotto  adds r0, r0, #1
128e407d093SDavid Peixotto  adds r0, r0, #1
129e407d093SDavid Peixotto@
130e407d093SDavid Peixotto@ Check for correct usage in other contexts
131e407d093SDavid Peixotto@
132e407d093SDavid Peixotto
133e407d093SDavid Peixotto@ usage in macro
134e407d093SDavid Peixotto.macro useit_in_a_macro
135d5491ab1SRenato Golin  ldr r0, =0x10009
136e407d093SDavid Peixotto  ldr r0, =baz
137e407d093SDavid Peixotto.endm
138e407d093SDavid Peixotto.section k,"ax",%progbits
139e407d093SDavid Peixotto@ CHECK-LABEL: f14:
140e407d093SDavid Peixottof14:
141e407d093SDavid Peixotto  useit_in_a_macro
142f010b985SOliver Stannard@ CHECK: ldr r0, .Ltmp[[TMP12:[0-9]+]]
143f010b985SOliver Stannard@ CHECK: ldr r0, .Ltmp[[TMP13:[0-9]+]]
144e407d093SDavid Peixotto
145e407d093SDavid Peixotto@ usage with expressions
146e407d093SDavid Peixotto.section l, "ax", %progbits
147e407d093SDavid Peixotto@ CHECK-LABEL: f15:
148e407d093SDavid Peixottof15:
149d5491ab1SRenato Golin  ldr r0, =0x10001+9
150f010b985SOliver Stannard@ CHECK: ldr r0, .Ltmp[[TMP14:[0-9]+]]
151e407d093SDavid Peixotto  adds r0, r0, #1
152e407d093SDavid Peixotto  ldr r0, =bar+4
153f010b985SOliver Stannard@ CHECK: ldr r0, .Ltmp[[TMP15:[0-9]+]]
154e407d093SDavid Peixotto  adds r0, r0, #1
155e407d093SDavid Peixotto
156608cb5deSRenato Golin@ transformation to mov
157608cb5deSRenato Golin.section m, "ax", %progbits
158608cb5deSRenato Golin@ CHECK-LABEL: f16:
159608cb5deSRenato Golinf16:
160608cb5deSRenato Golin
161608cb5deSRenato Golin@ Representable in ARM, and Thumb with support mov.w or movw
162608cb5deSRenato Golin  ldr r1, =0x1
163608cb5deSRenato Golin@ CHECK-ARM: mov r1, #1
164608cb5deSRenato Golin@ CHECK-ARMV5: mov r1, #1
165608cb5deSRenato Golin@ CHECK-THUMB: ldr r1, .Ltmp[[TMP16:[0-9]+]]
166608cb5deSRenato Golin@ CHECK-THUMB2: mov.w r1, #1
167608cb5deSRenato Golin@ CHECK-BASELINE: movw r1, #1
168608cb5deSRenato Golin
169608cb5deSRenato Golin@ Immediate is representable in A1 and T2 modified immediate only not movw
170608cb5deSRenato Golin  ldr r2, =0x120000
171608cb5deSRenato Golin@ CHECK-ARM: mov r2, #1179648
172608cb5deSRenato Golin@ CHECK-ARMV5: mov r2, #1179648
173608cb5deSRenato Golin@ CHECK-THUMB: ldr r2, .Ltmp[[TMP17:[0-9]+]]
174608cb5deSRenato Golin@ CHECK-THUMB2: mov.w r2, #1179648
175608cb5deSRenato Golin@ CHECK-BASELINE: ldr r2, .Ltmp[[TMP16:[0-9]+]]
176608cb5deSRenato Golin
177608cb5deSRenato Golin@ Immediate can be represented only with movw instruction
178608cb5deSRenato Golin  ldr r3, =0x1234
179608cb5deSRenato Golin@ CHECK-ARM: movw r3, #4660
180608cb5deSRenato Golin@ CHECK-ARMV5: ldr r3, .Ltmp[[TMP16:[0-9]+]]
181608cb5deSRenato Golin@ CHECK-THUMB: ldr r3, .Ltmp[[TMP18:[0-9]+]]
182608cb5deSRenato Golin@ CHECK-THUMB2: movw r3, #4660
183608cb5deSRenato Golin@ CHECK-BASELINE: movw r3, #4660
184608cb5deSRenato Golin
185608cb5deSRenato Golin@ Immediate can be represented only with T2 modified immediate
186608cb5deSRenato Golin  ldr r4, =0xabababab
187608cb5deSRenato Golin@ CHECK-ARM: ldr r4, .Ltmp[[TMP16:[0-9]+]]
188608cb5deSRenato Golin@ CHECK-ARMV5: ldr r4, .Ltmp[[TMP17:[0-9]+]]
189608cb5deSRenato Golin@ CHECK-THUMB: ldr r4, .Ltmp[[TMP19:[0-9]+]]
190608cb5deSRenato Golin@ CHECK-THUMB2: mov.w r4, #2880154539
191608cb5deSRenato Golin@ CHECK-BASELINE: ldr r4, .Ltmp[[TMP17:[0-9]+]]
192608cb5deSRenato Golin
193608cb5deSRenato Golin@ Immediate can be represented only with A1 modified immediate
194608cb5deSRenato Golin  ldr r5, =0x1000000b
195608cb5deSRenato Golin@ CHECK-ARM: mov r5, #268435467
196608cb5deSRenato Golin@ CHECK-ARMV5: mov r5, #268435467
197608cb5deSRenato Golin@ CHECK-THUMB: ldr r5, .Ltmp[[TMP20:[0-9]+]]
198608cb5deSRenato Golin@ CHECK-THUMB2: ldr r5, .Ltmp[[TMP16:[0-9]+]]
199608cb5deSRenato Golin@ CHECK-BASELINE: ldr r5, .Ltmp[[TMP18:[0-9]+]]
200608cb5deSRenato Golin
201608cb5deSRenato Golin@ Negative numbers can be used with MVN or in Thumb2 with modified immediate
202608cb5deSRenato Golin  ldr r6, =-1
203608cb5deSRenato Golin@ CHECK-ARM: mvn r6, #0
204608cb5deSRenato Golin@ CHECK-ARMV5: mvn r6, #0
205608cb5deSRenato Golin@ CHECK-THUMB: ldr r6, .Ltmp[[TMP21:[0-9]+]]
206608cb5deSRenato Golin@ CHECK-THUMB2: mov.w r6, #-1
207608cb5deSRenato Golin@ CHECK-BASELINE: ldr r6, .Ltmp[[TMP19:[0-9]+]]
208608cb5deSRenato Golin  ldr r7, =-0x100
209608cb5deSRenato Golin@ CHECK-ARM: mvn r7, #255
210608cb5deSRenato Golin@ CHECK-ARMV5: mvn r7, #255
211608cb5deSRenato Golin@ CHECK-THUMB: ldr r7, .Ltmp[[TMP22:[0-9]+]]
212608cb5deSRenato Golin@ CHECK-THUMB2: mvn r7, #255
213608cb5deSRenato Golin@ CHECK-BASELINE: ldr r7, .Ltmp[[TMP20:[0-9]+]]
214608cb5deSRenato Golin
215608cb5deSRenato Golin@ Constant expressions can be used
216608cb5deSRenato Golin  .equ expr, 0x10 + 0x10
217608cb5deSRenato Golin  ldr r0, = expr
218608cb5deSRenato Golin@ CHECK-ARM: mov r0, #32
219608cb5deSRenato Golin@ CHECK-ARMV5: mov r0, #32
220608cb5deSRenato Golin@ CHECK-THUMB: ldr r0, .Ltmp[[TMP23:[0-9]+]]
221608cb5deSRenato Golin@ CHECK-THUMB2: mov.w r0, #32
222608cb5deSRenato Golin@ CHECK-BASELINE: movw r0, #32
223608cb5deSRenato Golin  ldr r1, = expr - 0x10
224608cb5deSRenato Golin@ CHECK-ARM: mov r1, #16
225608cb5deSRenato Golin@ CHECK-ARMV5: mov r1, #16
226608cb5deSRenato Golin@ CHECK-THUMB: ldr r1, .Ltmp[[TMP24:[0-9]+]]
227608cb5deSRenato Golin@ CHECK-THUMB2: mov.w r1, #16
228608cb5deSRenato Golin@ CHECK-BASELINE: movw r1, #16
229608cb5deSRenato Golin
230608cb5deSRenato Golin@ usage of translation in macro
231608cb5deSRenato Golin.macro usemov_in_a_macro
232608cb5deSRenato Golin  ldr r2, =0x3
233608cb5deSRenato Golin  ldr r3, =expr
234608cb5deSRenato Golin.endm
235608cb5deSRenato Golin@ CHECK-LABEL: f17:
236608cb5deSRenato Golinf17:
237608cb5deSRenato Golin  usemov_in_a_macro
238608cb5deSRenato Golin@ CHECK-ARM: mov r2, #3
239608cb5deSRenato Golin@ CHECK-ARM: mov r3, #32
240608cb5deSRenato Golin@ CHECK-ARMV5: mov r2, #3
241608cb5deSRenato Golin@ CHECK-ARMV5: mov r3, #32
242608cb5deSRenato Golin@ CHECK-THUMB: ldr r2, .Ltmp[[TMP25:[0-9]+]]
243608cb5deSRenato Golin@ CHECK-THUMB: ldr r3, .Ltmp[[TMP26:[0-9]+]]
244608cb5deSRenato Golin@ CHECK-THUMB2: mov.w r2, #3
245608cb5deSRenato Golin@ CHECK-THUMB2: mov.w r3, #32
246608cb5deSRenato Golin@ CHECK-BASELINE: movw r2, #3
247608cb5deSRenato Golin@ CHECK-BASELINE: movw r3, #32
248e407d093SDavid Peixotto@
249e407d093SDavid Peixotto@ Constant Pools
250e407d093SDavid Peixotto@
251e407d093SDavid Peixotto@ CHECK: .section b,"ax",%progbits
25214d8436cSDan Gohman@ CHECK: .p2align 2
253f010b985SOliver Stannard@ CHECK: .Ltmp[[TMP0]]
254d5491ab1SRenato Golin@ CHECK: .long 65538
255e407d093SDavid Peixotto
256e407d093SDavid Peixotto@ CHECK: .section c,"ax",%progbits
25714d8436cSDan Gohman@ CHECK: .p2align 2
258f010b985SOliver Stannard@ CHECK: .Ltmp[[TMP1]]
259e407d093SDavid Peixotto@ CHECK: .long 65539
260d5491ab1SRenato Golin@ CHECK: .Ltmp[[TMP2]]
261d5491ab1SRenato Golin@ CHECK: .long 65540
262e407d093SDavid Peixotto
263e407d093SDavid Peixotto@ CHECK: .section d,"ax",%progbits
26414d8436cSDan Gohman@ CHECK: .p2align 2
265f010b985SOliver Stannard@ CHECK: .Ltmp[[TMP3]]
266d5491ab1SRenato Golin@ CHECK: .long 65541
267e407d093SDavid Peixotto
268e407d093SDavid Peixotto@ CHECK: .section e,"ax",%progbits
26914d8436cSDan Gohman@ CHECK: .p2align 2
270f010b985SOliver Stannard@ CHECK: .Ltmp[[TMP5]]
271e407d093SDavid Peixotto@ CHECK: .long 65542
272f010b985SOliver Stannard@ CHECK: .Ltmp[[TMP6]]
273e407d093SDavid Peixotto@ CHECK: .long 65543
274e407d093SDavid Peixotto
275e407d093SDavid Peixotto@ Should not switch to section because it has no constant pool
276e407d093SDavid Peixotto@ CHECK-NOT: .section f,"ax",%progbits
277e407d093SDavid Peixotto
278e407d093SDavid Peixotto@ CHECK: .section g,"ax",%progbits
27914d8436cSDan Gohman@ CHECK: .p2align 2
280f010b985SOliver Stannard@ CHECK: .Ltmp[[TMP7]]
281e407d093SDavid Peixotto@ CHECK: .long foo
282e407d093SDavid Peixotto
283e407d093SDavid Peixotto@ CHECK: .section h,"ax",%progbits
28414d8436cSDan Gohman@ CHECK: .p2align 2
285f010b985SOliver Stannard@ CHECK: .Ltmp[[TMP8]]
286e407d093SDavid Peixotto@ CHECK: .long f5
287e407d093SDavid Peixotto
288e407d093SDavid Peixotto@ CHECK: .section i,"ax",%progbits
28914d8436cSDan Gohman@ CHECK: .p2align 2
290f010b985SOliver Stannard@ CHECK: .Ltmp[[TMP9]]
291e407d093SDavid Peixotto@ CHECK: .long f12
292e407d093SDavid Peixotto
293e407d093SDavid Peixotto@ CHECK: .section j,"ax",%progbits
29414d8436cSDan Gohman@ CHECK: .p2align 2
295f010b985SOliver Stannard@ CHECK: .Ltmp[[TMP10]]
296d5491ab1SRenato Golin@ CHECK: .long 65544
297f010b985SOliver Stannard@ CHECK: .Ltmp[[TMP11]]
298e407d093SDavid Peixotto@ CHECK: .long bar
299e407d093SDavid Peixotto
300e407d093SDavid Peixotto@ CHECK: .section k,"ax",%progbits
30114d8436cSDan Gohman@ CHECK: .p2align 2
302f010b985SOliver Stannard@ CHECK: .Ltmp[[TMP12]]
303d5491ab1SRenato Golin@ CHECK: .long 65545
304f010b985SOliver Stannard@ CHECK: .Ltmp[[TMP13]]
305e407d093SDavid Peixotto@ CHECK: .long baz
306e407d093SDavid Peixotto
307e407d093SDavid Peixotto@ CHECK: .section l,"ax",%progbits
30814d8436cSDan Gohman@ CHECK: .p2align 2
309f010b985SOliver Stannard@ CHECK: .Ltmp[[TMP14]]
310d5491ab1SRenato Golin@ CHECK: .long 65546
311f010b985SOliver Stannard@ CHECK: .Ltmp[[TMP15]]
312e407d093SDavid Peixotto@ CHECK: .long bar+4
313