llvm-project
185 строк · 3.9 Кб
1# REQUIRES: aarch64
2
3# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t.o
4# RUN: %lld -arch arm64 %t.o -o %t
5# RUN: llvm-objdump --no-print-imm-hex -d --macho %t | FileCheck %s
6
7## This is mostly a copy of loh-adrp-ldr-got-ldr.s's `local.s` test, except that Adrp+Ldr+Ldr
8## triples have been changed to Adrp+Add+Ldr. The performed optimization is the same.
9.text
10.align 2
11.globl _main
12_main:
13
14### Transformation to a literal LDR
15## Basic case
16L1: adrp x0, _close@PAGE
17L2: add x1, x0, _close@PAGEOFF
18L3: ldr x2, [x1]
19# CHECK-LABEL: _main:
20# CHECK-NEXT: nop
21# CHECK-NEXT: nop
22# CHECK-NEXT: ldr x2
23
24## Load with offset
25L4: adrp x0, _close@PAGE
26L5: add x1, x0, _close@PAGEOFF
27L6: ldr x2, [x1, #8]
28# CHECK-NEXT: nop
29# CHECK-NEXT: nop
30# CHECK-NEXT: ldr x2
31
32## 32 bit load
33L7: adrp x0, _close@PAGE
34L8: add x1, x0, _close@PAGEOFF
35L9: ldr w1, [x1]
36# CHECK-NEXT: nop
37# CHECK-NEXT: nop
38# CHECK-NEXT: ldr w1, _close
39
40## Floating point
41L10: adrp x0, _close@PAGE
42L11: add x1, x0, _close@PAGEOFF
43L12: ldr s1, [x1]
44# CHECK-NEXT: nop
45# CHECK-NEXT: nop
46# CHECK-NEXT: ldr s1, _close
47
48L13: adrp x0, _close@PAGE
49L14: add x1, x0, _close@PAGEOFF
50L15: ldr d1, [x1, #8]
51# CHECK-NEXT: nop
52# CHECK-NEXT: nop
53# CHECK-NEXT: ldr d1, _close8
54
55L16: adrp x0, _close@PAGE
56L17: add x1, x0, _close@PAGEOFF
57L18: ldr q0, [x1]
58# CHECK-NEXT: nop
59# CHECK-NEXT: nop
60# CHECK-NEXT: ldr q0, _close
61
62
63### Transformation to ADR+LDR
64## 1 byte floating point load
65L19: adrp x0, _close@PAGE
66L20: add x1, x0, _close@PAGEOFF
67L21: ldr b2, [x1]
68# CHECK-NEXT: adr x1
69# CHECK-NEXT: nop
70# CHECK-NEXT: ldr b2, [x1]
71
72## 1 byte GPR load, zero extend
73L22: adrp x0, _close@PAGE
74L23: add x1, x0, _close@PAGEOFF
75L24: ldrb w2, [x1]
76# CHECK-NEXT: adr x1
77# CHECK-NEXT: nop
78# CHECK-NEXT: ldrb w2, [x1]
79
80## 1 byte GPR load, sign extend
81L25: adrp x0, _close@PAGE
82L26: add x1, x0, _close@PAGEOFF
83L27: ldrsb x2, [x1]
84# CHECK-NEXT: adr x1
85# CHECK-NEXT: nop
86# CHECK-NEXT: ldrsb x2, [x1]
87
88## Unaligned
89L28: adrp x0, _unaligned@PAGE
90L29: add x1, x0, _unaligned@PAGEOFF
91L30: ldr x2, [x1]
92# CHECK-NEXT: adr x1
93# CHECK-NEXT: nop
94# CHECK-NEXT: ldr x2, [x1]
95
96
97### Transformation to ADRP + immediate LDR
98## Basic test: target is far
99L31: adrp x0, _far@PAGE
100L32: add x1, x0, _far@PAGEOFF
101L33: ldr x2, [x1]
102# CHECK-NEXT: adrp x0
103# CHECK-NEXT: nop
104# CHECK-NEXT: ldr x2
105
106## With offset
107L34: adrp x0, _far@PAGE
108L35: add x1, x0, _far@PAGEOFF
109L36: ldr x2, [x1, #8]
110# CHECK-NEXT: adrp x0
111# CHECK-NEXT: nop
112# CHECK-NEXT: ldr x2
113
114### No changes
115## Far and unaligned
116L37: adrp x0, _far_unaligned@PAGE
117L38: add x1, x0, _far_unaligned@PAGEOFF
118L39: ldr x2, [x1]
119# CHECK-NEXT: adrp x0
120# CHECK-NEXT: add x1, x0
121# CHECK-NEXT: ldr x2, [x1]
122
123## Far with large offset (_far_offset@PAGE + #255 > 4095)
124L40: adrp x0, _far_offset@PAGE
125L41: add x1, x0, _far_offset@PAGEOFF
126L42: ldrb w2, [x1, #255]
127# CHECK-NEXT: adrp x0
128# CHECK-NEXT: add x1, x0
129# CHECK-NEXT: ldrb w2, [x1, #255]
130
131### Invalid inputs; the instructions should be left untouched.
132## Registers don't match
133L43: adrp x0, _far@PAGE
134L44: add x1, x0, _far@PAGEOFF
135L45: ldr x2, [x2]
136# CHECK-NEXT: adrp x0
137# CHECK-NEXT: add x1, x0
138# CHECK-NEXT: ldr x2, [x2]
139
140## Targets don't match
141L46: adrp x0, _close@PAGE
142L47: add x1, x0, _close8@PAGEOFF
143L48: ldr x2, [x1]
144# CHECK-NEXT: adrp x0
145# CHECK-NEXT: add x1, x0
146# CHECK-NEXT: ldr x2, [x1]
147
148.data
149.align 4
150.quad 0
151_close:
152.quad 0
153_close8:
154.quad 0
155.byte 0
156_unaligned:
157.quad 0
158
159.space 1048576
160.align 12
161.quad 0
162_far:
163.quad 0
164.byte 0
165_far_unaligned:
166.quad 0
167.space 4000
168_far_offset:
169.byte 0
170
171.loh AdrpAddLdr L1, L2, L3
172.loh AdrpAddLdr L4, L5, L6
173.loh AdrpAddLdr L7, L8, L9
174.loh AdrpAddLdr L10, L11, L12
175.loh AdrpAddLdr L13, L14, L15
176.loh AdrpAddLdr L16, L17, L18
177.loh AdrpAddLdr L19, L20, L21
178.loh AdrpAddLdr L22, L23, L24
179.loh AdrpAddLdr L25, L26, L27
180.loh AdrpAddLdr L28, L29, L30
181.loh AdrpAddLdr L31, L32, L33
182.loh AdrpAddLdr L34, L35, L36
183.loh AdrpAddLdr L37, L38, L39
184.loh AdrpAddLdr L40, L41, L42
185.loh AdrpAddLdr L43, L44, L45
186