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
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.
14 ### Transformation to a literal LDR
16 L1
: adrp x0
, _close@PAGE
17 L2
: add x1
, x0
, _close@PAGEOFF
25 L4
: adrp x0
, _close@PAGE
26 L5
: add x1
, x0
, _close@PAGEOFF
33 L7
: adrp x0
, _close@PAGE
34 L8
: add x1
, x0
, _close@PAGEOFF
38 # CHECK-NEXT: ldr w1, _close
41 L10
: adrp x0
, _close@PAGE
42 L11
: add x1
, x0
, _close@PAGEOFF
46 # CHECK-NEXT: ldr s1, _close
48 L13
: adrp x0
, _close@PAGE
49 L14
: add x1
, x0
, _close@PAGEOFF
53 # CHECK-NEXT: ldr d1, _close8
55 L16
: adrp x0
, _close@PAGE
56 L17
: add x1
, x0
, _close@PAGEOFF
60 # CHECK-NEXT: ldr q0, _close
63 ### Transformation to ADR+LDR
64 ## 1 byte floating point load
65 L19
: adrp x0
, _close@PAGE
66 L20
: add x1
, x0
, _close@PAGEOFF
70 # CHECK-NEXT: ldr b2, [x1]
72 ## 1 byte GPR load, zero extend
73 L22
: adrp x0
, _close@PAGE
74 L23
: add x1
, x0
, _close@PAGEOFF
78 # CHECK-NEXT: ldrb w2, [x1]
80 ## 1 byte GPR load, sign extend
81 L25
: adrp x0
, _close@PAGE
82 L26
: add x1
, x0
, _close@PAGEOFF
86 # CHECK-NEXT: ldrsb x2, [x1]
89 L28
: adrp x0
, _unaligned@PAGE
90 L29
: add x1
, x0
, _unaligned@PAGEOFF
94 # CHECK-NEXT: ldr x2, [x1]
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
102 # CHECK-NEXT: adrp x0
107 L34
: adrp x0
, _far@PAGE
108 L35
: add x1
, x0
, _far@PAGEOFF
109 L36
: ldr x2
, [x1
, #8]
110 # CHECK-NEXT: adrp x0
116 L37
: adrp x0
, _far_unaligned@PAGE
117 L38
: add x1
, x0
, _far_unaligned@PAGEOFF
119 # CHECK-NEXT: adrp x0
120 # CHECK-NEXT: add x1, x0
121 # CHECK-NEXT: ldr x2, [x1]
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]
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
136 # CHECK-NEXT: adrp x0
137 # CHECK-NEXT: add x1, x0
138 # CHECK-NEXT: ldr x2, [x2]
140 ## Targets don't match
141 L46
: adrp x0
, _close@PAGE
142 L47
: add x1
, x0
, _close8@PAGEOFF
144 # CHECK-NEXT: adrp x0
145 # CHECK-NEXT: add x1, x0
146 # CHECK-NEXT: ldr x2, [x1]
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