• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//RUN: llvm-mc  -triple=aarch64-linux-gnu -print-imm-hex %s | FileCheck %s
2
3//
4// Check that large constants are converted to ldr from constant pool
5//
6// simple test
7.section a, "ax", @progbits
8// CHECK-LABEL: f1:
9f1:
10  ldr x0, =0x1234
11// CHECK: mov    x0, #0x1234
12  ldr w1, =0x4567
13// CHECK:  mov    w1, #0x4567
14  ldr x0, =0x12340000
15// CHECK:  mov    x0, #0x12340000
16  ldr w1, =0x45670000
17// CHECK: mov    w1, #0x45670000
18  ldr x0, =0xabc00000000
19// CHECK: mov    x0, #0xabc00000000
20  ldr x0, =0xbeef000000000000
21// CHECK: mov    x0, #-0x4111000000000000
22
23.section b,"ax",@progbits
24// CHECK-LABEL: f3:
25f3:
26  ldr w0, =0x10001
27// CHECK: ldr w0, .Ltmp[[TMP0:[0-9]+]]
28
29// loading multiple constants
30.section c,"ax",@progbits
31// CHECK-LABEL: f4:
32f4:
33  ldr w0, =0x10002
34// CHECK: ldr w0, .Ltmp[[TMP1:[0-9]+]]
35  adds x0, x0, #1
36  adds x0, x0, #1
37  adds x0, x0, #1
38  adds x0, x0, #1
39  ldr w0, =0x10003
40// CHECK: ldr w0, .Ltmp[[TMP2:[0-9]+]]
41  adds x0, x0, #1
42  adds x0, x0, #1
43
44// TODO: the same constants should have the same constant pool location
45.section d,"ax",@progbits
46// CHECK-LABEL: f5:
47f5:
48  ldr w0, =0x10004
49// CHECK: ldr w0, .Ltmp[[TMP3:[0-9]+]]
50  adds x0, x0, #1
51  adds x0, x0, #1
52  adds x0, x0, #1
53  adds x0, x0, #1
54  adds x0, x0, #1
55  adds x0, x0, #1
56  adds x0, x0, #1
57  ldr w0, =0x10004
58// CHECK: ldr w0, .Ltmp[[TMP4:[0-9]+]]
59  adds x0, x0, #1
60  adds x0, x0, #1
61  adds x0, x0, #1
62  adds x0, x0, #1
63  adds x0, x0, #1
64  adds x0, x0, #1
65
66// a section defined in multiple pieces should be merged and use a single constant pool
67.section e,"ax",@progbits
68// CHECK-LABEL: f6:
69f6:
70  ldr w0, =0x10006
71// CHECK: ldr w0, .Ltmp[[TMP5:[0-9]+]]
72  adds x0, x0, #1
73  adds x0, x0, #1
74  adds x0, x0, #1
75
76.section f, "ax", @progbits
77// CHECK-LABEL: f7:
78f7:
79  adds x0, x0, #1
80  adds x0, x0, #1
81  adds x0, x0, #1
82
83.section e, "ax", @progbits
84// CHECK-LABEL: f8:
85f8:
86  adds x0, x0, #1
87  ldr w0, =0x10007
88// CHECK: ldr w0, .Ltmp[[TMP6:[0-9]+]]
89  adds x0, x0, #1
90  adds x0, x0, #1
91
92//
93// Check that symbols can be loaded using ldr pseudo
94//
95
96// load an undefined symbol
97.section g,"ax",@progbits
98// CHECK-LABEL: f9:
99f9:
100  ldr w0, =foo
101// CHECK: ldr w0, .Ltmp[[TMP7:[0-9]+]]
102
103// load a symbol from another section
104.section h,"ax",@progbits
105// CHECK-LABEL: f10:
106f10:
107  ldr w0, =f5
108// CHECK: ldr w0, .Ltmp[[TMP8:[0-9]+]]
109
110// load a symbol from the same section
111.section i,"ax",@progbits
112// CHECK-LABEL: f11:
113f11:
114  ldr w0, =f12
115// CHECK: ldr w0, .Ltmp[[TMP9:[0-9]+]]
116  ldr w0,=0x3C000
117// CHECK: ldr     w0, .Ltmp[[TMP10:[0-9]+]]
118
119// CHECK-LABEL: f12:
120f12:
121  adds x0, x0, #1
122  adds x0, x0, #1
123
124.section j,"ax",@progbits
125// mix of symbols and constants
126// CHECK-LABEL: f13:
127f13:
128  adds x0, x0, #1
129  adds x0, x0, #1
130  ldr w0, =0x101
131// CHECK: mov w0, #0x101
132  adds x0, x0, #1
133  adds x0, x0, #1
134  ldr w0, =bar
135// CHECK: ldr w0, .Ltmp[[TMP11:[0-9]+]]
136  adds x0, x0, #1
137  adds x0, x0, #1
138//
139// Check for correct usage in other contexts
140//
141
142// usage in macro
143.macro useit_in_a_macro
144  ldr w0, =0x10008
145  ldr w0, =baz
146.endm
147.section k,"ax",@progbits
148// CHECK-LABEL: f14:
149f14:
150  useit_in_a_macro
151// CHECK: ldr w0, .Ltmp[[TMP12:[0-9]+]]
152// CHECK: ldr w0, .Ltmp[[TMP13:[0-9]+]]
153
154// usage with expressions
155.section l, "ax", @progbits
156// CHECK-LABEL: f15:
157f15:
158  ldr w0, =0x10001+8
159// CHECK: ldr w0, .Ltmp[[TMP14:[0-9]+]]
160  adds x0, x0, #1
161  ldr w0, =bar+4
162// CHECK: ldr w0, .Ltmp[[TMP15:[0-9]+]]
163  adds x0, x0, #1
164
165// usage with 64-bit regs
166.section m, "ax", @progbits
167// CHECK-LABEL: f16:
168f16:
169  ldr x0, =0x0102030405060708
170// CHECK: ldr x0, .Ltmp[[TMP16:[0-9]+]]
171  add x0, x0, #1
172  ldr w0, =bar
173// CHECK: ldr w0, .Ltmp[[TMP17:[0-9]+]]
174  ldr x0, =bar+16
175// CHECK: ldr x0, .Ltmp[[TMP18:[0-9]+]]
176  add x0, x0, #1
177  ldr x0, =0x100000001
178// CHECK: ldr x0, .Ltmp[[TMP19:[0-9]+]]
179  ldr x1, =-0x80000001
180// CHECK: ldr x1, .Ltmp[[TMP20:[0-9]+]]
181  ldr x2, =0x10001
182// CHECK: ldr x2, .Ltmp[[TMP21:[0-9]+]]
183
184// check range for 32-bit regs
185.section n, "ax", @progbits
186// CHECK-LABEL: f17:
187f17:
188  ldr w0, =0xFFFFFFFF
189// CHECK: ldr w0, .Ltmp[[TMP22:[0-9]+]]
190  add w0, w0, #1
191  ldr w1, =-0x7FFFFFFF
192// CHECK: ldr w1, .Ltmp[[TMP23:[0-9]+]]
193  add w0, w0, #1
194  ldr w0, =-1
195// CHECK: ldr w0, .Ltmp[[TMP24:[0-9]+]]
196  add w0, w0, #1
197
198// make sure the same contant uses different pools for 32- and 64-bit registers
199.section o, "ax", @progbits
200// CHECK-LABEL: f18:
201f18:
202  ldr w0, =0x320064
203// CHECK: ldr w0, .Ltmp[[TMP25:[0-9]+]]
204  add w0, w0, #1
205  ldr x1, =0x320064
206// CHECK: ldr x1, .Ltmp[[TMP26:[0-9]+]]
207
208//
209// Constant Pools
210//
211// CHECK: .section b,"ax",@progbits
212// CHECK: .p2align 2
213// CHECK: .Ltmp[[TMP0]]
214// CHECK: .word 65537
215
216// CHECK: .section c,"ax",@progbits
217// CHECK: .p2align 2
218// CHECK: .Ltmp[[TMP1]]
219// CHECK: .word 65538
220// CHECK: .p2align 2
221// CHECK: .Ltmp[[TMP2]]
222// CHECK: .word 65539
223
224// CHECK: .section d,"ax",@progbits
225// CHECK: .p2align 2
226// CHECK: .Ltmp[[TMP3]]
227// CHECK: .word 65540
228// CHECK: .p2align 2
229// CHECK: .Ltmp[[TMP4]]
230// CHECK: .word 65540
231
232// CHECK: .section e,"ax",@progbits
233// CHECK: .p2align 2
234// CHECK: .Ltmp[[TMP5]]
235// CHECK: .word 65542
236// CHECK: .p2align 2
237// CHECK: .Ltmp[[TMP6]]
238// CHECK: .word 65543
239
240// Should not switch to section because it has no constant pool
241// CHECK-NOT: .section f,"ax",@progbits
242
243// CHECK: .section g,"ax",@progbits
244// CHECK: .p2align 2
245// CHECK: .Ltmp[[TMP7]]
246// CHECK: .word foo
247
248// CHECK: .section h,"ax",@progbits
249// CHECK: .p2align 2
250// CHECK: .Ltmp[[TMP8]]
251// CHECK: .word f5
252
253// CHECK: .section i,"ax",@progbits
254// CHECK: .p2align 2
255// CHECK: .Ltmp[[TMP9]]
256// CHECK: .word f12
257// CHECK: .p2align 2
258// CHECK: .Ltmp[[TMP10]]
259// CHECK: .word 245760
260
261// CHECK: .section j,"ax",@progbits
262// CHECK: .p2align 2
263// CHECK: .Ltmp[[TMP11]]
264// CHECK: .word bar
265
266// CHECK: .section k,"ax",@progbits
267// CHECK: .p2align 2
268// CHECK: .Ltmp[[TMP12]]
269// CHECK: .word 65544
270// CHECK: .p2align 2
271// CHECK: .Ltmp[[TMP13]]
272// CHECK: .word baz
273
274// CHECK: .section l,"ax",@progbits
275// CHECK: .p2align 2
276// CHECK: .Ltmp[[TMP14]]
277// CHECK: .word 65545
278// CHECK: .p2align 2
279// CHECK: .Ltmp[[TMP15]]
280// CHECK: .word bar+4
281
282// CHECK: .section m,"ax",@progbits
283// CHECK: .p2align 3
284// CHECK: .Ltmp[[TMP16]]
285// CHECK: .xword 72623859790382856
286// CHECK: .p2align 2
287// CHECK: .Ltmp[[TMP17]]
288// CHECK: .word bar
289// CHECK: .p2align 3
290// CHECK: .Ltmp[[TMP18]]
291// CHECK: .xword bar+16
292// CHECK: .p2align 3
293// CHECK: .Ltmp[[TMP19]]
294// CHECK: .xword 4294967297
295// CHECK: .p2align 3
296// CHECK: .Ltmp[[TMP20]]
297// CHECK: .xword -2147483649
298// CHECK: .p2align 3
299// CHECK: .Ltmp[[TMP21]]
300// CHECK: .xword 65537
301
302// CHECK: .section n,"ax",@progbits
303// CHECK: .p2align 2
304// CHECK: .Ltmp[[TMP22]]
305// CHECK: .word 4294967295
306// CHECK: .p2align 2
307// CHECK: .Ltmp[[TMP23]]
308// CHECK: .word -2147483647
309// CHECK: .p2align 2
310// CHECK: .Ltmp[[TMP24]]
311// CHECK: .word -1
312
313// CHECK: .section o,"ax",@progbits
314// CHECK: .p2align 2
315// CHECK: .Ltmp[[TMP25]]
316// CHECK: .word 3276900
317// CHECK: .p2align 3
318// CHECK: .Ltmp[[TMP26]]
319// CHECK: .xword 3276900
320