1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -relocation-model=pic -verify-machineinstrs -mcpu=pwr7 -mattr=+altivec -mattr=-vsx < %s | FileCheck %s
3
4target datalayout = "e-m:e-i64:64-n32:64"
5target triple = "powerpc64le-unknown-linux-gnu"
6
7@g = common global ppc_fp128 0xM00000000000000000000000000000000, align 16
8
9define void @callee(ppc_fp128 %x) {
10; CHECK-LABEL: callee:
11; CHECK:       # %bb.0: # %entry
12; CHECK-NEXT:    addis 3, 2, .LC0@toc@ha
13; CHECK-NEXT:    stfd 2, -8(1)
14; CHECK-NEXT:    stfd 1, -16(1)
15; CHECK-NEXT:    ld 3, .LC0@toc@l(3)
16; CHECK-NEXT:    stfd 2, 8(3)
17; CHECK-NEXT:    stfd 1, 0(3)
18; CHECK-NEXT:    blr
19entry:
20  %x.addr = alloca ppc_fp128, align 16
21  store ppc_fp128 %x, ppc_fp128* %x.addr, align 16
22  %0 = load ppc_fp128, ppc_fp128* %x.addr, align 16
23  store ppc_fp128 %0, ppc_fp128* @g, align 16
24  ret void
25}
26
27define void @caller() {
28; CHECK-LABEL: caller:
29; CHECK:       # %bb.0: # %entry
30; CHECK-NEXT:    mflr 0
31; CHECK-NEXT:    std 0, 16(1)
32; CHECK-NEXT:    stdu 1, -32(1)
33; CHECK-NEXT:    .cfi_def_cfa_offset 32
34; CHECK-NEXT:    .cfi_offset lr, 16
35; CHECK-NEXT:    addis 3, 2, .LC0@toc@ha
36; CHECK-NEXT:    ld 3, .LC0@toc@l(3)
37; CHECK-NEXT:    lfd 2, 8(3)
38; CHECK-NEXT:    lfd 1, 0(3)
39; CHECK-NEXT:    bl test
40; CHECK-NEXT:    nop
41; CHECK-NEXT:    addi 1, 1, 32
42; CHECK-NEXT:    ld 0, 16(1)
43; CHECK-NEXT:    mtlr 0
44; CHECK-NEXT:    blr
45entry:
46  %0 = load ppc_fp128, ppc_fp128* @g, align 16
47  call void @test(ppc_fp128 %0)
48  ret void
49}
50
51declare void @test(ppc_fp128)
52
53define void @caller_const() {
54; CHECK-LABEL: caller_const:
55; CHECK:       # %bb.0: # %entry
56; CHECK-NEXT:    mflr 0
57; CHECK-NEXT:    std 0, 16(1)
58; CHECK-NEXT:    stdu 1, -32(1)
59; CHECK-NEXT:    .cfi_def_cfa_offset 32
60; CHECK-NEXT:    .cfi_offset lr, 16
61; CHECK-NEXT:    addis 3, 2, .LCPI2_0@toc@ha
62; CHECK-NEXT:    addis 4, 2, .LCPI2_1@toc@ha
63; CHECK-NEXT:    lfs 1, .LCPI2_0@toc@l(3)
64; CHECK-NEXT:    lfs 2, .LCPI2_1@toc@l(4)
65; CHECK-NEXT:    bl test
66; CHECK-NEXT:    nop
67; CHECK-NEXT:    addi 1, 1, 32
68; CHECK-NEXT:    ld 0, 16(1)
69; CHECK-NEXT:    mtlr 0
70; CHECK-NEXT:    blr
71entry:
72  call void @test(ppc_fp128 0xM3FF00000000000000000000000000000)
73  ret void
74}
75
76define ppc_fp128 @result() {
77; CHECK-LABEL: result:
78; CHECK:       # %bb.0: # %entry
79; CHECK-NEXT:    addis 3, 2, .LC0@toc@ha
80; CHECK-NEXT:    ld 3, .LC0@toc@l(3)
81; CHECK-NEXT:    lfd 1, 0(3)
82; CHECK-NEXT:    lfd 2, 8(3)
83; CHECK-NEXT:    blr
84entry:
85  %0 = load ppc_fp128, ppc_fp128* @g, align 16
86  ret ppc_fp128 %0
87}
88
89define void @use_result() {
90; CHECK-LABEL: use_result:
91; CHECK:       # %bb.0: # %entry
92; CHECK-NEXT:    mflr 0
93; CHECK-NEXT:    std 0, 16(1)
94; CHECK-NEXT:    stdu 1, -32(1)
95; CHECK-NEXT:    .cfi_def_cfa_offset 32
96; CHECK-NEXT:    .cfi_offset lr, 16
97; CHECK-NEXT:    bl test_result
98; CHECK-NEXT:    nop
99; CHECK-NEXT:    addis 3, 2, .LC0@toc@ha
100; CHECK-NEXT:    ld 3, .LC0@toc@l(3)
101; CHECK-NEXT:    stfd 2, 8(3)
102; CHECK-NEXT:    stfd 1, 0(3)
103; CHECK-NEXT:    addi 1, 1, 32
104; CHECK-NEXT:    ld 0, 16(1)
105; CHECK-NEXT:    mtlr 0
106; CHECK-NEXT:    blr
107entry:
108  %call = tail call ppc_fp128 @test_result() #3
109  store ppc_fp128 %call, ppc_fp128* @g, align 16
110  ret void
111}
112
113declare ppc_fp128 @test_result()
114
115define void @caller_result() {
116; CHECK-LABEL: caller_result:
117; CHECK:       # %bb.0: # %entry
118; CHECK-NEXT:    mflr 0
119; CHECK-NEXT:    std 0, 16(1)
120; CHECK-NEXT:    stdu 1, -32(1)
121; CHECK-NEXT:    .cfi_def_cfa_offset 32
122; CHECK-NEXT:    .cfi_offset lr, 16
123; CHECK-NEXT:    bl test_result
124; CHECK-NEXT:    nop
125; CHECK-NEXT:    bl test
126; CHECK-NEXT:    nop
127; CHECK-NEXT:    addi 1, 1, 32
128; CHECK-NEXT:    ld 0, 16(1)
129; CHECK-NEXT:    mtlr 0
130; CHECK-NEXT:    blr
131entry:
132  %call = tail call ppc_fp128 @test_result()
133  tail call void @test(ppc_fp128 %call)
134  ret void
135}
136
137define i128 @convert_from(ppc_fp128 %x) {
138; CHECK-LABEL: convert_from:
139; CHECK:       # %bb.0: # %entry
140; CHECK-NEXT:    stfd 1, -16(1)
141; CHECK-NEXT:    stfd 2, -8(1)
142; CHECK-NEXT:    ld 3, -16(1)
143; CHECK-NEXT:    ld 4, -8(1)
144; CHECK-NEXT:    blr
145entry:
146  %0 = bitcast ppc_fp128 %x to i128
147  ret i128 %0
148}
149
150define ppc_fp128 @convert_to(i128 %x) {
151; CHECK-LABEL: convert_to:
152; CHECK:       # %bb.0: # %entry
153; CHECK-NEXT:    std 3, -16(1)
154; CHECK-NEXT:    std 4, -8(1)
155; CHECK-NEXT:    lfd 1, -16(1)
156; CHECK-NEXT:    lfd 2, -8(1)
157; CHECK-NEXT:    blr
158entry:
159  %0 = bitcast i128 %x to ppc_fp128
160  ret ppc_fp128 %0
161}
162
163define ppc_fp128 @convert_to2(i128 %x) {
164; CHECK-LABEL: convert_to2:
165; CHECK:       # %bb.0: # %entry
166; CHECK-NEXT:    rotldi 5, 3, 1
167; CHECK-NEXT:    sldi 3, 3, 1
168; CHECK-NEXT:    rldimi 5, 4, 1, 0
169; CHECK-NEXT:    std 3, -16(1)
170; CHECK-NEXT:    std 5, -8(1)
171; CHECK-NEXT:    lfd 1, -16(1)
172; CHECK-NEXT:    lfd 2, -8(1)
173; CHECK-NEXT:    blr
174entry:
175  %shl = shl i128 %x, 1
176  %0 = bitcast i128 %shl to ppc_fp128
177  ret ppc_fp128 %0
178}
179
180
181define double @convert_vector(<4 x i32> %x) {
182; CHECK-LABEL: convert_vector:
183; CHECK:       # %bb.0: # %entry
184; CHECK-NEXT:    addi 3, 1, -16
185; CHECK-NEXT:    stvx 2, 0, 3
186; CHECK-NEXT:    lfd 1, -16(1)
187; CHECK-NEXT:    blr
188entry:
189  %cast = bitcast <4 x i32> %x to ppc_fp128
190  %conv = fptrunc ppc_fp128 %cast to double
191  ret double %conv
192}
193
194declare void @llvm.va_start(i8*)
195
196define double @vararg(i32 %a, ...) {
197; CHECK-LABEL: vararg:
198; CHECK:       # %bb.0: # %entry
199; CHECK-NEXT:    addi 3, 1, 55
200; CHECK-NEXT:    std 4, 40(1)
201; CHECK-NEXT:    rldicr 3, 3, 0, 59
202; CHECK-NEXT:    std 5, 48(1)
203; CHECK-NEXT:    ori 4, 3, 8
204; CHECK-NEXT:    std 6, 56(1)
205; CHECK-NEXT:    std 7, 64(1)
206; CHECK-NEXT:    std 8, 72(1)
207; CHECK-NEXT:    std 9, 80(1)
208; CHECK-NEXT:    std 10, 88(1)
209; CHECK-NEXT:    std 4, -8(1)
210; CHECK-NEXT:    lfd 1, 0(3)
211; CHECK-NEXT:    addi 3, 3, 16
212; CHECK-NEXT:    std 3, -8(1)
213; CHECK-NEXT:    blr
214entry:
215  %va = alloca i8*, align 8
216  %va1 = bitcast i8** %va to i8*
217  call void @llvm.va_start(i8* %va1)
218  %arg = va_arg i8** %va, ppc_fp128
219  %conv = fptrunc ppc_fp128 %arg to double
220  ret double %conv
221}
222
223