llvm-project

Форк
0
/
loh-adrp-add-ldr.s 
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
16
L1: adrp x0, _close@PAGE
17
L2: add  x1, x0, _close@PAGEOFF
18
L3: 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
25
L4: adrp x0, _close@PAGE
26
L5: add x1, x0, _close@PAGEOFF
27
L6: ldr  x2, [x1, #8]
28
# CHECK-NEXT: nop
29
# CHECK-NEXT: nop
30
# CHECK-NEXT: ldr x2
31

32
## 32 bit load
33
L7: adrp x0, _close@PAGE
34
L8: add  x1, x0, _close@PAGEOFF
35
L9: ldr  w1, [x1]
36
# CHECK-NEXT: nop
37
# CHECK-NEXT: nop
38
# CHECK-NEXT: ldr w1, _close
39

40
## Floating point
41
L10: adrp x0, _close@PAGE
42
L11: add  x1, x0, _close@PAGEOFF
43
L12: ldr  s1, [x1]
44
# CHECK-NEXT: nop
45
# CHECK-NEXT: nop
46
# CHECK-NEXT: ldr s1, _close
47

48
L13: adrp x0, _close@PAGE
49
L14: add  x1, x0, _close@PAGEOFF
50
L15: ldr  d1, [x1, #8]
51
# CHECK-NEXT: nop
52
# CHECK-NEXT: nop
53
# CHECK-NEXT: ldr d1, _close8
54

55
L16: adrp x0, _close@PAGE
56
L17: add  x1, x0, _close@PAGEOFF
57
L18: 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
65
L19: adrp x0, _close@PAGE
66
L20: add  x1, x0, _close@PAGEOFF
67
L21: 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
73
L22: adrp x0, _close@PAGE
74
L23: add  x1, x0, _close@PAGEOFF
75
L24: 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
81
L25: adrp  x0, _close@PAGE
82
L26: add   x1, x0, _close@PAGEOFF
83
L27: ldrsb x2, [x1]
84
# CHECK-NEXT: adr x1
85
# CHECK-NEXT: nop
86
# CHECK-NEXT: ldrsb x2, [x1]
87

88
## Unaligned
89
L28: adrp x0, _unaligned@PAGE
90
L29: add  x1, x0, _unaligned@PAGEOFF
91
L30: 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
99
L31: adrp x0, _far@PAGE
100
L32: add  x1, x0, _far@PAGEOFF
101
L33: ldr  x2, [x1]
102
# CHECK-NEXT: adrp x0
103
# CHECK-NEXT: nop
104
# CHECK-NEXT: ldr x2
105

106
## With offset
107
L34: adrp x0, _far@PAGE
108
L35: add  x1, x0, _far@PAGEOFF
109
L36: 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
116
L37: adrp x0, _far_unaligned@PAGE
117
L38: add  x1, x0, _far_unaligned@PAGEOFF
118
L39: 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)
124
L40: adrp x0, _far_offset@PAGE
125
L41: add  x1, x0, _far_offset@PAGEOFF
126
L42: 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
133
L43: adrp x0, _far@PAGE
134
L44: add  x1, x0, _far@PAGEOFF
135
L45: 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
141
L46: adrp x0, _close@PAGE
142
L47: add  x1, x0, _close8@PAGEOFF
143
L48: 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

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.