blob: 941310a592efda24ed504edf629a22f18115e3c3 [file] [log] [blame]
David Peixottoe407d092013-12-19 18:12:36 +00001@ This test has a partner (ldr-pseudo.s) that contains matching
2@ tests for the ldr-pseudo on linux targets. We need separate files
3@ because the syntax for switching sections and temporary labels differs
4@ between darwin and linux. Any tests added here should have a matching
5@ test added there.
6
Renato Golin608cb5d2016-05-12 21:22:42 +00007@RUN: llvm-mc -triple armv7-base-apple-darwin %s | FileCheck --check-prefix=CHECK-ARM --check-prefix=CHECK %s
8@RUN: llvm-mc -triple armv5-base-apple-darwin %s | FileCheck --check-prefix=CHECK-ARMV5 --check-prefix=CHECK %s
9@RUN: llvm-mc -triple thumbv5-base-apple-darwin %s | FileCheck --check-prefix=CHECK-THUMB --check-prefix=CHECK %s
10@RUN: llvm-mc -triple thumbv7-base-apple-darwin %s | FileCheck --check-prefix=CHECK-THUMB2 --check-prefix=CHECK %s
11@RUN: llvm-mc -triple thumbv8m.base-base-apple-darwin %s | FileCheck --check-prefix=CHECK-BASELINE --check-prefix=CHECK %s
David Peixottoe407d092013-12-19 18:12:36 +000012@
13@ Check that large constants are converted to ldr from constant pool
14@
15@ simple test
16.section __TEXT,b,regular,pure_instructions
17@ CHECK-LABEL: f3:
18f3:
Renato Golind5491ab2016-05-12 21:22:37 +000019 ldr r0, =0x10002
David Peixottoe407d092013-12-19 18:12:36 +000020@ CHECK: ldr r0, Ltmp0
21
22@ loading multiple constants
23.section __TEXT,c,regular,pure_instructions
24@ CHECK-LABEL: f4:
25f4:
Renato Golind5491ab2016-05-12 21:22:37 +000026 ldr r0, =0x10003
David Peixottoe407d092013-12-19 18:12:36 +000027@ CHECK: ldr r0, Ltmp1
28 adds r0, r0, #1
29 adds r0, r0, #1
30 adds r0, r0, #1
31 adds r0, r0, #1
Renato Golind5491ab2016-05-12 21:22:37 +000032 ldr r0, =0x10004
David Peixottoe407d092013-12-19 18:12:36 +000033@ CHECK: ldr r0, Ltmp2
34 adds r0, r0, #1
35 adds r0, r0, #1
36
37@ TODO: the same constants should have the same constant pool location
38.section __TEXT,d,regular,pure_instructions
39@ CHECK-LABEL: f5:
40f5:
Renato Golind5491ab2016-05-12 21:22:37 +000041 ldr r0, =0x10005
David Peixottoe407d092013-12-19 18:12:36 +000042@ CHECK: ldr r0, Ltmp3
43 adds r0, r0, #1
44 adds r0, r0, #1
45 adds r0, r0, #1
46 adds r0, r0, #1
47 adds r0, r0, #1
48 adds r0, r0, #1
49 adds r0, r0, #1
Renato Golind5491ab2016-05-12 21:22:37 +000050 ldr r0, =0x10005
James Molloy5193c802017-05-22 09:42:01 +000051@ CHECK: ldr r0, Ltmp3
David Peixottoe407d092013-12-19 18:12:36 +000052 adds r0, r0, #1
53 adds r0, r0, #1
54 adds r0, r0, #1
55 adds r0, r0, #1
56 adds r0, r0, #1
57 adds r0, r0, #1
58
59@ a section defined in multiple pieces should be merged and use a single constant pool
60.section __TEXT,e,regular,pure_instructions
61@ CHECK-LABEL: f6:
62f6:
63 ldr r0, =0x10006
James Molloy5193c802017-05-22 09:42:01 +000064@ CHECK: ldr r0, Ltmp4
David Peixottoe407d092013-12-19 18:12:36 +000065 adds r0, r0, #1
66 adds r0, r0, #1
67 adds r0, r0, #1
68
69.section __TEXT,f,regular,pure_instructions
70@ CHECK-LABEL: f7:
71f7:
72 adds r0, r0, #1
73 adds r0, r0, #1
74 adds r0, r0, #1
75
76.section __TEXT,e,regular,pure_instructions
77@ CHECK-LABEL: f8:
78f8:
79 adds r0, r0, #1
80 ldr r0, =0x10007
James Molloy5193c802017-05-22 09:42:01 +000081@ CHECK: ldr r0, Ltmp5
David Peixottoe407d092013-12-19 18:12:36 +000082 adds r0, r0, #1
83 adds r0, r0, #1
84
85@
86@ Check that symbols can be loaded using ldr pseudo
87@
88
89@ load an undefined symbol
90.section __TEXT,g,regular,pure_instructions
91@ CHECK-LABEL: f9:
92f9:
93 ldr r0, =foo
James Molloy5193c802017-05-22 09:42:01 +000094@ CHECK: ldr r0, Ltmp6
David Peixottoe407d092013-12-19 18:12:36 +000095
96@ load a symbol from another section
97.section __TEXT,h,regular,pure_instructions
98@ CHECK-LABEL: f10:
99f10:
100 ldr r0, =f5
James Molloy5193c802017-05-22 09:42:01 +0000101@ CHECK: ldr r0, Ltmp7
David Peixottoe407d092013-12-19 18:12:36 +0000102
103@ load a symbol from the same section
104.section __TEXT,i,regular,pure_instructions
105@ CHECK-LABEL: f11:
106f11:
107 ldr r0, =f12
James Molloy5193c802017-05-22 09:42:01 +0000108@ CHECK: ldr r0, Ltmp8
David Peixottoe407d092013-12-19 18:12:36 +0000109
110@ CHECK-LABEL: f12:
111f12:
112 adds r0, r0, #1
113 adds r0, r0, #1
114
115.section __TEXT,j,regular,pure_instructions
116@ mix of symbols and constants
117@ CHECK-LABEL: f13:
118f13:
119 adds r0, r0, #1
120 adds r0, r0, #1
Renato Golind5491ab2016-05-12 21:22:37 +0000121 ldr r0, =0x10008
James Molloy5193c802017-05-22 09:42:01 +0000122@ CHECK: ldr r0, Ltmp9
David Peixottoe407d092013-12-19 18:12:36 +0000123 adds r0, r0, #1
124 adds r0, r0, #1
125 ldr r0, =bar
James Molloy5193c802017-05-22 09:42:01 +0000126@ CHECK: ldr r0, Ltmp10
David Peixottoe407d092013-12-19 18:12:36 +0000127 adds r0, r0, #1
128 adds r0, r0, #1
129@
130@ Check for correct usage in other contexts
131@
132
133@ usage in macro
134.macro useit_in_a_macro
Renato Golind5491ab2016-05-12 21:22:37 +0000135 ldr r0, =0x10009
David Peixottoe407d092013-12-19 18:12:36 +0000136 ldr r0, =baz
137.endm
138.section __TEXT,k,regular,pure_instructions
139@ CHECK-LABEL: f14:
140f14:
141 useit_in_a_macro
James Molloy5193c802017-05-22 09:42:01 +0000142@ CHECK: ldr r0, Ltmp11
David Peixottoe407d092013-12-19 18:12:36 +0000143@ CHECK: ldr r0, Ltmp12
David Peixottoe407d092013-12-19 18:12:36 +0000144
145@ usage with expressions
146.section __TEXT,l,regular,pure_instructions
147@ CHECK-LABEL: f15:
148f15:
Renato Golind5491ab2016-05-12 21:22:37 +0000149 ldr r0, =0x10001+9
James Molloy5193c802017-05-22 09:42:01 +0000150@ CHECK: ldr r0, Ltmp13
David Peixottoe407d092013-12-19 18:12:36 +0000151 adds r0, r0, #1
152 ldr r0, =bar+4
James Molloy5193c802017-05-22 09:42:01 +0000153@ CHECK: ldr r0, Ltmp14
David Peixottoe407d092013-12-19 18:12:36 +0000154 adds r0, r0, #1
155
Renato Golin608cb5d2016-05-12 21:22:42 +0000156@ transformation to mov
157.section __TEXT,m,regular,pure_instructions
158@ CHECK-LABEL: f16:
159f16:
160
161@ Representable in ARM, and Thumb with support mov.w or movw
162 ldr r1, =0x1
163@ CHECK-ARM: mov r1, #1
164@ CHECK-ARMV5: mov r1, #1
James Molloy5193c802017-05-22 09:42:01 +0000165@ CHECK-THUMB: ldr r1, Ltmp15
Renato Golin608cb5d2016-05-12 21:22:42 +0000166@ CHECK-THUMB2: mov.w r1, #1
167@ CHECK-BASELINE: movw r1, #1
168
169@ Immediate is representable in A1 and T2 modified immediate only not movw
170 ldr r2, =0x120000
171@ CHECK-ARM: mov r2, #1179648
172@ CHECK-ARMV5: mov r2, #1179648
James Molloy5193c802017-05-22 09:42:01 +0000173@ CHECK-THUMB: ldr r2, Ltmp16
Renato Golin608cb5d2016-05-12 21:22:42 +0000174@ CHECK-THUMB2: mov.w r2, #1179648
James Molloy5193c802017-05-22 09:42:01 +0000175@ CHECK-BASELINE: ldr r2, Ltmp15
Renato Golin608cb5d2016-05-12 21:22:42 +0000176
177@ Immediate can be represented only with movw instruction
178 ldr r3, =0x1234
179@ CHECK-ARM: movw r3, #4660
James Molloy5193c802017-05-22 09:42:01 +0000180@ CHECK-ARMV5: ldr r3, Ltmp15
181@ CHECK-THUMB: ldr r3, Ltmp17
Renato Golin608cb5d2016-05-12 21:22:42 +0000182@ CHECK-THUMB2: movw r3, #4660
183@ CHECK-BASELINE: movw r3, #4660
184
185@ Immediate can be represented only with T2 modified immediate
186 ldr r4, =0xabababab
James Molloy5193c802017-05-22 09:42:01 +0000187@ CHECK-ARM: ldr r4, Ltmp15
188@ CHECK-ARMV5: ldr r4, Ltmp16
189@ CHECK-THUMB: ldr r4, Ltmp18
Renato Golin608cb5d2016-05-12 21:22:42 +0000190@ CHECK-THUMB2: mov.w r4, #2880154539
James Molloy5193c802017-05-22 09:42:01 +0000191@ CHECK-BASELINE: ldr r4, Ltmp16
Renato Golin608cb5d2016-05-12 21:22:42 +0000192
193@ Immediate can be represented only with A1 modified immediate
194 ldr r5, =0x1000000b
195@ CHECK-ARM: mov r5, #268435467
196@ CHECK-ARMV5: mov r5, #268435467
James Molloy5193c802017-05-22 09:42:01 +0000197@ CHECK-THUMB: ldr r5, Ltmp19
198@ CHECK-THUMB2: ldr r5, Ltmp15
199@ CHECK-BASELINE: ldr r5, Ltmp17
Renato Golin608cb5d2016-05-12 21:22:42 +0000200
201@ Negative numbers can be used with MVN or in Thumb2 with modified immediate
202 ldr r6, =-1
203@ CHECK-ARM: mvn r6, #0
204@ CHECK-ARMV5: mvn r6, #0
James Molloy5193c802017-05-22 09:42:01 +0000205@ CHECK-THUMB: ldr r6, Ltmp20
Renato Golin608cb5d2016-05-12 21:22:42 +0000206@ CHECK-THUMB2: mov.w r6, #-1
James Molloy5193c802017-05-22 09:42:01 +0000207@ CHECK-BASELINE: ldr r6, Ltmp18
Renato Golin608cb5d2016-05-12 21:22:42 +0000208 ldr r7, =-0x100
209@ CHECK-ARM: mvn r7, #255
210@ CHECK-ARMV5: mvn r7, #255
James Molloy5193c802017-05-22 09:42:01 +0000211@ CHECK-THUMB: ldr r7, Ltmp21
Renato Golin608cb5d2016-05-12 21:22:42 +0000212@ CHECK-THUMB2: mvn r7, #255
James Molloy5193c802017-05-22 09:42:01 +0000213@ CHECK-BASELINE: ldr r7, Ltmp19
Renato Golin608cb5d2016-05-12 21:22:42 +0000214
215@ Constant expressions can be used
216 .equ expr, 0x10 + 0x10
217 ldr r0, = expr
218@ CHECK-ARM: mov r0, #32
219@ CHECK-ARMV5: mov r0, #32
James Molloy5193c802017-05-22 09:42:01 +0000220@ CHECK-THUMB: ldr r0, Ltmp22
Renato Golin608cb5d2016-05-12 21:22:42 +0000221@ CHECK-THUMB2: mov.w r0, #32
222@ CHECK-BASELINE: movw r0, #32
223 ldr r1, = expr - 0x10
224@ CHECK-ARM: mov r1, #16
225@ CHECK-ARMV5: mov r1, #16
James Molloy5193c802017-05-22 09:42:01 +0000226@ CHECK-THUMB: ldr r1, Ltmp23
Renato Golin608cb5d2016-05-12 21:22:42 +0000227@ CHECK-THUMB2: mov.w r1, #16
228@ CHECK-BASELINE: movw r1, #16
229
230@ usage of translation in macro
231.macro usemov_in_a_macro
232 ldr r2, =0x3
233 ldr r3, =expr
234.endm
235@ CHECK-LABEL: f17:
236f17:
237 usemov_in_a_macro
238@ CHECK-ARM: mov r2, #3
239@ CHECK-ARM: mov r3, #32
240@ CHECK-ARMV5: mov r2, #3
241@ CHECK-ARMV5: mov r3, #32
James Molloy5193c802017-05-22 09:42:01 +0000242@ CHECK-THUMB: ldr r2, Ltmp24
243@ CHECK-THUMB: ldr r3, Ltmp22
Renato Golin608cb5d2016-05-12 21:22:42 +0000244@ CHECK-THUMB2: mov.w r2, #3
245@ CHECK-THUMB2: mov.w r3, #32
246@ CHECK-BASELINE: movw r2, #3
247@ CHECK-BASELINE: movw r3, #32
David Peixottoe407d092013-12-19 18:12:36 +0000248@
249@ Constant Pools
250@
251@ CHECK: .section __TEXT,b,regular,pure_instructions
David Peixottoe407d092013-12-19 18:12:36 +0000252@ CHECK: .data_region
Dan Gohman14d84362016-01-26 00:27:59 +0000253@ CHECK: .p2align 2
David Peixottoe407d092013-12-19 18:12:36 +0000254@ CHECK-LABEL: Ltmp0:
Renato Golind5491ab2016-05-12 21:22:37 +0000255@ CHECK: .long 65538
David Peixottoe407d092013-12-19 18:12:36 +0000256@ CHECK: .end_data_region
257
258@ CHECK: .section __TEXT,c,regular,pure_instructions
David Peixottoe407d092013-12-19 18:12:36 +0000259@ CHECK: .data_region
Dan Gohman14d84362016-01-26 00:27:59 +0000260@ CHECK: .p2align 2
David Peixottoe407d092013-12-19 18:12:36 +0000261@ CHECK-LABEL: Ltmp1:
Renato Golind5491ab2016-05-12 21:22:37 +0000262@ CHECK: .long 65539
Dan Gohman14d84362016-01-26 00:27:59 +0000263@ CHECK: .p2align 2
David Peixottoe407d092013-12-19 18:12:36 +0000264@ CHECK-LABEL: Ltmp2:
Renato Golind5491ab2016-05-12 21:22:37 +0000265@ CHECK: .long 65540
David Peixottoe407d092013-12-19 18:12:36 +0000266@ CHECK: .end_data_region
267
268@ CHECK: .section __TEXT,d,regular,pure_instructions
David Peixottoe407d092013-12-19 18:12:36 +0000269@ CHECK: .data_region
Dan Gohman14d84362016-01-26 00:27:59 +0000270@ CHECK: .p2align 2
David Peixottoe407d092013-12-19 18:12:36 +0000271@ CHECK-LABEL: Ltmp3:
Renato Golind5491ab2016-05-12 21:22:37 +0000272@ CHECK: .long 65541
David Peixottoe407d092013-12-19 18:12:36 +0000273@ CHECK: .end_data_region
274
275@ CHECK: .section __TEXT,e,regular,pure_instructions
David Peixottoe407d092013-12-19 18:12:36 +0000276@ CHECK: .data_region
Dan Gohman14d84362016-01-26 00:27:59 +0000277@ CHECK: .p2align 2
James Molloy5193c802017-05-22 09:42:01 +0000278@ CHECK-LABEL: Ltmp4:
David Peixottoe407d092013-12-19 18:12:36 +0000279@ CHECK: .long 65542
Dan Gohman14d84362016-01-26 00:27:59 +0000280@ CHECK: .p2align 2
James Molloy5193c802017-05-22 09:42:01 +0000281@ CHECK-LABEL: Ltmp5:
David Peixottoe407d092013-12-19 18:12:36 +0000282@ CHECK: .long 65543
283@ CHECK: .end_data_region
284
285@ Should not switch to section because it has no constant pool
286@ CHECK-NOT: .section __TEXT,f,regular,pure_instructions
287
288@ CHECK: .section __TEXT,g,regular,pure_instructions
David Peixottoe407d092013-12-19 18:12:36 +0000289@ CHECK: .data_region
Dan Gohman14d84362016-01-26 00:27:59 +0000290@ CHECK: .p2align 2
James Molloy5193c802017-05-22 09:42:01 +0000291@ CHECK-LABEL: Ltmp6:
David Peixottoe407d092013-12-19 18:12:36 +0000292@ CHECK: .long foo
293@ CHECK: .end_data_region
294
295@ CHECK: .section __TEXT,h,regular,pure_instructions
David Peixottoe407d092013-12-19 18:12:36 +0000296@ CHECK: .data_region
Dan Gohman14d84362016-01-26 00:27:59 +0000297@ CHECK: .p2align 2
James Molloy5193c802017-05-22 09:42:01 +0000298@ CHECK-LABEL: Ltmp7:
David Peixottoe407d092013-12-19 18:12:36 +0000299@ CHECK: .long f5
300@ CHECK: .end_data_region
301
302@ CHECK: .section __TEXT,i,regular,pure_instructions
David Peixottoe407d092013-12-19 18:12:36 +0000303@ CHECK: .data_region
Dan Gohman14d84362016-01-26 00:27:59 +0000304@ CHECK: .p2align 2
James Molloy5193c802017-05-22 09:42:01 +0000305@ CHECK-LABEL: Ltmp8:
David Peixottoe407d092013-12-19 18:12:36 +0000306@ CHECK: .long f12
307@ CHECK: .end_data_region
308
309@ CHECK: .section __TEXT,j,regular,pure_instructions
David Peixottoe407d092013-12-19 18:12:36 +0000310@ CHECK: .data_region
Dan Gohman14d84362016-01-26 00:27:59 +0000311@ CHECK: .p2align 2
James Molloy5193c802017-05-22 09:42:01 +0000312@ CHECK-LABEL: Ltmp9:
Renato Golind5491ab2016-05-12 21:22:37 +0000313@ CHECK: .long 65544
Dan Gohman14d84362016-01-26 00:27:59 +0000314@ CHECK: .p2align 2
James Molloy5193c802017-05-22 09:42:01 +0000315@ CHECK-LABEL: Ltmp10:
David Peixottoe407d092013-12-19 18:12:36 +0000316@ CHECK: .long bar
317@ CHECK: .end_data_region
318
319@ CHECK: .section __TEXT,k,regular,pure_instructions
David Peixottoe407d092013-12-19 18:12:36 +0000320@ CHECK: .data_region
Dan Gohman14d84362016-01-26 00:27:59 +0000321@ CHECK: .p2align 2
James Molloy5193c802017-05-22 09:42:01 +0000322@ CHECK-LABEL: Ltmp11:
Renato Golind5491ab2016-05-12 21:22:37 +0000323@ CHECK: .long 65545
Dan Gohman14d84362016-01-26 00:27:59 +0000324@ CHECK: .p2align 2
James Molloy5193c802017-05-22 09:42:01 +0000325@ CHECK-LABEL: Ltmp12:
David Peixottoe407d092013-12-19 18:12:36 +0000326@ CHECK: .long baz
327@ CHECK: .end_data_region
328
329@ CHECK: .section __TEXT,l,regular,pure_instructions
David Peixottoe407d092013-12-19 18:12:36 +0000330@ CHECK: .data_region
Dan Gohman14d84362016-01-26 00:27:59 +0000331@ CHECK: .p2align 2
James Molloy5193c802017-05-22 09:42:01 +0000332@ CHECK-LABEL: Ltmp13:
Renato Golind5491ab2016-05-12 21:22:37 +0000333@ CHECK: .long 65546
Dan Gohman14d84362016-01-26 00:27:59 +0000334@ CHECK: .p2align 2
James Molloy5193c802017-05-22 09:42:01 +0000335@ CHECK-LABEL: Ltmp14:
David Peixottoe407d092013-12-19 18:12:36 +0000336@ CHECK: .long bar+4
337@ CHECK: .end_data_region