1# REQUIRES: ppc
2# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t1.o
3# RUN: llvm-mc -filetype=obj -triple=powerpc64le %p/Inputs/ppc64-got-to-pcrel-relaxation-def.s -o %t2.o
4# RUN: ld.lld --shared %t2.o -o %t2.so --soname=t2
5# RUN: ld.lld %t1.o %t2.o -o %t
6# RUN: ld.lld %t1.o %t2.so -o %ts
7# RUN: ld.lld %t1.o %t2.o -o %tn --no-pcrel-optimize
8# RUN: llvm-objdump -d --no-show-raw-insn --mcpu=pwr10 %t | FileCheck %s --check-prefix=CHECK-S
9# RUN: llvm-objdump -d --no-show-raw-insn --mcpu=pwr10 %ts | FileCheck %s --check-prefix=CHECK-D
10# RUN: llvm-objdump -d --no-show-raw-insn --mcpu=pwr10 %tn | FileCheck %s --check-prefix=CHECK-D
11
12# RUN: llvm-mc -filetype=obj -triple=powerpc64 %s -o %t1.o
13# RUN: llvm-mc -filetype=obj -triple=powerpc64 %p/Inputs/ppc64-got-to-pcrel-relaxation-def.s -o %t2.o
14# RUN: ld.lld --shared %t2.o -o %t2.so --soname=t2
15# RUN: ld.lld %t1.o %t2.o -o %t
16# RUN: ld.lld %t1.o %t2.so -o %ts
17# RUN: ld.lld %t1.o %t2.o -o %tn --no-pcrel-optimize
18# RUN: llvm-objdump -d --no-show-raw-insn --mcpu=pwr10 %t | FileCheck %s --check-prefix=CHECK-S
19# RUN: llvm-objdump -d --no-show-raw-insn --mcpu=pwr10 %ts | FileCheck %s --check-prefix=CHECK-D
20# RUN: llvm-objdump -d --no-show-raw-insn --mcpu=pwr10 %tn | FileCheck %s --check-prefix=CHECK-D
21
22# CHECK-S-LABEL: <check_LBZ_STB>:
23# CHECK-S-NEXT:    plbz 10
24# CHECK-S-NEXT:    paddi 9
25# CHECK-S-NEXT:    li 3, 0
26# CHECK-S-NEXT:    nop
27# CHECK-S-NEXT:    rldicl 9, 9, 9, 60
28# CHECK-S-NEXT:    add 9, 9, 10
29# CHECK-S-NEXT:    pstb 9
30# CHECK-S-NEXT:    nop
31# CHECK-S-NEXT:    blr
32
33# CHECK-D-LABEL: <check_LBZ_STB>:
34# CHECK-D-NEXT:    pld 8
35# CHECK-D-NEXT:    pld 9
36# CHECK-D-NEXT:    li 3, 0
37# CHECK-D-NEXT:    lbz 10, 0(8)
38# CHECK-D-NEXT:    rldicl 9, 9, 9, 60
39# CHECK-D-NEXT:    add 9, 9, 10
40# CHECK-D-NEXT:    pld 10
41# CHECK-D-NEXT:    stb 9, 0(10)
42# CHECK-D-NEXT:    blr
43check_LBZ_STB:
44  pld 8,useVal@got@pcrel(0),1
45.Lpcrel1:
46  pld 9,useAddr@got@pcrel(0),1
47  li 3,0
48  .reloc .Lpcrel1-8,R_PPC64_PCREL_OPT,.-(.Lpcrel1-8)
49  lbz 10,0(8)
50  rldicl 9,9,9,60
51  add 9,9,10
52  pld 10,storeVal@got@pcrel(0),1
53.Lpcrel2:
54  .reloc .Lpcrel2-8,R_PPC64_PCREL_OPT,.-(.Lpcrel2-8)
55  stb 9,0(10)
56  blr
57
58# CHECK-S-LABEL: <check_LHZ_STH>:
59# CHECK-S-NEXT:    plhz 3
60# CHECK-S-NEXT:    nop
61# CHECK-S-NEXT:    nop
62# CHECK-S-NEXT:    psth 3
63# CHECK-S-NEXT:    nop
64# CHECK-S-NEXT:    blr
65
66# CHECK-D-LABEL: <check_LHZ_STH>:
67# CHECK-D-NEXT:    pld 9
68# CHECK-D-NEXT:    lhz 3, 0(9)
69# CHECK-D-NEXT:    nop
70# CHECK-D-NEXT:    pld 9
71# CHECK-D-NEXT:    sth 3, 0(9)
72# CHECK-D-NEXT:    blr
73check_LHZ_STH:
74  pld 9,useVal_ushort@got@pcrel(0),1
75.Lpcrel3:
76  .reloc .Lpcrel3-8,R_PPC64_PCREL_OPT,.-(.Lpcrel3-8)
77  lhz 3,0(9)
78  pld 9,storeVal_ushort@got@pcrel(0),1
79.Lpcrel4:
80  .reloc .Lpcrel4-8,R_PPC64_PCREL_OPT,.-(.Lpcrel4-8)
81  sth 3,0(9)
82  blr
83
84# CHECK-S-LABEL: <check_LWZ_STW>:
85# CHECK-S-NEXT:    plwz 3
86# CHECK-S-NEXT:    nop
87# CHECK-S-NEXT:    pstw 3
88# CHECK-S-NEXT:    nop
89# CHECK-S-NEXT:    blr
90
91# CHECK-D-LABEL: <check_LWZ_STW>:
92# CHECK-D-NEXT:    pld 9
93# CHECK-D-NEXT:    lwz 3, 0(9)
94# CHECK-D-NEXT:    pld 9
95# CHECK-D-NEXT:    stw 3, 0(9)
96# CHECK-D-NEXT:    blr
97check_LWZ_STW:
98  pld 9,useVal_uint@got@pcrel(0),1
99.Lpcrel5:
100  .reloc .Lpcrel5-8,R_PPC64_PCREL_OPT,.-(.Lpcrel5-8)
101  lwz 3,0(9)
102  pld 9,storeVal_uint@got@pcrel(0),1
103.Lpcrel6:
104  .reloc .Lpcrel6-8,R_PPC64_PCREL_OPT,.-(.Lpcrel6-8)
105  stw 3,0(9)
106  blr
107
108# CHECK-S-LABEL: <check_LFS_STFS>:
109# CHECK-S-NEXT:    plfs 1
110# CHECK-S-NEXT:    nop
111# CHECK-S-NEXT:    pstfs 1
112# CHECK-S-NEXT:    nop
113# CHECK-S-NEXT:    blr
114
115# CHECK-D-LABEL: <check_LFS_STFS>:
116# CHECK-D-NEXT:    pld 9
117# CHECK-D-NEXT:    lfs 1, 0(9)
118# CHECK-D-NEXT:    pld 9
119# CHECK-D-NEXT:    stfs 1, 0(9)
120# CHECK-D-NEXT:    blr
121check_LFS_STFS:
122  pld 9,useVal_float@got@pcrel(0),1
123.Lpcrel7:
124  .reloc .Lpcrel7-8,R_PPC64_PCREL_OPT,.-(.Lpcrel7-8)
125  lfs 1,0(9)
126  pld 9,storeVal_float@got@pcrel(0),1
127.Lpcrel8:
128  .reloc .Lpcrel8-8,R_PPC64_PCREL_OPT,.-(.Lpcrel8-8)
129  stfs 1,0(9)
130  blr
131
132# CHECK-S-LABEL: <check_LFD_STFD>:
133# CHECK-S-NEXT:    plfd 1
134# CHECK-S-NEXT:    nop
135# CHECK-S-NEXT:    pstfd 1
136# CHECK-S-NEXT:    nop
137# CHECK-S-NEXT:    blr
138
139# CHECK-D-LABEL: <check_LFD_STFD>:
140# CHECK-D-NEXT:    pld 9
141# CHECK-D-NEXT:    lfd 1, 0(9)
142# CHECK-D-NEXT:    pld 9
143# CHECK-D-NEXT:    stfd 1, 0(9)
144# CHECK-D-NEXT:    blr
145check_LFD_STFD:
146  pld 9,useVal_double@got@pcrel(0),1
147.Lpcrel9:
148  .reloc .Lpcrel9-8,R_PPC64_PCREL_OPT,.-(.Lpcrel9-8)
149  lfd 1,0(9)
150  pld 9,storeVal_double@got@pcrel(0),1
151.Lpcrel10:
152  .reloc .Lpcrel10-8,R_PPC64_PCREL_OPT,.-(.Lpcrel10-8)
153  stfd 1,0(9)
154  blr
155
156# CHECK-S-LABEL: <check_LWA_STW>:
157# CHECK-S-NEXT:    mr 9, 3
158# CHECK-S-NEXT:    plwa 3
159# CHECK-S-NEXT:    pstw 9
160# CHECK-S-NEXT:    nop
161# CHECK-S-NEXT:    nop
162# CHECK-S-NEXT:    blr
163
164# CHECK-D-LABEL: <check_LWA_STW>:
165# CHECK-D-NEXT:    mr 9, 3
166# CHECK-D-NEXT:    pld 8
167# CHECK-D-NEXT:    pld 10
168# CHECK-D-NEXT:    lwa 3, 0(8)
169# CHECK-D-NEXT:    stw 9, 0(10)
170# CHECK-D-NEXT:    blr
171check_LWA_STW:
172  mr 9,3
173  pld 8,useVal_sint@got@pcrel(0),1
174.Lpcrel11:
175  pld 10,storeVal_sint@got@pcrel(0),1
176.Lpcrel12:
177  .reloc .Lpcrel11-8,R_PPC64_PCREL_OPT,.-(.Lpcrel11-8)
178  lwa 3,0(8)
179  .reloc .Lpcrel12-8,R_PPC64_PCREL_OPT,.-(.Lpcrel12-8)
180  stw 9,0(10)
181  blr
182
183# CHECK-S-LABEL: <check_LHA_STH>:
184# CHECK-S-NEXT:    mr 9, 3
185# CHECK-S-NEXT:    plha 3
186# CHECK-S-NEXT:    psth 9
187# CHECK-S-NEXT:    nop
188# CHECK-S-NEXT:    nop
189# CHECK-S-NEXT:    blr
190
191# CHECK-D-LABEL: <check_LHA_STH>:
192# CHECK-D-NEXT:    mr 9, 3
193# CHECK-D-NEXT:    pld 8
194# CHECK-D-NEXT:    pld 10
195# CHECK-D-NEXT:    lha 3, 0(8)
196# CHECK-D-NEXT:    sth 9, 0(10)
197# CHECK-D-NEXT:    blr
198check_LHA_STH:
199  mr 9,3
200  pld 8,useVal_sshort@got@pcrel(0),1
201.Lpcrel13:
202  pld 10,storeVal_sshort@got@pcrel(0),1
203.Lpcrel14:
204  .reloc .Lpcrel13-8,R_PPC64_PCREL_OPT,.-(.Lpcrel13-8)
205  lha 3,0(8)
206  .reloc .Lpcrel14-8,R_PPC64_PCREL_OPT,.-(.Lpcrel14-8)
207  sth 9,0(10)
208  blr
209
210# CHECK-S-LABEL: <check_LD_STD>:
211# CHECK-S-NEXT:    pld 3
212# CHECK-S-NEXT:    nop
213# CHECK-S-NEXT:    pstd 3
214# CHECK-S-NEXT:    nop
215# CHECK-S-NEXT:    blr
216
217# CHECK-D-LABEL: <check_LD_STD>:
218# CHECK-D-NEXT:    pld 9
219# CHECK-D-NEXT:    ld 3, 0(9)
220# CHECK-D-NEXT:    pld 9
221# CHECK-D-NEXT:    std 3, 0(9)
222# CHECK-D-NEXT:    blr
223check_LD_STD:
224  pld 9,useVal_longlong@got@pcrel(0),1
225.Lpcrel15:
226  .reloc .Lpcrel15-8,R_PPC64_PCREL_OPT,.-(.Lpcrel15-8)
227  ld 3,0(9)
228  pld 9,storeVal_longlong@got@pcrel(0),1
229.Lpcrel16:
230  .reloc .Lpcrel16-8,R_PPC64_PCREL_OPT,.-(.Lpcrel16-8)
231  std 3,0(9)
232  blr
233
234# CHECK-S-LABEL: <check_LXV_STXV>:
235# CHECK-S-NEXT:    plxv 34
236# CHECK-S-NEXT:    nop
237# CHECK-S-NEXT:    pstxv 34
238# CHECK-S-NEXT:    nop
239# CHECK-S-NEXT:    blr
240
241# CHECK-D-LABEL: <check_LXV_STXV>:
242# CHECK-D-NEXT:    pld 9
243# CHECK-D-NEXT:    lxv 34, 0(9)
244# CHECK-D-NEXT:    pld 9
245# CHECK-D-NEXT:    stxv 34, 0(9)
246# CHECK-D-NEXT:    blr
247check_LXV_STXV:
248  pld 9,useVal_vector@got@pcrel(0),1
249.Lpcrel17:
250  .reloc .Lpcrel17-8,R_PPC64_PCREL_OPT,.-(.Lpcrel17-8)
251  lxv 34,0(9)
252  pld 9,storeVal_vector@got@pcrel(0),1
253.Lpcrel18:
254  .reloc .Lpcrel18-8,R_PPC64_PCREL_OPT,.-(.Lpcrel18-8)
255  stxv 34,0(9)
256  blr
257
258# CHECK-S-LABEL: <check_LXSSP_STXSSP>:
259# CHECK-S-NEXT:    plxssp 1
260# CHECK-S-NEXT:    nop
261# CHECK-S-NEXT:    pstxssp 1
262# CHECK-S-NEXT:    nop
263# CHECK-S-NEXT:    blr
264
265# CHECK-D-LABEL: <check_LXSSP_STXSSP>:
266# CHECK-D-NEXT:    pld 9
267# CHECK-D-NEXT:    lxssp 1, 0(9)
268# CHECK-D-NEXT:    pld 9
269# CHECK-D-NEXT:    stxssp 1, 0(9)
270# CHECK-D-NEXT:    blr
271check_LXSSP_STXSSP:
272  pld 9,useVal_float@got@pcrel(0),1
273.Lpcrel19:
274  .reloc .Lpcrel19-8,R_PPC64_PCREL_OPT,.-(.Lpcrel19-8)
275  lxssp 1,0(9)
276  pld 9,storeVal_float@got@pcrel(0),1
277.Lpcrel20:
278  .reloc .Lpcrel20-8,R_PPC64_PCREL_OPT,.-(.Lpcrel20-8)
279  stxssp 1,0(9)
280  blr
281
282# CHECK-S-LABEL: <check_LXSD_STXSD>:
283# CHECK-S-NEXT:    plxsd 1, [[#ADDR1:]]
284# CHECK-S-NEXT:    nop
285# CHECK-S-NEXT:    pstxsd 1, [[#ADDR2:]]
286# CHECK-S-NEXT:    nop
287# CHECK-S-NEXT:    blr
288
289# CHECK-D-LABEL: <check_LXSD_STXSD>:
290# CHECK-D-NEXT:    pld 9
291# CHECK-D-NEXT:    lxsd 1, 0(9)
292# CHECK-D-NEXT:    pld 9
293# CHECK-D-NEXT:    stxsd 1, 0(9)
294# CHECK-D-NEXT:    blr
295check_LXSD_STXSD:
296  pld 9,useVal_double@got@pcrel(0),1
297.Lpcrel21:
298  .reloc .Lpcrel21-8,R_PPC64_PCREL_OPT,.-(.Lpcrel21-8)
299  lxsd 1,0(9)
300  pld 9,storeVal_double@got@pcrel(0),1
301.Lpcrel22:
302  .reloc .Lpcrel22-8,R_PPC64_PCREL_OPT,.-(.Lpcrel22-8)
303  stxsd 1,0(9)
304  blr
305
306# The respective displacements are computed relative to the PC which advanced
307# by 28 bytes in this function. Since the displacements in the two access
308# instructions are 8 and 32 so the displacements are those computed above minus
309# 20 and plus 4 (+8 - 28 and +32 - 28) respectively.
310# CHECK-S-LABEL: <check_LXSD_STXSD_aggr>:
311# CHECK-S-NEXT:    plxsd 1, [[#ADDR1-20]]
312# CHECK-S-NEXT:    nop
313# CHECK-S-NEXT:    pstxsd 1, [[#ADDR2+4]]
314# CHECK-S-NEXT:    nop
315# CHECK-S-NEXT:    blr
316
317# CHECK-D-LABEL: <check_LXSD_STXSD_aggr>:
318# CHECK-D-NEXT:    pld 9
319# CHECK-D-NEXT:    lxsd 1, 8(9)
320# CHECK-D-NEXT:    pld 9
321# CHECK-D-NEXT:    stxsd 1, 32(9)
322# CHECK-D-NEXT:    blr
323check_LXSD_STXSD_aggr:
324  pld 9,useVal_double@got@pcrel(0),1
325.Lpcrel23:
326  .reloc .Lpcrel23-8,R_PPC64_PCREL_OPT,.-(.Lpcrel23-8)
327  lxsd 1,8(9)
328  pld 9,storeVal_double@got@pcrel(0),1
329.Lpcrel24:
330  .reloc .Lpcrel24-8,R_PPC64_PCREL_OPT,.-(.Lpcrel24-8)
331  stxsd 1,32(9)
332  blr
333
334# This includes a nop but that is not emitted by the linker.
335# It is an alignment nop to prevent the prefixed instruction from
336# crossing a 64-byte boundary.
337# CHECK-S-LABEL: <check_LD_STD_W_PADDI>:
338# CHECK-S-NEXT:    paddi 9
339# CHECK-S-NEXT:    ld 3, 0(9)
340# CHECK-S-NEXT:    nop
341# CHECK-S-NEXT:    paddi 9
342# CHECK-S-NEXT:    std 3, 0(9)
343# CHECK-S-NEXT:    blr
344
345# CHECK-D-LABEL: <check_LD_STD_W_PADDI>:
346# CHECK-D-NEXT:    paddi 9
347# CHECK-D-NEXT:    ld 3, 0(9)
348# CHECK-D-NEXT:    nop
349# CHECK-D-NEXT:    paddi 9
350# CHECK-D-NEXT:    std 3, 0(9)
351# CHECK-D-NEXT:    blr
352check_LD_STD_W_PADDI:
353  paddi 9,0,useVal_longlong@got@pcrel,1
354.Lpcrel25:
355  .reloc .Lpcrel25-8,R_PPC64_PCREL_OPT,.-(.Lpcrel25-8)
356  ld 3,0(9)
357  paddi 9,0,storeVal_longlong@got@pcrel,1
358.Lpcrel26:
359  .reloc .Lpcrel26-8,R_PPC64_PCREL_OPT,.-(.Lpcrel26-8)
360  std 3,0(9)
361  blr
362# CHECK-S-LABEL: <check_LXSD_STXSD_aggr_notoc>:
363# CHECK-S-NEXT:    paddi 3, 0, -12, 1
364# CHECK-S-NEXT:    lwz 4, 8(3)
365# CHECK-S-NEXT:    paddi 3, 0, -24, 1
366# CHECK-S-NEXT:    stw 4, 32(3)
367# CHECK-S-NEXT:    blr
368
369# CHECK-D-LABEL: <check_LXSD_STXSD_aggr_notoc>:
370# CHECK-D-NEXT:    paddi 3, 0, -12, 1
371# CHECK-D-NEXT:    lwz 4, 8(3)
372# CHECK-D-NEXT:    paddi 3, 0, -24, 1
373# CHECK-D-NEXT:    stw 4, 32(3)
374# CHECK-D-NEXT:    blr
375.type	Arr,@object                     # @Arr
376.globl	Arr
377.p2align	2
378Arr:
379.long	11                              # 0xb
380.long	22                              # 0x16
381.long	33                              # 0x21
382check_LXSD_STXSD_aggr_notoc:
383  paddi 3, 0, Arr@PCREL, 1
384.Lpcrel27:
385  .reloc .Lpcrel27-8,R_PPC64_PCREL_OPT,.-(.Lpcrel27-8)
386  lwz 4,8(3)
387  paddi 3, 0, Arr@PCREL, 1
388.Lpcrel28:
389  .reloc .Lpcrel28-8,R_PPC64_PCREL_OPT,.-(.Lpcrel28-8)
390  stw 4,32(3)
391  blr
392
393