1; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
2; RUN:   -mcpu=pwr10 -ppc-asm-full-reg-names < %s \
3; RUN:   | FileCheck %s --check-prefixes=CHECK-S,CHECK-ALL
4; RUN: llc -verify-machineinstrs -target-abi=elfv2 -mtriple=powerpc64-- \
5; RUN:   -mcpu=pwr10 -ppc-asm-full-reg-names < %s \
6; RUN:   | FileCheck %s --check-prefixes=CHECK-S,CHECK-ALL
7; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
8; RUN:   -mcpu=pwr9 -ppc-asm-full-reg-names < %s \
9; RUN:   | FileCheck %s --check-prefixes=CHECK-P9,CHECK-ALL
10; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
11; RUN:   -mcpu=pwr9 --code-model=large -ppc-asm-full-reg-names < %s \
12; RUN:   | FileCheck %s --check-prefixes=CHECK-LARGE,CHECK-ALL
13
14@global_int = common dso_local local_unnamed_addr global i32 0, align 4
15
16define dso_local signext i32 @NoTOC() local_unnamed_addr {
17; CHECK-ALL-LABEL: NoTOC:
18; CHECK-S-NOT:     .localentry
19; CHECK-S:         li r3, 42
20; CHECK-S-NEXT:    blr
21entry:
22  ret i32 42
23}
24
25define dso_local signext i32 @AsmClobberX2(i32 signext %a, i32 signext %b) local_unnamed_addr {
26; CHECK-ALL-LABEL: AsmClobberX2:
27; CHECK-S:         .localentry AsmClobberX2, 1
28; CHECK-S:         add r3, r4, r3
29; CHECK-S:         #APP
30; CHECK-S-NEXT:    nop
31; CHECK-S-NEXT:    #NO_APP
32; CHECK-S:         blr
33entry:
34  %add = add nsw i32 %b, %a
35  tail call void asm sideeffect "nop", "~{r2}"()
36  ret i32 %add
37}
38
39; FIXME: This is actually a test case that shows a bug. On power9 and earlier
40;        this test should not compile. On later CPUs (like this test) the @toc
41;        should be replaced with @pcrel and we won't need R2 and so the problem
42;        goes away.
43define dso_local signext i32 @AsmClobberX2WithTOC(i32 signext %a, i32 signext %b) local_unnamed_addr {
44; CHECK-ALL-LABEL: AsmClobberX2WithTOC:
45; CHECK-LARGE:     ld r2, .Lfunc_toc2-.Lfunc_gep2(r12)
46; CHECK-LARGE:     add r2, r2, r12
47; CHECK-S:         .localentry     AsmClobberX2WithTOC
48; CHECK-S:         add r3, r4, r3
49; CHECK-S-NEXT:    #APP
50; CHECK-S-NEXT:    li r2, 0
51; CHECK-S-NEXT:    #NO_APP
52; CHECK-S-NEXT:    plwz r4, global_int@PCREL(0), 1
53; CHECK-S-NEXT:    add r3, r3, r4
54; CHECK-S-NEXT:    extsw r3, r3
55; CHECK-S-NEXT:    blr
56entry:
57  %add = add nsw i32 %b, %a
58  tail call void asm sideeffect "li 2, 0", "~{r2}"()
59  %0 = load i32, i32* @global_int, align 4
60  %add1 = add nsw i32 %add, %0
61  ret i32 %add1
62}
63
64define dso_local signext i32 @AsmClobberX5(i32 signext %a, i32 signext %b) local_unnamed_addr {
65; CHECK-ALL-LABEL: AsmClobberX5:
66; CHECK-S:         .localentry AsmClobberX5, 1
67; CHECK-P9-NOT:    .localentry
68; CHECK-ALL:       # %bb.0: # %entry
69; CHECK-S-NEXT:    add r3, r4, r3
70; CHECK-S-NEXT:    #APP
71; CHECK-S-NEXT:    nop
72; CHECK-S-NEXT:    #NO_APP
73; CHECK-S-NEXT:    extsw r3, r3
74; CHECK-S-NEXT:    blr
75entry:
76  %add = add nsw i32 %b, %a
77  tail call void asm sideeffect "nop", "~{r5}"()
78  ret i32 %add
79}
80
81; Clobber all GPRs except R2.
82define dso_local signext i32 @AsmClobberNotR2(i32 signext %a, i32 signext %b) local_unnamed_addr {
83; CHECK-ALL-LABEL: AsmClobberNotR2:
84; CHECK-S:         .localentry AsmClobberNotR2, 1
85; CHECK-P9-NOT:    .localentry
86; CHECK-S:         add r3, r4, r3
87; CHECK-S:         stw r3, -148(r1) # 4-byte Folded Spill
88; CHECK-S-NEXT:    #APP
89; CHECK-S-NEXT:    nop
90; CHECK-S-NEXT:    #NO_APP
91; CHECK-S-NEXT:    lwz r3, -148(r1) # 4-byte Folded Reload
92; CHECK-S:    blr
93entry:
94  %add = add nsw i32 %b, %a
95  tail call void asm sideeffect "nop", "~{r0},~{r1},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{r13},~{r14},~{r15},~{r16},~{r17},~{r18},~{r19},~{r20},~{r21},~{r22},~{r23},~{r24},~{r25},~{r26},~{r27},~{r28},~{r29},~{r30},~{r31}"()
96  ret i32 %add
97}
98
99; Increase register pressure enough to force the register allocator to
100; make use of R2.
101define dso_local signext i32 @X2IsCallerSaved(i32 signext %a, i32 signext %b, i32 signext %c, i32 signext %d, i32 signext %e, i32 signext %f, i32 signext %g, i32 signext %h) local_unnamed_addr {
102; CHECK-ALL-LABEL: X2IsCallerSaved:
103; CHECK-S:         .localentry X2IsCallerSaved, 1
104; CHECK-P9-NOT:    .localentry
105; CHECK-ALL:       # %bb.0: # %entry
106; CHECK-S-NEXT:    std r29, -24(r1) # 8-byte Folded Spill
107; CHECK-S-NEXT:    std r30, -16(r1) # 8-byte Folded Spill
108; CHECK-S-NEXT:    add r11, r4, r3
109; CHECK-S-NEXT:    sub r29, r8, r9
110; CHECK-S-NEXT:    add r9, r10, r9
111; CHECK-S-NEXT:    sub r10, r10, r3
112; CHECK-S-NEXT:    sub r12, r4, r5
113; CHECK-S-NEXT:    add r0, r6, r5
114; CHECK-S-NEXT:    sub r2, r6, r7
115; CHECK-S-NEXT:    mullw r3, r4, r3
116; CHECK-S-NEXT:    add r30, r8, r7
117; CHECK-S-NEXT:    mullw r3, r3, r11
118; CHECK-S-NEXT:    mullw r3, r3, r5
119; CHECK-S-NEXT:    mullw r3, r3, r6
120; CHECK-S-NEXT:    mullw r3, r3, r12
121; CHECK-S-NEXT:    mullw r3, r3, r0
122; CHECK-S-NEXT:    mullw r3, r3, r7
123; CHECK-S-NEXT:    mullw r3, r3, r8
124; CHECK-S-NEXT:    mullw r3, r3, r2
125; CHECK-S-NEXT:    mullw r3, r3, r30
126; CHECK-S-NEXT:    ld r30, -16(r1) # 8-byte Folded Reload
127; CHECK-S-NEXT:    mullw r3, r3, r29
128; CHECK-S-NEXT:    ld r29, -24(r1) # 8-byte Folded Reload
129; CHECK-S-NEXT:    mullw r3, r3, r9
130; CHECK-S-NEXT:    mullw r3, r3, r10
131; CHECK-S-NEXT:    extsw r3, r3
132; CHECK-S-NEXT:    blr
133entry:
134  %add = add nsw i32 %b, %a
135  %sub = sub nsw i32 %b, %c
136  %add1 = add nsw i32 %d, %c
137  %sub2 = sub nsw i32 %d, %e
138  %add3 = add nsw i32 %f, %e
139  %sub4 = sub nsw i32 %f, %g
140  %add5 = add nsw i32 %h, %g
141  %sub6 = sub nsw i32 %h, %a
142  %mul = mul i32 %b, %a
143  %mul7 = mul i32 %mul, %add
144  %mul8 = mul i32 %mul7, %c
145  %mul9 = mul i32 %mul8, %d
146  %mul10 = mul i32 %mul9, %sub
147  %mul11 = mul i32 %mul10, %add1
148  %mul12 = mul i32 %mul11, %e
149  %mul13 = mul i32 %mul12, %f
150  %mul14 = mul i32 %mul13, %sub2
151  %mul15 = mul i32 %mul14, %add3
152  %mul16 = mul i32 %mul15, %sub4
153  %mul17 = mul i32 %mul16, %add5
154  %mul18 = mul i32 %mul17, %sub6
155  ret i32 %mul18
156}
157
158
159define dso_local signext i32 @UsesX2AsTOC() local_unnamed_addr {
160; CHECK-ALL-LABEL: UsesX2AsTOC:
161; CHECK-LARGE:     ld r2, .Lfunc_toc6-.Lfunc_gep6(r12)
162; CHECK-LARGE:     add r2, r2, r12
163; CHECK-ALL:       # %bb.0: # %entry
164entry:
165  %0 = load i32, i32* @global_int, align 4
166  ret i32 %0
167}
168
169
170define dso_local double @UsesX2AsConstPoolTOC() local_unnamed_addr {
171; CHECK-ALL-LABEL: UsesX2AsConstPoolTOC:
172; CHECK-LARGE:     ld r2, .Lfunc_toc7-.Lfunc_gep7(r12)
173; CHECK-LARGE:     add r2, r2, r12
174; CHECK-S-NOT:       .localentry
175; CHECK-ALL:       # %bb.0: # %entry
176; CHECK-S-NEXT:    plfd f1, .LCPI7_0@PCREL(0), 1
177; CHECK-S-NEXT:    blr
178entry:
179  ret double 0x404124A4EBDD334C
180}
181
182
183