1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
3; RUN:   -mcpu=pwr10 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s \
4; RUN:   | FileCheck %s --check-prefix=LE
5; RUN: llc -verify-machineinstrs -target-abi=elfv2 -mtriple=powerpc64-- \
6; RUN:   -mcpu=pwr10 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s \
7; RUN:   | FileCheck %s --check-prefix=BE
8
9
10%struct.Struct = type { i8, i16, i32 }
11
12@valChar = external local_unnamed_addr global i8, align 1
13@valShort = external local_unnamed_addr global i16, align 2
14@valInt = external global i32, align 4
15@valUnsigned = external local_unnamed_addr global i32, align 4
16@valLong = external local_unnamed_addr global i64, align 8
17@ptr = external local_unnamed_addr global i32*, align 8
18@array = external local_unnamed_addr global [10 x i32], align 4
19@structure = external local_unnamed_addr global %struct.Struct, align 4
20@ptrfunc = external local_unnamed_addr global void (...)*, align 8
21
22define dso_local signext i32 @ReadGlobalVarChar() local_unnamed_addr  {
23; LE-LABEL: ReadGlobalVarChar:
24; LE:       # %bb.0: # %entry
25; LE-NEXT:    pld r3, valChar@got@pcrel(0), 1
26; LE-NEXT:  .Lpcrel0:
27; LE-NEXT:    .reloc .Lpcrel0-8,R_PPC64_PCREL_OPT,.-(.Lpcrel0-8)
28; LE-NEXT:    lbz r3, 0(r3)
29; LE-NEXT:    blr
30;
31; BE-LABEL: ReadGlobalVarChar:
32; BE:       # %bb.0: # %entry
33; BE-NEXT:    pld r3, valChar@got@pcrel(0), 1
34; BE-NEXT:  .Lpcrel0:
35; BE-NEXT:    .reloc .Lpcrel0-8,R_PPC64_PCREL_OPT,.-(.Lpcrel0-8)
36; BE-NEXT:    lbz r3, 0(r3)
37; BE-NEXT:    blr
38entry:
39  %0 = load i8, i8* @valChar, align 1
40  %conv = zext i8 %0 to i32
41  ret i32 %conv
42}
43
44define dso_local void @WriteGlobalVarChar() local_unnamed_addr  {
45; LE-LABEL: WriteGlobalVarChar:
46; LE:       # %bb.0: # %entry
47; LE-NEXT:    pld r3, valChar@got@pcrel(0), 1
48; LE-NEXT:    li r4, 3
49; LE-NEXT:    stb r4, 0(r3)
50; LE-NEXT:    blr
51;
52; BE-LABEL: WriteGlobalVarChar:
53; BE:       # %bb.0: # %entry
54; BE-NEXT:    pld r3, valChar@got@pcrel(0), 1
55; BE-NEXT:    li r4, 3
56; BE-NEXT:    stb r4, 0(r3)
57; BE-NEXT:    blr
58entry:
59  store i8 3, i8* @valChar, align 1
60  ret void
61}
62
63define dso_local signext i32 @ReadGlobalVarShort() local_unnamed_addr  {
64; LE-LABEL: ReadGlobalVarShort:
65; LE:       # %bb.0: # %entry
66; LE-NEXT:    pld r3, valShort@got@pcrel(0), 1
67; LE-NEXT:  .Lpcrel1:
68; LE-NEXT:    .reloc .Lpcrel1-8,R_PPC64_PCREL_OPT,.-(.Lpcrel1-8)
69; LE-NEXT:    lha r3, 0(r3)
70; LE-NEXT:    blr
71;
72; BE-LABEL: ReadGlobalVarShort:
73; BE:       # %bb.0: # %entry
74; BE-NEXT:    pld r3, valShort@got@pcrel(0), 1
75; BE-NEXT:  .Lpcrel1:
76; BE-NEXT:    .reloc .Lpcrel1-8,R_PPC64_PCREL_OPT,.-(.Lpcrel1-8)
77; BE-NEXT:    lha r3, 0(r3)
78; BE-NEXT:    blr
79entry:
80  %0 = load i16, i16* @valShort, align 2
81  %conv = sext i16 %0 to i32
82  ret i32 %conv
83}
84
85define dso_local void @WriteGlobalVarShort() local_unnamed_addr  {
86; LE-LABEL: WriteGlobalVarShort:
87; LE:       # %bb.0: # %entry
88; LE-NEXT:    pld r3, valShort@got@pcrel(0), 1
89; LE-NEXT:    li r4, 3
90; LE-NEXT:    sth r4, 0(r3)
91; LE-NEXT:    blr
92;
93; BE-LABEL: WriteGlobalVarShort:
94; BE:       # %bb.0: # %entry
95; BE-NEXT:    pld r3, valShort@got@pcrel(0), 1
96; BE-NEXT:    li r4, 3
97; BE-NEXT:    sth r4, 0(r3)
98; BE-NEXT:    blr
99entry:
100  store i16 3, i16* @valShort, align 2
101  ret void
102}
103
104define dso_local signext i32 @ReadGlobalVarInt() local_unnamed_addr  {
105; LE-LABEL: ReadGlobalVarInt:
106; LE:       # %bb.0: # %entry
107; LE-NEXT:    pld r3, valInt@got@pcrel(0), 1
108; LE-NEXT:  .Lpcrel2:
109; LE-NEXT:    .reloc .Lpcrel2-8,R_PPC64_PCREL_OPT,.-(.Lpcrel2-8)
110; LE-NEXT:    lwa r3, 0(r3)
111; LE-NEXT:    blr
112;
113; BE-LABEL: ReadGlobalVarInt:
114; BE:       # %bb.0: # %entry
115; BE-NEXT:    pld r3, valInt@got@pcrel(0), 1
116; BE-NEXT:  .Lpcrel2:
117; BE-NEXT:    .reloc .Lpcrel2-8,R_PPC64_PCREL_OPT,.-(.Lpcrel2-8)
118; BE-NEXT:    lwa r3, 0(r3)
119; BE-NEXT:    blr
120entry:
121  %0 = load i32, i32* @valInt, align 4
122  ret i32 %0
123}
124
125define dso_local void @WriteGlobalVarInt() local_unnamed_addr  {
126; LE-LABEL: WriteGlobalVarInt:
127; LE:       # %bb.0: # %entry
128; LE-NEXT:    pld r3, valInt@got@pcrel(0), 1
129; LE-NEXT:    li r4, 33
130; LE-NEXT:    stw r4, 0(r3)
131; LE-NEXT:    blr
132;
133; BE-LABEL: WriteGlobalVarInt:
134; BE:       # %bb.0: # %entry
135; BE-NEXT:    pld r3, valInt@got@pcrel(0), 1
136; BE-NEXT:    li r4, 33
137; BE-NEXT:    stw r4, 0(r3)
138; BE-NEXT:    blr
139entry:
140  store i32 33, i32* @valInt, align 4
141  ret void
142}
143
144define dso_local signext i32 @ReadGlobalVarUnsigned() local_unnamed_addr  {
145; LE-LABEL: ReadGlobalVarUnsigned:
146; LE:       # %bb.0: # %entry
147; LE-NEXT:    pld r3, valUnsigned@got@pcrel(0), 1
148; LE-NEXT:  .Lpcrel3:
149; LE-NEXT:    .reloc .Lpcrel3-8,R_PPC64_PCREL_OPT,.-(.Lpcrel3-8)
150; LE-NEXT:    lwa r3, 0(r3)
151; LE-NEXT:    blr
152;
153; BE-LABEL: ReadGlobalVarUnsigned:
154; BE:       # %bb.0: # %entry
155; BE-NEXT:    pld r3, valUnsigned@got@pcrel(0), 1
156; BE-NEXT:  .Lpcrel3:
157; BE-NEXT:    .reloc .Lpcrel3-8,R_PPC64_PCREL_OPT,.-(.Lpcrel3-8)
158; BE-NEXT:    lwa r3, 0(r3)
159; BE-NEXT:    blr
160entry:
161  %0 = load i32, i32* @valUnsigned, align 4
162  ret i32 %0
163}
164
165define dso_local void @WriteGlobalVarUnsigned() local_unnamed_addr  {
166; LE-LABEL: WriteGlobalVarUnsigned:
167; LE:       # %bb.0: # %entry
168; LE-NEXT:    pld r3, valUnsigned@got@pcrel(0), 1
169; LE-NEXT:    li r4, 33
170; LE-NEXT:    stw r4, 0(r3)
171; LE-NEXT:    blr
172;
173; BE-LABEL: WriteGlobalVarUnsigned:
174; BE:       # %bb.0: # %entry
175; BE-NEXT:    pld r3, valUnsigned@got@pcrel(0), 1
176; BE-NEXT:    li r4, 33
177; BE-NEXT:    stw r4, 0(r3)
178; BE-NEXT:    blr
179entry:
180  store i32 33, i32* @valUnsigned, align 4
181  ret void
182}
183
184define dso_local signext i32 @ReadGlobalVarLong() local_unnamed_addr  {
185; LE-LABEL: ReadGlobalVarLong:
186; LE:       # %bb.0: # %entry
187; LE-NEXT:    pld r3, valLong@got@pcrel(0), 1
188; LE-NEXT:  .Lpcrel4:
189; LE-NEXT:    .reloc .Lpcrel4-8,R_PPC64_PCREL_OPT,.-(.Lpcrel4-8)
190; LE-NEXT:    lwa r3, 0(r3)
191; LE-NEXT:    blr
192;
193; BE-LABEL: ReadGlobalVarLong:
194; BE:       # %bb.0: # %entry
195; BE-NEXT:    pld r3, valLong@got@pcrel(0), 1
196; BE-NEXT:  .Lpcrel4:
197; BE-NEXT:    .reloc .Lpcrel4-8,R_PPC64_PCREL_OPT,.-(.Lpcrel4-8)
198; BE-NEXT:    lwa r3, 4(r3)
199; BE-NEXT:    blr
200entry:
201  %0 = load i64, i64* @valLong, align 8
202  %conv = trunc i64 %0 to i32
203  ret i32 %conv
204}
205
206define dso_local void @WriteGlobalVarLong() local_unnamed_addr  {
207; LE-LABEL: WriteGlobalVarLong:
208; LE:       # %bb.0: # %entry
209; LE-NEXT:    pld r3, valLong@got@pcrel(0), 1
210; LE-NEXT:    li r4, 3333
211; LE-NEXT:    std r4, 0(r3)
212; LE-NEXT:    blr
213;
214; BE-LABEL: WriteGlobalVarLong:
215; BE:       # %bb.0: # %entry
216; BE-NEXT:    pld r3, valLong@got@pcrel(0), 1
217; BE-NEXT:    li r4, 3333
218; BE-NEXT:    std r4, 0(r3)
219; BE-NEXT:    blr
220entry:
221  store i64 3333, i64* @valLong, align 8
222  ret void
223}
224
225define dso_local i32* @ReadGlobalPtr() local_unnamed_addr  {
226; LE-LABEL: ReadGlobalPtr:
227; LE:       # %bb.0: # %entry
228; LE-NEXT:    pld r3, ptr@got@pcrel(0), 1
229; LE-NEXT:  .Lpcrel5:
230; LE-NEXT:    .reloc .Lpcrel5-8,R_PPC64_PCREL_OPT,.-(.Lpcrel5-8)
231; LE-NEXT:    ld r3, 0(r3)
232; LE-NEXT:    blr
233;
234; BE-LABEL: ReadGlobalPtr:
235; BE:       # %bb.0: # %entry
236; BE-NEXT:    pld r3, ptr@got@pcrel(0), 1
237; BE-NEXT:  .Lpcrel5:
238; BE-NEXT:    .reloc .Lpcrel5-8,R_PPC64_PCREL_OPT,.-(.Lpcrel5-8)
239; BE-NEXT:    ld r3, 0(r3)
240; BE-NEXT:    blr
241entry:
242  %0 = load i32*, i32** @ptr, align 8
243  ret i32* %0
244}
245
246define dso_local void @WriteGlobalPtr() local_unnamed_addr  {
247; LE-LABEL: WriteGlobalPtr:
248; LE:       # %bb.0: # %entry
249; LE-NEXT:    pld r3, ptr@got@pcrel(0), 1
250; LE-NEXT:  .Lpcrel6:
251; LE-NEXT:    li r4, 3
252; LE-NEXT:    .reloc .Lpcrel6-8,R_PPC64_PCREL_OPT,.-(.Lpcrel6-8)
253; LE-NEXT:    ld r3, 0(r3)
254; LE-NEXT:    stw r4, 0(r3)
255; LE-NEXT:    blr
256;
257; BE-LABEL: WriteGlobalPtr:
258; BE:       # %bb.0: # %entry
259; BE-NEXT:    pld r3, ptr@got@pcrel(0), 1
260; BE-NEXT:  .Lpcrel6:
261; BE-NEXT:    li r4, 3
262; BE-NEXT:    .reloc .Lpcrel6-8,R_PPC64_PCREL_OPT,.-(.Lpcrel6-8)
263; BE-NEXT:    ld r3, 0(r3)
264; BE-NEXT:    stw r4, 0(r3)
265; BE-NEXT:    blr
266entry:
267  %0 = load i32*, i32** @ptr, align 8
268  store i32 3, i32* %0, align 4
269  ret void
270}
271
272define dso_local nonnull i32* @GlobalVarAddr() local_unnamed_addr  {
273; LE-LABEL: GlobalVarAddr:
274; LE:       # %bb.0: # %entry
275; LE-NEXT:    pld r3, valInt@got@pcrel(0), 1
276; LE-NEXT:    blr
277;
278; BE-LABEL: GlobalVarAddr:
279; BE:       # %bb.0: # %entry
280; BE-NEXT:    pld r3, valInt@got@pcrel(0), 1
281; BE-NEXT:    blr
282entry:
283  ret i32* @valInt
284}
285
286define dso_local signext i32 @ReadGlobalArray() local_unnamed_addr  {
287; LE-LABEL: ReadGlobalArray:
288; LE:       # %bb.0: # %entry
289; LE-NEXT:    pld r3, array@got@pcrel(0), 1
290; LE-NEXT:  .Lpcrel7:
291; LE-NEXT:    .reloc .Lpcrel7-8,R_PPC64_PCREL_OPT,.-(.Lpcrel7-8)
292; LE-NEXT:    lwa r3, 12(r3)
293; LE-NEXT:    blr
294;
295; BE-LABEL: ReadGlobalArray:
296; BE:       # %bb.0: # %entry
297; BE-NEXT:    pld r3, array@got@pcrel(0), 1
298; BE-NEXT:  .Lpcrel7:
299; BE-NEXT:    .reloc .Lpcrel7-8,R_PPC64_PCREL_OPT,.-(.Lpcrel7-8)
300; BE-NEXT:    lwa r3, 12(r3)
301; BE-NEXT:    blr
302entry:
303  %0 = load i32, i32* getelementptr inbounds ([10 x i32], [10 x i32]* @array, i64 0, i64 3), align 4
304  ret i32 %0
305}
306
307define dso_local void @WriteGlobalArray() local_unnamed_addr  {
308; LE-LABEL: WriteGlobalArray:
309; LE:       # %bb.0: # %entry
310; LE-NEXT:    pld r3, array@got@pcrel(0), 1
311; LE-NEXT:    li r4, 5
312; LE-NEXT:    stw r4, 12(r3)
313; LE-NEXT:    blr
314;
315; BE-LABEL: WriteGlobalArray:
316; BE:       # %bb.0: # %entry
317; BE-NEXT:    pld r3, array@got@pcrel(0), 1
318; BE-NEXT:    li r4, 5
319; BE-NEXT:    stw r4, 12(r3)
320; BE-NEXT:    blr
321entry:
322  store i32 5, i32* getelementptr inbounds ([10 x i32], [10 x i32]* @array, i64 0, i64 3), align 4
323  ret void
324}
325
326define dso_local signext i32 @ReadGlobalStruct() local_unnamed_addr  {
327; LE-LABEL: ReadGlobalStruct:
328; LE:       # %bb.0: # %entry
329; LE-NEXT:    pld r3, structure@got@pcrel(0), 1
330; LE-NEXT:  .Lpcrel8:
331; LE-NEXT:    .reloc .Lpcrel8-8,R_PPC64_PCREL_OPT,.-(.Lpcrel8-8)
332; LE-NEXT:    lwa r3, 4(r3)
333; LE-NEXT:    blr
334;
335; BE-LABEL: ReadGlobalStruct:
336; BE:       # %bb.0: # %entry
337; BE-NEXT:    pld r3, structure@got@pcrel(0), 1
338; BE-NEXT:  .Lpcrel8:
339; BE-NEXT:    .reloc .Lpcrel8-8,R_PPC64_PCREL_OPT,.-(.Lpcrel8-8)
340; BE-NEXT:    lwa r3, 4(r3)
341; BE-NEXT:    blr
342entry:
343  %0 = load i32, i32* getelementptr inbounds (%struct.Struct, %struct.Struct* @structure, i64 0, i32 2), align 4
344  ret i32 %0
345}
346
347define dso_local void @WriteGlobalStruct() local_unnamed_addr  {
348; LE-LABEL: WriteGlobalStruct:
349; LE:       # %bb.0: # %entry
350; LE-NEXT:    pld r3, structure@got@pcrel(0), 1
351; LE-NEXT:    li r4, 3
352; LE-NEXT:    stw r4, 4(r3)
353; LE-NEXT:    blr
354;
355; BE-LABEL: WriteGlobalStruct:
356; BE:       # %bb.0: # %entry
357; BE-NEXT:    pld r3, structure@got@pcrel(0), 1
358; BE-NEXT:    li r4, 3
359; BE-NEXT:    stw r4, 4(r3)
360; BE-NEXT:    blr
361entry:
362  store i32 3, i32* getelementptr inbounds (%struct.Struct, %struct.Struct* @structure, i64 0, i32 2), align 4
363  ret void
364}
365
366define dso_local void @ReadFuncPtr() local_unnamed_addr  {
367; LE-LABEL: ReadFuncPtr:
368; LE:         .localentry ReadFuncPtr, 1
369; LE-NEXT:  # %bb.0: # %entry
370; LE-NEXT:    pld r3, ptrfunc@got@pcrel(0), 1
371; LE-NEXT:  .Lpcrel9:
372; LE-NEXT:    .reloc .Lpcrel9-8,R_PPC64_PCREL_OPT,.-(.Lpcrel9-8)
373; LE-NEXT:    ld r12, 0(r3)
374; LE-NEXT:    mtctr r12
375; LE-NEXT:    bctr
376; LE-NEXT:    #TC_RETURNr8 ctr 0
377;
378; BE-LABEL: ReadFuncPtr:
379; BE:         .localentry ReadFuncPtr, 1
380; BE-NEXT:  # %bb.0: # %entry
381; BE-NEXT:    pld r3, ptrfunc@got@pcrel(0), 1
382; BE-NEXT:  .Lpcrel9:
383; BE-NEXT:    .reloc .Lpcrel9-8,R_PPC64_PCREL_OPT,.-(.Lpcrel9-8)
384; BE-NEXT:    ld r12, 0(r3)
385; BE-NEXT:    mtctr r12
386; BE-NEXT:    bctr
387; BE-NEXT:    #TC_RETURNr8 ctr 0
388entry:
389  %0 = load void ()*, void ()** bitcast (void (...)** @ptrfunc to void ()**), align 8
390  tail call void %0()
391  ret void
392}
393
394define dso_local void @WriteFuncPtr() local_unnamed_addr  {
395; LE-LABEL: WriteFuncPtr:
396; LE:       # %bb.0: # %entry
397; LE-NEXT:    pld r3, ptrfunc@got@pcrel(0), 1
398; LE-NEXT:    pld r4, function@got@pcrel(0), 1
399; LE-NEXT:    std r4, 0(r3)
400; LE-NEXT:    blr
401;
402; BE-LABEL: WriteFuncPtr:
403; BE:       # %bb.0: # %entry
404; BE-NEXT:    pld r3, ptrfunc@got@pcrel(0), 1
405; BE-NEXT:    pld r4, function@got@pcrel(0), 1
406; BE-NEXT:    std r4, 0(r3)
407; BE-NEXT:    blr
408entry:
409  store void (...)* @function, void (...)** @ptrfunc, align 8
410  ret void
411}
412
413declare void @function(...)
414
415